// this is a crucial object and needs to be declared in global space
var searchForm;

function getFlashMovie(movieName) {
    var isIE = navigator.appName.indexOf("Microsoft") != -1;
    return (isIE) ? window[movieName] : document[movieName];
}

HomeSearch.prototype.switchSearchTypeToBuy = function() {
    this.switchSearchType(minimumPricesBuy, maximumPricesBuy);
    getFlashMovie( 'topLevelMap' ).switchLocationsTo( 'buy' );
};

HomeSearch.prototype.switchSearchTypeToRent = function() {
    this.switchSearchType(minimumPricesRent, maximumPricesRent);
    getFlashMovie( 'topLevelMap' ).switchLocationsTo( 'rent' );
};

HomeSearch.prototype.initExtend = function() {
	HomeSearch.prototype.disableAutosuggest();
	
	$('#location option:first').attr('selected','selected');
	
    $("#location").focus(function () {
        if(typeof(searchForm) === 'object') {
            searchForm.disableAutosuggest();
        }
    });
    
    geoLocationType = 'customarea';
	geoLocationId = 3;
    $('#geoLocationType').val(geoLocationType);
    $('#geoLocationId').val(geoLocationId);
    
	$("#location").change(function () {
        if ($(this).val() == 'All')
        {
        	geoLocationType = 'customarea';
        	geoLocationId = 3;
        } else if ($(this).val() == 'Clapham') {
        	geoLocationType = 'customarea';
        	geoLocationId = 2;
        } else if ($(this).val() == 'Brixton') {
        	geoLocationType = 'customarea';
        	geoLocationId = 1;
        } else if ($(this).val() == 'Stockwell') {
        	geoLocationType = 'alias';
        	geoLocationId = 24509;
        } else if ($(this).val() == 'Battersea') {
        	geoLocationType = 'customarea';
        	geoLocationId = 5;
        } else if ($(this).val() == 'Balham') {
        	geoLocationType = 'alias';
        	geoLocationId = 24532;
        } else if ($(this).val() == 'Camberwell') {
        	geoLocationType = 'customarea';
        	geoLocationId = 4;
        } else if ($(this).val() == 'East Dulwich') {
        	geoLocationType = 'customarea';
        	geoLocationId = 6;
        } else if ($(this).val() == 'West Dulwich') {
        	geoLocationType = 'customarea';
        	geoLocationId = 7;
        } else if ($(this).val() == 'Peckham') {
        	geoLocationType = 'customarea';
        	geoLocationId = 8;
        } else if ($(this).val() == 'Nunhead') {
        	geoLocationType = 'customarea';
        	geoLocationId = 9;
        } else if ($(this).val() == 'Brockley') {
        	geoLocationType = 'customarea';
        	geoLocationId = 14;
        } else if ($(this).val() == 'Forest Hill') {
        	geoLocationType = 'customarea';
        	geoLocationId = 11;
        } else if ($(this).val() == 'Camberwell') {
        	geoLocationType = 'customarea';
        	geoLocationId = 12;
        } else if ($(this).val() == 'Herne Hill') {
        	geoLocationType = 'customarea';
        	geoLocationId = 13;
        }
        $('#geoLocationType').val(geoLocationType);
        $('#geoLocationId').val(geoLocationId);
        
        searchForm.canSubmitRightAway = true;
        HomeSearch.prototype.criteriaChanged();
        
    });
};




$(document).ready(function() {
    searchForm = new HomeSearch('homeSearch');
    searchForm.switchCenterTypeToGeoName();
    searchForm.canSubmitRightAway = true;
});

