// Switch contact details displayed on homepage

function log(msg){
    if (window.console && console.log) console.log(msg);
}

function getContact(n) {
//	log(n);
	return $(".contactDetails:eq("+n+")");
};

$(function() {
	$(".contactDetails").hide();
	
	$("select#to").change(function(){
		// Show the contact details
		$('.contactDetails').hide();
		getContact($(this).find("option:selected").attr("detail")).show();
		
		if($('#map')[0]) {
			// Update map
			var address = getContact($(this).find("option:selected").val()).val();
			setPoint('to', address, $(this).val());
		}
	});
	
	$('a.sub_sub_nav').click(function() {
		// hide unclicked navigation items
		var _this = this;
		$(this).parent().children("a").each(function(i) {
			if($(this).parent().children("a")[i] != _this) {
				$($(this).parent().children("a")[i]).hide();
			}

	    });

		// insert extra navigation
		if($(this).text().toLowerCase() == "service" || $(this).text().toLowerCase() == "parts" || $(this).text().toLowerCase() == "specials" || $(this).text().toLowerCase() == "finance") {
			switch($(this).text().toLowerCase()) {
				case 'specials':
					$(this).after(" <a href='ford_" + $(this).text().toLowerCase() +".html'>Ford " + $(this).text() + "</a> <a href='fpv_" + $(this).text().toLowerCase() + ".html'>FPV " + $(this).text() + "</a> <a href='http://www.camberwellvolkswagen.com.au/volkswagen-" + $(this).text().toLowerCase() + "'>Volkswagen " + $(this).text() + "</a> <a href='skoda/skoda_" + $(this).text().toLowerCase() + ".html'>Skoda " + $(this).text() + "</a> <a href='javascript: void(0);' id='cancel_temp'>Close</a>");
				break;
				
				default: 
					$(this).after(" <a href='ford_" + $(this).text().toLowerCase() +".html'>Ford " + $(this).text() + "</a> <a href='fpv_" + $(this).text().toLowerCase() + ".html'>FPV " + $(this).text() + "</a> <a href='http://www.camberwellvolkswagen.com.au/volkswagen-" + $(this).text().toLowerCase() + "'>Volkswagen " + $(this).text() + "</a> <a href='peugeot_home.html'>Peugeot " + $(this).text() + "</a> <a href='skoda/skoda_" + $(this).text().toLowerCase() + ".html'>Skoda " + $(this).text() + "</a> <a href='javascript: void(0);' id='cancel_temp'>Close</a>");
				break;
			}
		} else {
			switch($(this).text().toLowerCase()) {
				case 'transmissions':
					$(this).after("<span class='subnav_description'>click for</span> <a href='ford_" + $(this).text().toLowerCase() +".html'>Ford Trans.</a> <a href='fpv_" + $(this).text().toLowerCase() + ".html'>FPV Trans.</a> <a href='http://www.camberwellvolkswagen.com.au/volkswagen-" + $(this).text().toLowerCase() + "'>Volkswagen Trans.</a> <a href='peugeot_home.html'>Peugeot Trans.</a> <a href='skoda/skoda_" + $(this).text().toLowerCase() + ".html'>Skoda Trans.</a> <a href='javascript: void(0);' id='cancel_temp'>Close</a>");
				break;
				default:
					return;
				break;
			}
		}

		// attach event for cancel button
		$('a#cancel_temp').click(function() {
			// remove temp nav
			$(this).parent().children("a:not(.sub_sub_nav)").remove();
			$(".subnav_description").remove();
			// show all sub sub nav items and deselect current item
			$("a.sub_sub_nav").show();
			
		});
	});
});
