

FC.vars = {
	selectors: {
		ACCORDION: 'div.accordion',					// the accordion container
		BIGMAP: 'a.bigMap',							// the link to display the larger map
		CAROUSEL: 'div.carousel',					// the carousel container
		CAROUSEL_PROPERTY: 'div.property',			// the container around each carousel item
		CAROUSEL_PROPERTY_DESC: 'div.propertyDesc',	// the text on the carousel property overlay
		GALLERY: "a.propPhotos",
		HERO_IMAGE: 'a.heroImage',					// the hero image that the text will show/hide over
		HELPBUTTON: 'a.helpbutton',					// the button to click to show form help
		INFOBUTTON: 'a.infobutton',					// the button to click to show info bubbles
		JSONOBJECT: '/Templates/Services/AssetSearch.svc/Search/',
		MAP: 'map',
		OVERLAY_INFO: 'div.overlayInfo',			// the text on the Homepage carousel overlay
		OVERLAY_TABS: 'div.overlayTabs',			// the tabs on the Homepage carousel
		PRED_SEARCH: 'input#WhereTextBox', 		    // the input box for the predictive search
		//SHOW_SELECT: 'div.showSelect',			// the select box to be shown (functionality removed)
		//SELECT_LINK: 'p.selectLink',				// the para to be shown initially (functionality removed)
        SEARCH_DROPDOWN: '#SectorTypeDropDown',
        HIDE_SECTOR: "#hidHideSector",
		SLIDER_OPTIONS: ".slider-options",
		TOOLTIP: 'div.tooltip',						// the tooltip container
        LOCATION_DROPDOWN: '#slt-distance'          // the location/range dropdown list on the search page
	}

}

FC.accordion = function(el) {
	__$expander= $(el);
	
	__$headings=__$expander.find('h2');
	__$headings.append('<span></span>');
	__$headings.wrapInner('<a href="#"></a>');
	
	__$headingFirst=__$expander.find('h2:first').addClass('open');
	__$headingFirst.parent().find('div.acc-content').slideDown('fast');
	
	__$headings.find('a').bind('click', function() {
		var __$heading= $(this).parent();
		
		if(__$heading.hasClass('open')) { 
			__$heading.next('div.acc-content').slideUp('fast');
			__$heading.removeClass('open').addClass('closed');
		}
		else {
			__$heading.next('div.acc-content').slideDown('fast');
			__$heading.removeClass('closed').addClass('open');
		}
		
		return false;
	});
}


FC.homepageCarousel = function () {

    var __SEL = FC.vars.selectors;
    var __$listItems = $(__SEL.OVERLAY_TABS).find('li');
    var __count = 0;

    $(__SEL.OVERLAY_TABS).find('p').hide();
    $(__SEL.OVERLAY_INFO).hide();

    $(__SEL.HERO_IMAGE).append('<img class="image2" alt="" src="/images/transparent.gif"/>');

    var __$img1 = $('img.image1');
    var __$img2 = $('img.image2');

    $(__SEL.OVERLAY_TABS).find('li').bind('click', function () {
        var __imgSrc = $(this).find('img').attr('src');
        var __$anchor = $(this).find('a');
        var __anchorHref = __$anchor.attr('href');
        var __overlayTitle = __$anchor.text();
        var __overlayText = $(this).find('p').text();
        $(__SEL.OVERLAY_TABS).find('a.tabOn').removeClass('tabOn');
        __$anchor.addClass('tabOn');

        //crossfade images
        __$img2.attr('src', __imgSrc);
        __$img1.fadeOut('500', function () {
            __$img1.attr('src', __imgSrc);
            __$img1.fadeIn('fast');
        });

        $(__SEL.OVERLAY_INFO).find('h2 a').text(__overlayTitle).attr('href', __anchorHref);
        $(__SEL.HERO_IMAGE).attr('href', __anchorHref);
        $(__SEL.OVERLAY_INFO).find('p').text(__overlayText);

        //update the count for rotating, stop the timer and restart it (for when user clicks item just before it rotates to the next one- frustrating for them)
        __count = __$listItems.index(this);
        $(document).stopTime();
        switchItem();
        $(__SEL.OVERLAY_INFO).show();

        return false;
    });

    $('div.hero').bind("mouseenter", function () {
        $(__SEL.OVERLAY_INFO).fadeIn('100');
        $(document).stopTime();
    });

    $('div.hero').bind("mouseleave", function () {
        $(__SEL.OVERLAY_INFO).hide();
        switchItem();
    });

    var time = 10000;


    var switchItem = function () {
        $(document).everyTime(time, function () {
            var __numItems = __$listItems.length;
            var __$current = $(__SEL.OVERLAY_TABS).find('a.tabOn').parent();

            if (__count < __numItems - 1) {
                __$itemToChangeTo = __$listItems.eq(__count + 1);
                __count++;
            }
            else {
                __count = 0;
                __$itemToChangeTo = __$listItems.eq(__count);
            }

            var __imgSrc = __$itemToChangeTo.find('img').attr('src');
            var __$anchor = __$itemToChangeTo.find('a');
            var __anchorHref = __$anchor.attr('href');
            var __overlayTitle = __$anchor.text();
            var __overlayText = __$itemToChangeTo.find('p').text();

            __$current.find('a').removeClass('tabOn');
            __$anchor.addClass('tabOn');

            __$img2.attr('src', __imgSrc);
            __$img1.fadeOut('500', function () {
                __$img1.attr('src', __imgSrc);
                __$img1.fadeIn('fast');
            });

            $(__SEL.OVERLAY_INFO).find('h2 a').text(__overlayTitle).attr('href', __anchorHref);
            $(__SEL.HERO_IMAGE).attr('href', __anchorHref);
            $(__SEL.OVERLAY_INFO).find('p').text(__overlayText);
        }, 0);
    }
    switchItem();


}

FC.carousel = function(){
	var __SEL = FC.vars.selectors;
	var $__PROPERTY= $(__SEL.CAROUSEL_PROPERTY);
	var __PROPERTY_DESC= __SEL.CAROUSEL_PROPERTY_DESC;

	// rollover states for each property
	$(__PROPERTY_DESC).addClass('hide');
	$(__PROPERTY_DESC).hide();

	$__PROPERTY.each(function () {
	    var $propName = $(this).find('p.caption').clone();
	    $(this).find(__PROPERTY_DESC).prepend($propName);
	})

	$__PROPERTY.bind('mouseenter focus', function () {
	    $(this).find(__PROPERTY_DESC).fadeIn('50');
	    $(this).find(__PROPERTY_DESC).removeClass('hide');
	});

	$__PROPERTY.bind('mouseleave blur', function () {
	    $(this).find(__PROPERTY_DESC).hide();
	    $(this).find(__PROPERTY_DESC).addClass('hide');
	});
    	
	$__PROPERTY.bind('click', function() {
		window.location = $(this).find('p.caption a').attr('href');
	});
	
	var __axis = {axis:'x'};

	$(__SEL.CAROUSEL).each(function(){
		var __$this = $(this);	
		var __current = 0, __scrollAmount=__$this.hasClass('two-col') ? 2 : 3, __$contentBoxes = $("div.property", __$this);
		
		//build pagination and controls
		if(__$contentBoxes.length > __scrollAmount) {
			__$this.find('div.headerRow').append('<div class="grid grid-3 m-prefix-2"><div class="pagination clear"><div class="inner"><h3 class="reader">Pagination for image galleries</h3><ul role="navigation"><li class="prev-disabled"><span>Previous page</span></li><li class="page-list"><ol></ol><li class="next"><a href="#" rel="Next">Next page</a></li></ul></div></div></div>');
		
			var __$pageListPar=  __$this.find('ol');
		
			for(i=0;i<__$contentBoxes.length/__scrollAmount;i++) {
				if(i==0) {
					__$pageListPar.append('<li class="current"><strong><span class="reader">You are on page</span> ' + (i+1) + '</strong></li>')
				}
				else {
					__$pageListPar.append('<li><a href="#"><span class="reader">Page</span> ' +(i+1)+'</a></li>');
				}
			}
		
			var __$container = $("div.carouselContainer", __$this),	__$right = $("li.next", __$this), __$left = $("div.pagination ul li:first", __$this), __$pageList = $('li.page-list li', __$this),
			
			updatePageList = function(direction) {
				
				var $__currentPage = $('li.page-list li.current', __$this);
				var $__currentPageText= $__currentPage.text();
				$__currentPageText = $.trim($__currentPageText);
				
				var __currentPageNum = $__currentPageText.charAt($__currentPageText.length-1)*1;
				
				$__currentPage.empty();
				$__currentPage.append('<a href="#"><span class="reader">Page</span> '+ __currentPageNum+'</a>');
				$__currentPage.removeClass('current');
				
				if(direction == 'left') {
					var $__prevPage = $__currentPage.prev('li')
					$__prevPage.empty();
					$__prevPage.append('<strong><span class="reader">You are on page</span> ' + (__currentPageNum-1) +'</strong>');
					$__prevPage.addClass('current');
				}
				
				if(direction == 'right') {
					var $__nextPage = $__currentPage.next('li')
					$__nextPage.empty();
					$__nextPage.append('<strong><span class="reader">You are on page</span> ' + (__currentPageNum+1) +'</strong>');
					$__nextPage.addClass('current');
				}
				
			};
			//var __container = __$container[0];
			
			//set width of scrolling list by getting width of one item and adding 20px (for left margin)
			//the first item of each row doesn't have left margin, so calc how many rows and subtract that
			//var __itemWidth= __$contentBoxes.width();
			//var __width= (__$contentBoxes.length*(__itemWidth+20)) - (__$contentBoxes.length/__scrollAmount*20);
			//$("div.carouselItems", this).css('width', __width);
					
			//var __max = __$contentBoxes.length*__scrollAmount;
			var __max = __$contentBoxes.length;
			
			//Make sure the scroller is at the start
			__$container.scrollTo('div.property:eq('+0+')', 200, __axis);
			
			/*if(__max==__$contentBoxes.length){
				__max=__max-1;
			}*/
		
		
			//Left scroller button
			__$left.bind("click", function(){
				if(__$left.hasClass('prev-disabled')) {
					return false;
				}
				else {
					if(__current>0){
						__current = __current-__scrollAmount;
						__$this.find('div.carouselContainer').scrollTo('div.property:eq('+__current+')', 500, __axis);
						
						//__$right.show();
						__$right.empty();
						__$right.removeClass('next-disabled').addClass('next');;
						__$right.append('<a href="#">Next page</a>');
							
						if(__current == 0){
							//__$left.hide();
							__$left.empty();
							__$left.addClass('prev-disabled');
							__$left.append('<span>Previous page</span>');
						}
					}
					
					updatePageList('left');
					return false;
				}
			});
		
			//Right scroller button
			__$right.bind("click", function(){
				if(__$right.hasClass('next-disabled')) {
					return false;
				}
				
				else {
					if(__current<__max){
						__current = __current+__scrollAmount;
						//console.log(__current);
						__$container.scrollTo( 'div.property:eq('+__current+')', 500, __axis);
						
						//__$left.show();
						__$left.empty();
						__$left.removeClass('prev-disabled');
						__$left.addClass('prev');
						__$left.append('<a href="#">Previous page</a>');
						
						if((__max - __current) <= __scrollAmount){
							__$right.empty();
							__$right.removeClass('next').addClass('next-disabled');
							__$right.append('<span>Next page</span>');
						}
					
					updatePageList('right');
					}
					return false;
				}
			});
		
		
			// SPECIFIC PAGE NUMBER HAS BEEN CLICKED
			__$pageList.bind("click", function() {
				if ($(this).hasClass('current')) {
					return false;
				}
				
				else {
					var $this = $(this);
					var $__currentPage = $('li.page-list li.current', __$this);
					
					var $__currentPageText= $__currentPage.text();
					$__currentPageText = $.trim($__currentPageText);
									
					var __currentPageText = $__currentPageText.charAt($__currentPageText.length-1);
					
					// the whole text is "page x"- we just want the x (which is the 2nd part of array that split creates)
					var __num = $this.text().split(' ');				
					// we want to scroll to the 3rd, 6th, 9th etc item. we subtract 1 so clicking page 2 will be 1*scrollAmount which equals 3- instead of 2*3 which equals 6, 		 				// which is actually page 3
					__current = (__num[1]-1) * __scrollAmount;			
					
					__$container.scrollTo('div.property:eq('+__current+')', 500, __axis);
					
					$__currentPage.empty();
					$__currentPage.append('<a href="#"><span class="reader">Page</span> '+ __currentPageText+'</a>');
					$__currentPage.removeClass('current');
					
					$this.empty();
					$this.append('<strong><span class="reader">You are on page</span> '+ __num[1]+'</strong>');
					$this.addClass('current');
					
					if(__current == 0){
						__$left.empty();
						__$left.addClass('prev-disabled');
						__$left.append('<span>Previous page</span>');
						
						__$right.empty();
						__$right.removeClass('next-disabled').addClass('next');;
						__$right.append('<a href="#">Next page</a>');
					}
					
					else if((__max - __current) <= __scrollAmount){
						__$left.empty();
						__$left.removeClass('prev-disabled');
						__$left.addClass('prev');
						__$left.append('<a href="#">Previous page</a>');
						
						__$right.empty();
						__$right.removeClass('next').addClass('next-disabled');
						__$right.append('<span>Next page</span>');
					}
					
					else {
						__$left.empty();
						__$left.removeClass('prev-disabled');
						__$left.addClass('prev');
						__$left.append('<a href="#">Previous page</a>');
						
						__$right.empty();
						__$right.removeClass('next-disabled').addClass('next');;
						__$right.append('<a href="#">Next page</a>');
					}
					return false;
				}
			});
		}
	});// end 'each' statement
}

FC.tooltip = function(tooltip){
	__SEL= FC.vars.selectors;
	__$helpButton= $(__SEL.HELPBUTTON);
	__$tooltip= $(tooltip);
	
	__$tooltip.css('display','none');
	
	__$tooltip.each(function () {
		var __$that= $(this);
		var __$boxContent= __$that.html();
		__$that.empty();
		__$that.prepend('<div class="box-top clear"><div class="padding">'+__$boxContent+'<p class="fr"><a href="#" class="close"></a></p></div></div><div class="box-bottom">&nbsp;</div>');
		var __$closeButton = __$that.find('a.close');

		__$helpButton.bind('click', function() {
			var el= $(this).attr('href');
			$(el).show().addClass('active');
			$(el).find('a.close').text("Close");
			return false;
		});	
		
		__$closeButton.bind('click', function() {
			__$that.hide().removeClass('active');
			__$closeButton.text("");
			return false;
		});
		
	
		__$helpButton.bind('mouseover focus', function() {
			var el= $(this).attr('href');
			$(el).show();
			return false;
		});
		
		
		__$helpButton.bind('mouseout blur', function() {
			var el= $(this).attr('href');
			if(!($(el).hasClass('active'))){
				$(el).hide();
				return false;
			} 
		});		
	
	});	
}

FC.infoButton = function(infobutton){
	__SEL= FC.vars.selectors;
	__$infoButton= $(__SEL.INFOBUTTON);
	var __clicked = false;
	
	$('div.infobuttonContainer').each(function () {
		var __$that= $(this);
		var __$infoBox= __$that.find('div.infobox')
		var __$boxContent= __$infoBox.html();
		__$infoBox.empty();
		__$infoBox.prepend('<div class="box-top clear">&nbsp;</div><div class="box-bottom"><div class="inner clear">'+__$boxContent+'<p class="fr"><a href="#" class="close"></a></p></div></div>');
		var __$closeButton = __$that.find('a.close');
		
		__$that.find('a.infobutton').bind('click', function() {
			var el= $(this).attr('href');
			$(el).show().addClass('active');
			$(el).find('a.close').text("Close");
			return false;
		
		});
		
	__$that.find('a.infobutton').bind('mouseover focus', function() {
		var el= $(this).attr('href');
		$(el).show();
		return false;
	});
	
	
	__$that.find('a.infobutton').bind('mouseout blur', function() {
		var el= $(this).attr('href');
		if(!($(el).hasClass('active'))){
			$(el).hide();
			return false;
		} 
	});		
		
		
		__$closeButton.bind('click', function() {
			__$infoBox.hide().removeClass('active');
			__$closeButton.text("");
			return false;
		});
	});
}

FC.slidersFromSelect = function(){

	var sliderOptions = FC.vars.selectors.SLIDER_OPTIONS;
	
	$(sliderOptions).each(function() {
								   
		var valLow = "#" + $(this).attr('id') + ' select.valLow';
		var valHigh = "#" + $(this).attr('id') + ' select.valHigh';
		var valString = valLow + ", " + valHigh;
		
		$(valString).selectToUISlider();
		
		// initialise paragraph with the values from the sliders
		var lowVal = $(this).find('select.l-range option:selected');
		var highVal = $(this).find('select.h-range option:selected');
		var para = $(this).find('p.vals');
		para.html("<span class='lval'>" + lowVal.html() + "</span> &ndash; <span class='hval'>" + highVal.html() + "</span>");
		
	 });

	$(".ui-slider-scale").addClass("reader");
	$(sliderOptions + " label").addClass("reader");
	$(sliderOptions + " select").addClass("reader");
	
}

/* Function removed on client request
FC.showSelectBox = function(){
	$(FC.vars.selectors.SELECT_LINK).show(); //show the select link
	$(FC.vars.selectors.SELECT_LINK + " a").bind("click", function(){
		var selectToShow = $(this).attr('href');
		$(selectToShow).show(); //show the select box
		$(this).parent().hide(); // hide the parent paragraph
		return false;
	});
}
*/
FC.gallery = function() {
	var $links = $(FC.vars.selectors.GALLERY);
	$links.colorbox({
		transition:"elastic", // "fade", "none"
		slideshow:false
	});
}

FC.initialiseMap = function(mapLoc){
	//var latlng = new google.maps.LatLng(-34.397, 150.644);
	var myOptions = {
	  zoom: 16,
	  center: myGeoCoords,
	  mapTypeId: google.maps.MapTypeId.ROADMAP
	};
	var map = new google.maps.Map(document.getElementById(mapLoc), myOptions);

	// Create our marker icon
	if (FC.hasIE6){
		image = "/images/icon-map-pointer.gif";
	}else{
		image = "/images/icon-map-pointer.png";
	}
				
	// Set up our marker object
	var propertyMarker = new google.maps.Marker({
		  position: myGeoCoords,
		  map: map,
		  icon: image
	  });
}


FC.gMap = function(){

	// when the colour box is opened, load the map into the bigMap div (at the bottom of the page)
//	$(FC.vars.selectors.BIGMAP).bind('click', function(){
		
//	});	

	var mapLoc = $('#bigMap');
	//open the colour box
	$(FC.vars.selectors.BIGMAP).colorbox({width:"700px", inline:true, href:"#bigMap", 
	onOpen: function(){
		
		// show the DIV
		$(mapLoc).show();
	},
	onComplete: function(){ 
		
		//open the map
		FC.initialiseMap("bigMap");
		
		// set the width to be the width of the container
		//$(mapLoc).css('width','100%');
		
		// deal with hiding the content once the color box is closed
		$('div#cboxClose').bind('click',function(){
			$(mapLoc).hide();
		});
		
		$('#cboxOverlay').bind('click',function(){
			$(mapLoc).hide();
		});

		$('div#cboxClose').text('Close Map');
	}});
		

}

FC.map = function() {
	$('map').after('<div class="mapTooltip"><div class="box-9"><div class="box-top"><div class="box-top-right">&nbsp;</div></div><div class="box-middle"><div class="box-padding clear"><div class="box-inner"><p></p></div></div></div><div class="box-bottom"><div class="box-bottom-right">&nbsp;</div></div><span class="arrow"></span></div></div>');
	var __$tooltip= $('div.mapTooltip');
	var __$boxBotR = $('div.box-bottom-right');
	var __$boxTopR = $('div.box-top-right');
	var __$tooltipContent= __$tooltip.find('p');
	var __$tooltipArrow= __$tooltip.find('span');
	var __$title;
	__$tooltip.css('left', -9999);
	__$tooltip.css('width', 30);
	
	$('area').bind('mouseenter', function(e) {
		var __$text= $(this).attr('alt'), __$coords= $(this).attr('coords'), __$coordsSplit= __$coords.split(',');
		__$title= __$text;
		__$tooltipContent.append(__$text);
		
		//remove title attribute to prevent default tooltip from appearing
		/*$(this).attr({
			title : "",
			 alt : ""
		});*/
		//IE won't set the title to nothing- tried different methods below
		//$(this)[0].alt= "";
		//$(this)[0].title= "";
		//$(this).removeAttr('title');
		$(this).removeAttr('alt'); // it doesn't help on ie6


		var __$width= __$tooltip.width();
		var __$height= __$tooltip.height();
		var __$innerWidth = __$tooltip.find(".box-inner").width();
		__$width = __$innerWidth + 32;
		__$tooltip.css('width', __$width);
		__$boxBotR.css('width', __$width - 10);
		__$boxTopR.css('width', __$width - 10);

		//__$tooltip.hide(); it's hidden and then will show when in place.  This stops the flickering.
		__$tooltip.css({
			'left' : __$coordsSplit[0]- __$width/3+'px',
			'top' : __$coordsSplit[1]-(__$height+12)+'px'
		});
		__$tooltipArrow.css('left',__$width/2-7);
		
		//odd IE7 behaviour- these 2 divs have no width, so need to set them manually
	//	if(FC.hasIE7) {
	//		__$tooltip.find('div.box-top').width(__$width-10);
	//		__$tooltip.find('div.box-bottom').width(__$width-10);
	//	}
		//__$tooltip.fadeIn(100);

	});
	
	$('area').bind('mouseleave', function(e) {
										  
		__$tooltip.css('width', 30);
		__$tooltip.css('left', -9999);
		//$(this).attr('title',__$title);
		$(this).attr('alt',__$title);
		__$tooltipContent.empty();
		
		//odd IE7 behaviour- reset div width
		if(FC.hasIE7) {
			__$tooltip.find('div.box-top').width(0);
			__$tooltip.find('div.box-bottom').width(0);
		}
	});
}

FC.predictiveSearch = function () {
    //moved __defaultVal to masterpage so it can be populated from language file
    //__defaultVal = 'e.g. Knightsbridge, London';
    __predSearch = FC.vars.selectors.PRED_SEARCH;
    /*	var searchValue = $(__predSearch).text();
    var jsonUri = FC.vars.selectors.JSONOBJECT + searchValue;
    console.log(jsonUri);*/


    //TO-Do add integrated surface
    /*	$.getJSON(jsonUri, function (data) {
    var __searchAddress = data.address;
    $(__predSearch).autocomplete({
    source: __searchAddress
    });
    });*/


    $(__predSearch).autocomplete({
        source: function (request, response) {

               // $('.ui-autocomplete').bgiframe();
            if ((request.term).match(/^[a-z 0-9]+$/i)) {
                $.ajax({
                    url: FC.vars.selectors.JSONOBJECT + request.term,
                    dataType: "json",
                    success: function (data) {
                        
                        response($(data.Address, function (item) {
                            return {
                                value: item.Address
                            }
                        }));
                    }
                });
            } else { $(__predSearch).removeClass('ui-autocomplete-loading'); }
        },
        minLength: 2

    });


    
    $(__predSearch).bind('click focus', function () {
        if ($(this).attr('value') == __defaultVal) {
            $(this).attr('value', '');
        }
    });

    $(__predSearch).bind('blur', function () {
        if ($(this).attr('value') == "") {
            $(this).attr('value', __defaultVal);
        }
    });



}

// GOOGLE DISAMBIGUATION MODAL
FC.disambigBox = function(){
	$.colorbox({inline: true, href:"#htmlInlOv", open: true, width: 960, 
		onOpen: function(){ 
			$("#htmlInlOv").show(); $("#colorbox").addClass("modal-overlay"); 
		}, 
		onCleanup: function() { $("#htmlInlOv").hide(); } 
	});
}

FC.bindLocationDropdown = function () {

    var __lDd = FC.vars.selectors.LOCATION_DROPDOWN;

    $(__lDd).bind('change', FC.locationDropdown);

}

FC.locationDropdown = function () {

    var __lDd = FC.vars.selectors.LOCATION_DROPDOWN
    var __locationOptions = '#locationOptions'
    var __predSearch = FC.vars.selectors.PRED_SEARCH;

    var optVal = $(__lDd + " :selected").val();
    if (optVal == '0') {
        $(__locationOptions).show();
    }
    else {
        $(__locationOptions).hide();
    }

//    if ((optVal == '0' && __lastSearchTypeAndRange != '0') || (optVal != '0' && __lastSearchTypeAndRange == '0')) {
//        $(__predSearch).attr('value', '');
//    }
}

//Search dropdown - getting the right buttons
FC.bindSearchDropdown = function () {

    var __sDd = FC.vars.selectors.SEARCH_DROPDOWN;

    $(__sDd).bind('change', FC.searchDropdown);

}

FC.searchDropdown = function () {

    var __sDd = FC.vars.selectors.SEARCH_DROPDOWN;
    var __btnL = '#BuyButton';
    var __btnR = '#LetButton';
    var __btnLVal = '#btnLeft';
    var __btnRVal = '#btnRight';
    var __divLocation = '#divLocation';
    var __divCountries = '#divCountries';
    var __divSector = "#divSector";

    var optVal = $(__sDd + " :selected").val();

    if ($(FC.vars.selectors.HIDE_SECTOR).val() == 'true') {
        $(__divSector).hide();
    }

    switch (optVal) {
        case "Residential":
            $(__btnLVal).attr('value', 'to Buy');
            $(__btnRVal).attr('value', 'to Rent');
            $(__btnL).show();
            $(__btnR).show();
            $(__divLocation).show();
            $(__divCountries).hide();
            break;
        case "Commercial":
            $(__btnLVal).attr('value', 'to Buy');
            $(__btnRVal).attr('value', 'to Rent');
            $(__btnL).show();
            $(__btnR).show();
            $(__divLocation).show();
            $(__divCountries).hide();
            break;
        case "Rural":
            $(__btnRVal).attr('value', 'Find properties');
            $(__btnL).hide();
            $(__btnR).show();
            $(__divLocation).show();
            $(__divCountries).hide();
            break;
        case "LandAndNewHomes":
            $(__btnLVal).attr('value', 'to Buy');
            $(__btnL).show();
            $(__btnR).hide();
            $(__divLocation).show();
            $(__divCountries).hide();
            break;
        case "Leisure":
            $(__btnRVal).attr('value', 'Find properties');
            $(__btnL).hide();
            $(__btnR).show();
            $(__divLocation).show();
            $(__divCountries).hide();
            break;
        case "International":
            $(__btnRVal).attr('value', 'Find properties');
            $(__btnL).hide();
            $(__btnR).show();
            $(__divLocation).hide();
            $(__divCountries).show();
            break;
        default:
            $(__btnLVal).attr('value', 'to Buy');
            $(__btnRVal).attr('value', 'to Rent');
            $(__btnL).show();
            $(__btnR).show();
            $(__divLocation).show();
            $(__divCountries).hide();
    }
};

// document.ready function
$(function() {
	
	FC.setJS();
	
	
	var __SEL = FC.vars.selectors, __$tmp;
	
	(function(arg) {
		for (var __i = 0, __j = arg.length, __o; __i < __j; __i++) {
			__o = arg[__i];
			(function() {
				__$tmp = $(__o.test);
				return __$tmp.length
			})() ? __o.func(__$tmp, __o.args || null) : null;
		}

	})([{ func: FC.homepageCarousel, test: __SEL.HERO_IMAGE },
		{ func: FC.carousel, test: __SEL.CAROUSEL},
		{ func: FC.tooltip, test: __SEL.TOOLTIP},
		{ func: FC.infoButton, test: __SEL.INFOBUTTON}, 
		//{ func: FC.showSelectBox, test: __SEL.SHOW_SELECT},
		{ func: FC.slidersFromSelect, test: __SEL.SLIDER_OPTIONS},
		{ func: FC.gallery, test: __SEL.GALLERY},
		{ func: FC.map, test: __SEL.MAP},
		{ func: FC.accordion, test: __SEL.ACCORDION},
		{ func: FC.gMap, test: __SEL.BIGMAP },
		{ func: FC.searchDropdown, test: __SEL.SEARCH_DROPDOWN },
		{ func: FC.bindSearchDropdown, test: __SEL.SEARCH_DROPDOWN },
		{ func: FC.predictiveSearch, test: __SEL.PRED_SEARCH},
		{ func: FC.locationDropdown, test: __SEL.LOCATION_DROPDOWN},
		{ func: FC.bindLocationDropdown, test: __SEL.LOCATION_DROPDOWN }
	]);
	
	
	if(typeof modal != 'undefined'){
		if (modal){FC.disambigBox();}
	}



})















