
$(document).ready(function() {
	
	$("div.accordionButton").css("display","block");
	
	//HIDE ALL Center DIV ON PAGE LOAD	
	//$("#allCenter").hide();
	
	//ACCORDION BUTTON ACTION	
	$("div.accordionButton").click(function() {
		if ($(this).is(".accordionButtonSelected")){
			$("div.accordionContent").slideUp("normal");
			$(this).removeClass().addClass("accordionButton");
		} else {
			$("div.accordionContent").slideUp("normal");
			$(this).next().slideDown("normal");
			$("div.accordionButtonSelected").removeClass().addClass("accordionButton");
			$(this).removeClass().addClass("accordionButtonSelected");
		}
	});
	//ACCORDION BUTTON ACTION	
	$("div.accordionButtonSelected").click(function() {
		if ($(this).is(".accordionButtonSelected")){
			$("div.accordionContent").slideUp("normal");
			$(this).removeClass().addClass("accordionButton");
		} else {
			$("div.accordionContent").slideUp("normal");
			$(this).next().slideDown("normal");
			$("div.accordionButtonSelected").removeClass().addClass("accordionButton");
			$(this).removeClass().addClass("accordionButtonSelected");
		}
	});
/*
	// ANCHOR SORT DINAMIC STYLE (ABC	DEF	GHI)
	$(".sortDealersList a,.sortDealersList a:hover,.sortDealersList a:visited,").click(function () {
		Cufon.replace($(".sortDealersList a"));
		Cufon.replace($(this),{color: '#cc0033'});
		$(".sortDealersList a").css("border-bottom","1px solid #666666");
		$(this).css("border-bottom","1px solid #cc0033");
	});
*/
		
	/*	SORT ANCHOR ACTION (ABC	EFD)	*/
	$(".sortBt").click(function (){ 
		$(".dealerSort").css("display","none");
	});
	$(".all").click(function (){ 
		$(".dealerSort").css("display","block");
	});
	$(".sortABC").click(function (){ 
		$(".ABC").css("display","block");
	});
	$(".sortDEF").click(function (){ 
		$(".DEF").css("display","block");
	});
	$(".sortGHI").click(function (){ 
		$(".GHI").css("display","block");
	});
	$(".sortJKL").click(function (){ 
		$(".JKL").css("display","block");
	});
	$(".sortMNO").click(function (){ 
		$(".MNO").css("display","block");
	});
	$(".sortPQRS").click(function (){ 
		$(".PQRS").css("display","block");
	});
	$(".sortTUV").click(function (){ 
		$(".TUV").css("display","block");
	});
	$(".sortWXYZ").click(function (){ 
		$(".WXYZ").css("display","block");
	});

	// DEFAUL ANCHOR SORT
	$(".sortABC").click();

});
function getDirections(startPoint, toAddress){
	
	var D_map = new GMap2(document.getElementById("map-areaS"));
	mercatorToLatLong(centerMX, centerMY);
	var dealer = new GLatLng(dealerLat,dealerLon);
	startPoint+= " UK"
	
	geocoder.getLatLng(startPoint, function(pointPC) {
		if (!pointPC) {
			alert("Postcode not found");
			$("#postcode2").focus();      
		} 
		else {
		
			$("#directionListContent").html("");
			var directions = new GDirections(D_map,document.getElementById("directionListContent"));
			
			var arrLocation = new Array(2);
			arrLocation[0] = startPoint;
			arrLocation[1] = dealer;
			
			//Clear the mapa nd directions of any old information
			directions.clear();
			//Load the map and directions from the specified waypoints
			
			directions.loadFromWaypoints(arrLocation);			
			
			GEvent.addListener(directions,"addoverlay", function() {
																 
				$("div[jsselect='Placemark'] table:first").css("display","none");
				$("div[jsselect='Placemark']:last").css("display","none");
				$("div[jsselect='Placemark']:last + div").css("display","none");	
				
				$("div[jsselect='Placemark'] > div > div").css("display","none");
				$("div[jsselect='Placemark'] > div > table > tbody > tr > td").css({'border' : '0', 'padding' : '5px 10px 5px 20px'});
				//$("div[jsselect='Placemark'] > div > table > tbody > tr > td").addClass("txtCufon");
				
				dirHeader= "<tr><td colspan='3' style='background:#ffffff;'>"
				dirHeader+= "<ul class='printLink'><li><a href='javascript:document.printversion.fromAddress.value=document.directions.from.value; document.printversion.submit();' class='txtCufon'>Printer friendly version</a></li></ul>"
				dirHeader+= "</td></tr><tr><td colspan='2' style='background:#ffffff;padding-bottom:8px;padding-left:20px;'><span class='txtCufon titleDir'>Instruction</span></td>"
				dirHeader+= "<td style='background:#ffffff;padding-bottom:8px;padding-right:8px;'><span class='txtCufon titleDir'>Distance</span></td><tr>"
				
				$("#directionListContent > div > div > div > div > table > tbody > tr:first ").before(dirHeader);
				
				$("div[jsselect='Placemark'] > div > table > tbody > tr").css({'font-size' : '12px', 'font-family' : 'Arial'});	
				$("div[jsselect='Placemark'] > div > table > tbody > tr").attr("jsinstance", function (arr) {
					numType = (arr %2 == 1 ?  true : false);
					if(numType == true)
						$(this).css("background","#F3F3F2");	
				})
								
				//Cufon.refresh(".txtCufon");
				
				$("#directions").css("display","block");
				$("#localCenterSlideAndAllCenter").css("display","none");
				
				// DISPLAY DIRECTION SLIDE 
				$("#accordionList").css("display","block");
				$("div.accordionButtonSelected").removeClass().addClass("accordionButton");
				$("#directionsButton").removeClass().addClass("accordionButtonSelected");
				// -----------------------
			});
		}
	});
	D_map.addControl(new GLargeMapControl3D());
		D_map.enableScrollWheelZoom();
		var mapTypeControl = new GMapTypeControl();
		var topRight = new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(10,10));
		D_map.addControl(mapTypeControl, topRight);	
		D_map.enableDoubleClickZoom();
}
/*
Cufon.replace('h2,h3,h4,h5', {fontFamily:'Toyota Display'});
Cufon.replace('.titleCufon', {fontFamily:'Toyota Display'});	
Cufon.replace('.txtCufon', {fontFamily:'Toyota Text'});*/
