///////////Declared Varialbes
var propertyListingTitle	= "";
var resetVal 				= 0;
var headerCounter 			= 0;
var	icounter				= 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();
	tempCountryVal = $("option:selected", "#wmap_country").val();
	tempCityVal = $("option:selected", "#wmap_city").val();

	$("#map_view_tab").attr("class","tabSelected");
	$("#list_view_tab").attr("class","tab");
	 
	$("#propertyList").hide();
	
	try {
		if(tempBrandVal != "" || tempCountryVal != "" || tempCityVal != "") {
			$("#map").show();
			if(trigger=="1") { map.checkResize(); wmap_zoomAndShowMarkers(); trigger="0"; }
			$("#googleMapLengend").show();
			$("#staticMap").hide();	
		}
		else {
			$("#map").hide(); 
			$("#staticMap").show();		
		}	
	}
	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();
	 
	$("#propertyList").show(); 
	
	$.cookie("cookie_mapView", "0");
	$.cookie("cookie_listView", "1");
} ///////////end ListView Function

///////////Reset Function
function resetList() {
	$("#tempTop").remove();
	$("#DefaultList").show();
	$("#ConditionalList").find("tr").each(function() { $(this).show(); });	
	$("#ConditionalList").find("h1").each(function() { $(this).show(); });
	
	$("#propertyList").find("tr").each(function() { $(this).show(); });
	$("#propertyList").find("td").each(function() { $(this).show(); });
	
	///////////Show all Countries
	$(".list").find("h2").each(function() { $(this).show(); $(this).next().show(); });
	
	///////////Show all Cities
	$(".list").find("h5").each(function() { $(this).show(); $(this).parent().show(); $(this).next().show(); });
	$(".list").find("li").each(function() { $(this).show(); });
	
	$(".PropListHeader2").show(); 

	if(resetVal == 0) {
		
		try {
			wmap_reset();
		}
		
		catch(e) { }
		
		$("#wmap_brand").find('option:first').attr('selected', 'selected');
		$("#wmap_country").find('option:first').attr('selected', 'selected');
		$("#wmap_city").find('option:first').attr('selected', 'selected');
		
		$("#DefaultList h1").text(defaultListTitle);
		$("#ConditionalList").hide();
		
		$("#googleMapLengend").hide();
		$("#map").hide();
		
		if($("#propertyList").css("display") != "block") {
			$("#staticMap").show();	
		}
		translateCountryCity();
	}
}///////////end resetList Function

///////////Filter/Find By Brand
function filterBrand() {	
	try {
		if(tempCountryVal == "") { resetVal = 1; resetList(); }
		
		if(tempBrandVal != "") {	
			propertyListingTitle = tempBrandVal + " " + propertyListingTitle;
			$("#DefaultList h1").text(propertyListingTitle);
			
			///////////Hide Properties, Countries, Cities Not from Selected BRAND
			$("#DefaultList ul li ul li:not(:contains("+tempBrandVal+"))").filter(function() { $(this).hide(); });
			
			/* hide using class - for multi-lang - attention needed
			$("#DefaultList ul li ul").find("li").each(function() {
				if($(this).attr("class")!=tempBrandVal) {
					$(this).hide();
				} 
			}); */
			
			$("#DefaultList ul:not(:contains("+tempBrandVal+"))").filter(function() { $(this).hide(); $(this).prev().hide(); });
			
			///////////Hide City with no Brand
			$(".list").find("h5").each(function() { if($(this).css("display") == "none") $(this).parent().hide(); });
			
			///////////Hides Selected Brand on ConditionalList
			$("#ConditionalList").show();
			
			$("#ConditionalList tr.headerTitle").find("h1").each(function() {
				if($(this).attr("class")==tempBrandVal) { 			
					///////////Added Code for Layout Issue
					tempHeaderTop = $(this).parent().parent();
					tempBodyTop = $(this).parent().parent().next();
					
					$("#DefaultList").before("<div id=\"tempTop\"><table><tbody><tr class=\"headerTitle\">" + $(tempHeaderTop).html() + "</tr>" + $(tempBodyTop).html() + "</div>");
					$("#DefaultList").hide();
					///////////END of Added Code for Layout Issue

					$(this).hide();
					$(this).parent().parent().next().hide();
				}
			});
	
			///////////end Hide Properties, Countries, Cities Not from Selected BRAND
		}
		else {
			$("#DefaultList h1").text(defaultListTitle);
			$("#ConditionalList").hide();	
		}
		resetVal = 0;		
	}
	catch(e) {}
	
}///////////end filterBrand Function

///////////Filter/Find By Country
function filterCountry() {
	try {
		if(tempBrandVal == "" && tempCityVal == "") { resetVal = 1; resetList(); }
		
		if(tempCountryVal != "") {
			$(".list").find("h2").each(function() {
				tempCountryVal2 = "h2_" + tempCountryVal;
				if($(this).attr("class") != tempCountryVal2) {
					$(this).hide(); 
					$(this).next().hide();
				}
			});
			
			///////////not multi-lang need attention later
			$("#propertyList td:contains("+tempCountryVal+")").filter(function() {
				if($(this).text() != tempCountryVal) $(this).prev().hide();
			});	
			$("#ConditionalList .bodyList:not(:contains("+tempCountryVal+"))").filter(function() { $(this).prev().hide(); });	
			$("#ConditionalList").find(".bodyList").each(function() {
				$(this).find("h2").each(function() {
					if($(this).attr("class") == tempCountryVal2) {
					icounter = icounter + 1;
					}
				});
				if(icounter == 1) {
					$(this).prev().show();
				}
				icounter = 0;
			});

			///////////Hide/Show GreenBox Sep
			$("#ConditionalList").find(".headerTitle").each(function() {
				if($(this).css("display") == "none") headerCounter = headerCounter + 1;	
			});
			
			if(headerCounter >= 3) { $(".PropListHeader2").hide(); }
			else { $(".PropListHeader2").show(); }
			headerCounter = 0; 
			
		}
		resetVal = 0;	
	}	
	catch(e) { }

}///////////end filterCountry Function

///////////Filter/Find By City
function filterCity() {	
	try {
		if(tempCityVal != "") {
			$(".list").find("h5").each(function() {
				tempCityVal2 = "h5_" + tempCityVal;
				if($(this).attr("class") != tempCityVal2) {
					$(this).parent().hide();
					$(this).next().hide();
				}
			});
			
			$("#ConditionalList .list ul").find("h5").each(function() {
				if($(this).attr("class") == tempCityVal2) { 
					icounter = icounter + 1;
				}
				if(icounter <= 0) {
					$(this).parent().parent().prev().hide();
				}
				icounter = 0;
			});
			
			$(".bodyList:not(:contains("+tempCityVal+"))").filter(function() { $(this).prev().hide(); });
	
			$("#ConditionalList").find(".headerTitle").each(function() {
				if($(this).css("display") == "none") headerCounter = headerCounter + 1;
			});
			
			if(headerCounter >= 3) { $(".PropListHeader2").hide(); }
			else { $(".PropListHeader2").show(); }
			headerCounter = 0; 
		}	
	}
	catch(e) { }

}///////////end filterCity 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);
	$("#panel-map-tools").hide();
	$("#map").hide();
	$("#wmap_go").attr("value","");
	$("#wmap_go").css("background",findBtn);
	$("#wmap_reset").hide();
	$("#wmap_reset").after("<a id='resLink' href='javascript:;'>"+resetTranslate+"</a>");
	$("#resLink").bind("click", function() { resetList(); });
	$("#mapTab").bind("click", function() { MapView(); });
	$("#listTab").bind("click", function() { ListView(); });
	
	if(temp_cookieListView == "1") { $("#listTab").trigger("click"); }
	else { $("#mapTab").trigger("click"); }
	resetList();
}///////////end wmapFuncInit Function