//Declared Varialbes
var propertyListingTitle	= "";
var resetVal 				= 0;
var headerCounter 			= 0;
var	icounter				= 0;
var displayColCounter = 0;
var tempBrandVal 			= "";
var tempCountryVal 			= "";
var tempCityVal 			= "";
var tempHeaderTop			= "";
var tempBodyTop				= "";

var cookie_mapView 			= "";
var cookie_listView 		= "";
var cookie_BrandDDL 		= "";
var cookie_CountryDDL 		= "";
var cookie_CityDDL 			= "";
var options 				= { path: '/', expires: 2 };

var tempCookie_BrandDDL 	= "";
var tempCookie_CountryDDL	= "";
var tempCookie_CityDDL 		= "";
var trigger 				= "0";

//Tab Function for MapView
function MapView() {
	tempBrandVal = $("option:selected", "#wmap_brand").val(); //$("#wmap_brand").val();
	if($("option:selected", "#wmap_country").val().indexOf(",") > 0)
		tempCountryVal = $("option:selected", "#wmap_country").val().replace(",","").replace(" ","-");
	
	if(tempCountryVal==undefined || tempCountryVal=="")
		tempCountryVal = $("option:selected", "#wmap_country").val(); //$("#wmap_country").val();
	
	tempCityVal = $("option:selected", "#wmap_city").val(); //$("#wmap_city").val();
	
	
	
	$("#map_view_tab").attr("class","tabSelected");
	$("#list_view_tab").attr("class","tab");
	 
	$("#listContainer").hide();
	
	try {
		
		if(tempBrandVal.length > 0 || tempCountryVal.length > 0 || tempCityVal.length > 0) {
			$("#map").show();
			if(trigger=="1") { map.checkResize(); wmap_zoomAndShowMarkers(); trigger="0"; }
			$("#googleMapLengend").show();
			$("#staticMap").hide();	
		}
		else {
			$("#map").hide(); 
			$("#staticMap").show();	
			$("#googleMapLengend").hide();
		}	
	}
	catch(e) {  }
		
	$.cookie('cookie_mapView', "1");
	$.cookie('cookie_listView', "0");
	
} //end MapView Function

//Tab Function for ListView
function ListView() {
	$("#list_view_tab").attr("class","tabSelected");
	$("#map_view_tab").attr("class","tab");
	 
	$("#map").hide();
	$("#staticMap").hide();
	$("#googleMapLengend").hide();
	 
	$("#listContainer").show();
	
	$.cookie("cookie_mapView", "0");
	$.cookie("cookie_listView", "1");
} //end ListView Function

//Reset Function
function resetList() {

	if(resetVal == 0) {
		$("#property-list-full div > *").show();
		try { wmap_reset();	}
		catch(e) { }
		
		$("#property-list-full").show();
		$(".other-brands").remove();

		$("div.brand_Ascott").hide();
		$("div.brand_Somerset").hide();
		$("div.brand_Citadines").hide();
		$("div.brand_Non-Brand").hide();
		
		$("#wmap_brand").find('option:first').attr('selected', 'selected');
		$("#wmap_country").find('option:first').attr('selected', 'selected');
		$("#wmap_city").find('option:first').attr('selected', 'selected');
	}
	else {
		$("#property-list-full div > *").show();
		$("div.brand_Ascott div > *").show();
		$("div.brand_Somerset div > *").show();
		$("div.brand_Citadines div > *").show();
		$("div.brand_Non-Brand div > *").show();
	}
	$("div#listContainer").find(".col-1").show();

}//end resetList Function

//Filter/Find By Country
function filterCountry() {

	$("div.brand_Citadines").hide();
	$("div.brand_Ascott").hide();
	$("div.brand_Somerset").hide();
	$("div.brand_Non-Brand").hide();
	
	try {	
		if(tempCountryVal != "" && tempBrandVal == "") {
			$("#property-list-full").show();
			$("#property-list-full div > *").hide();

			$("#property-list-full").find("h3").each(function() {
				var tempCountryVal2 = $.trim($(this).attr("class").replace("country_","").replace("right-list",""));
				tempCountryVal2 = tempCountryVal2.replace(" ","-").replace(",","");
				tempCountryVal = tempCountryVal.replace(" ","-").replace(",","");
				if(tempCountryVal2 == tempCountryVal)
					$(this).show();
			}); //end find h3

			if($("#wmap_city").val() == "") {
				$("#property-list-full").find("h4").each(function() {
					var tempCityVal2 = $(this).attr("class").substring(0,$(this).attr("class").indexOf(" ")).replace("country_","");
					tempCountryVal = tempCountryVal.replace(" ","-").replace(",","");
					if(tempCityVal2 == tempCountryVal) {
						$(this).show();
						$(this).next().show(function(){ $(this).find("li").each(function() { $(this).show(); }); });
					}
				}); //end find h4
			} //end if tempCityVal
			else {
				var tempCity = $("#wmap_city").val().substring(0,$("#wmap_city").val().indexOf("|"));
				$("#property-list-full").find("h4").each(function() {
					var tempCityVal2 = $(this).attr("class").split(" ");
					tempCityVal2 = tempCityVal2[1].replace("city_","");
					tempCityVal2 = tempCityVal2.replace(" ","-").replace(",","");
					tempCity = tempCity.replace(" ","-").replace(",","");
					if(tempCityVal2 == tempCity) {
						$(this).show();
						$(this).next().show(function(){ $(this).find("li").each(function() { $(this).show(); }); });
					}
				}); //end find h4
			} //end else
		}
		else {

			$("#property-list-full").find("h4").each(function() { $(this).next().show(function(){ $(this).find("li").each(function() { $(this).show(); }); });});
			$("#property-list-full").hide();
			$("div.brand_Citadines").show();
			$("div.brand_Ascott").show();
			$("div.brand_Somerset").show();
			$("div.brand_Non-Brand").show();
			
			$("div.brand_"+tempBrandVal).insertAfter("#property-list-full");
			$(".other-brands").remove();

			var foundAscott = false;
			var foundSomerset = false;
			var foundCitadines = false;
			var foundOtherBrands = false;
			
			if(tempCountryVal != "") {
				
				$("div.brand_Citadines div > *").hide();
				$("div.brand_Ascott div > *").hide();
				$("div.brand_Somerset div > *").hide();
				$("div.brand_Non-Brand div > *").hide();
				
				$("div.brand_Non-Brand").find("h3").each(function() {
					var tempCountryVal2 = $.trim($(this).attr("class").replace("country_","").replace("right-list",""));
					tempCountryVal2 = tempCountryVal2.replace(" ","-").replace(",","");
					tempCountryVal = tempCountryVal.replace(" ","-").replace(",","");
					if(tempCountryVal2 == tempCountryVal)
						$(this).show();

				}); //end find h3
				
				$("div.brand_Citadines").find("h3").each(function() {
					var tempCountryVal2 = $.trim($(this).attr("class").replace("country_","").replace("right-list",""));
					tempCountryVal2 = tempCountryVal2.replace(" ","-").replace(",","");
					tempCountryVal = tempCountryVal.replace(" ","-").replace(",","");
					if(tempCountryVal2 == tempCountryVal)
						$(this).show();
				}); //end find h3
				
				$("div.brand_Ascott").find("h3").each(function() {
					var tempCountryVal2 = $.trim($(this).attr("class").replace("country_","").replace("right-list",""));
					tempCountryVal2 = tempCountryVal2.replace(" ","-").replace(",","");
					tempCountryVal = tempCountryVal.replace(" ","-").replace(",","");
					if(tempCountryVal2 == tempCountryVal)
						$(this).show();
					
				}); //end find h3
				
				$("div.brand_Somerset").find("h3").each(function() {
					var tempCountryVal2 = $.trim($(this).attr("class").replace("country_","").replace("right-list",""));
					tempCountryVal2 = tempCountryVal2.replace(" ","-").replace(",","");
					tempCountryVal = tempCountryVal.replace(" ","-").replace(",","");
					if(tempCountryVal2 == tempCountryVal)
						$(this).show();
				}); //end find h3
	
				if($("#wmap_city").val() == "") {
					$("div.brand_Non-Brand").find("h4").each(function() {
						var tempCityVal2 = $(this).attr("class").substring(0,$(this).attr("class").indexOf(" ")).replace("country_","");
						tempCountryVal = tempCountryVal.replace(" ","-").replace(",","");
						if(tempCityVal2 == tempCountryVal) {
							$(this).show();
							$(this).next().show(function(){ $(this).find("li").each(function() { $(this).show(); }); });
							foundOtherBrands = true;
						}
					}); //end find h4
					
					$("div.brand_Citadines").find("h4").each(function() {
						var tempCityVal2 = $(this).attr("class").substring(0,$(this).attr("class").indexOf(" ")).replace("country_","");
						tempCountryVal = tempCountryVal.replace(" ","-").replace(",","");
						if(tempCityVal2 == tempCountryVal) {
							$(this).show();
							$(this).next().show(function(){ $(this).find("li").each(function() { $(this).show(); }); });
							foundCitadines = true;
						}
					}); //end find h4
					
					$("div.brand_Ascott").find("h4").each(function() {
						var tempCityVal2 = $(this).attr("class").substring(0,$(this).attr("class").indexOf(" ")).replace("country_","");
						tempCountryVal = tempCountryVal.replace(" ","-").replace(",","");
						if(tempCityVal2 == tempCountryVal) {
							$(this).show();
							$(this).next().show(function(){ $(this).find("li").each(function() { $(this).show(); }); });
							foundAscott = true;
						}
					}); //end find h4
					
					$("div.brand_Somerset").find("h4").each(function() {
						var tempCityVal2 = $(this).attr("class").substring(0,$(this).attr("class").indexOf(" ")).replace("country_","");
						tempCountryVal = tempCountryVal.replace(" ","-").replace(",","");
						if(tempCityVal2 == tempCountryVal) {
							$(this).show();
							$(this).next().show(function(){ $(this).find("li").each(function() { $(this).show(); }); });
							foundSomerset = true;
						}
					}); //end find h4
				} //end if tempCityVal
				else {
					var tempCity = $("#wmap_city").val().substring(0,$("#wmap_city").val().indexOf("|"));
					tempCity = tempCity.replace(" ","-").replace(",","");

					$("div.brand_Non-Brand").find("h4").each(function() {
						var tempCityVal2 = $(this).attr("class").split(" ");
						tempCityVal2 = tempCityVal2[1].replace("city_","");
						tempCityVal2 = tempCityVal2.replace(" ","-").replace(",","");
						if(tempCityVal2 == tempCity) {
							$(this).show();
							$(this).next().show(function(){ $(this).find("li").each(function() { $(this).show(); }); });
							foundOtherBrands = true;
						}
					});
					
					$("div.brand_Citadines").find("h4").each(function() {
						var tempCityVal2 = $(this).attr("class").split(" ");
						tempCityVal2 = tempCityVal2[1].replace("city_","");
						tempCityVal2 = tempCityVal2.replace(" ","-").replace(",","");
						if(tempCityVal2 == tempCity) {
							$(this).show();
							$(this).next().show(function(){ $(this).find("li").each(function() { $(this).show(); }); });
							foundCitadines = true;
						}
					}); //end find h4
					
					$("div.brand_Ascott").find("h4").each(function() {
						var tempCityVal2 = $(this).attr("class").split(" ");
						tempCityVal2 = tempCityVal2[1].replace("city_","");
						tempCityVal2 = tempCityVal2.replace(" ","-").replace(",","");
						if(tempCityVal2 == tempCity) {
							$(this).show();
							$(this).next().show(function(){ $(this).find("li").each(function() { $(this).show(); }); });
							foundAscott = true;
						}
					}); //end find h4
					
					$("div.brand_Somerset").find("h4").each(function() {
						var tempCityVal2 = $(this).attr("class").split(" ");
						tempCityVal2 = tempCityVal2[1].replace("city_","");
						tempCityVal2 = tempCityVal2.replace(" ","-").replace(",","");
						if(tempCityVal2 == tempCity) {
							$(this).show();
							$(this).next().show(function(){ $(this).find("li").each(function() { $(this).show(); }); });
							foundSomerset = true;
						}
					}); //end find h4
				} //end else
				
				if(!foundAscott) { $("div.brand_Ascott").hide(); }
				if(!foundSomerset) { $("div.brand_Somerset").hide(); }
				if(!foundCitadines) { $("div.brand_Citadines").hide(); }	
				if(!foundOtherBrands) { $("div.brand_Non-Brand").hide(); }
				
				var countDisplay = 0;
				$("#listContainer").children("div").each(function() {
					if($(this).css("display") == "block")
						countDisplay += 1;
				});
				if(countDisplay > 1) $("<h2 class=\"other-brands\">"+otherProperties+"</h2>").insertAfter("div.brand_"+tempBrandVal);

			}
		}
		resetVal = 0;
		
		$("div#listContainer").find(".col-1").each(function(){												
			$(this).find("h3").each(function() {
				if($(this).css("display") == "block")
					displayColCounter = displayColCounter+1;
			});		
			if(displayColCounter < 1)
				$(this).hide();
			displayColCounter = 0;
		});
		
	}	
	catch(e) { }
	
	tempCountryVal = "";
	tempCityVal = "";

}//end filterCountry Function

function getUrlVars() {
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
    for(var i = 0; i < hashes.length; i++) {
        hash = hashes[i].split('=');
        vars.push(hash[0]);
        vars[hash[0]] = hash[1];
    }
    return vars;
}//end getUrlVars Function

function wmapFuncInit() {

	$("#map").before(TABS);
	$("#map").hide();
	$("#panel-map-tools").hide();
	$("#listContainer").hide();

	$("div.brand_Ascott").hide();
	$("div.brand_Somerset").hide();
	$("div.brand_Citadines").hide();
	$("div.brand_Non-Brand").hide();
	$("#wmap_go").attr("value",findBtn);
	$("#wmap_reset").hide();
	$("#wmap_reset").after("<a id='resLink' href='javascript:;'>"+resetTranslate+"</a>");
	$("#resLink").bind("click", function() { resetList(); });
	$("#map_view_tab").bind("click", function() { MapView(); });
	$("#list_view_tab").bind("click", function() { ListView(); });
	
	if(temp_cookieMapView == "1") { $("#map_view_tab").trigger("click"); }
	else { $("#list_view_tab").trigger("click"); }

}//end wmapFuncInit Function
