function getQueryVariable(variable){
	
	var query = window.location.search.substring(1);
	var vars = query.split("&");
	
	for (var i=0;i<vars.length;i++){
		var pair = vars[i].split("=");
		if (pair[0] == variable){
			return pair[1];
		}
	}
} 

$(document).ready(function(){
	
	var curOffice = parseInt(getQueryVariable("office")); 
	if( isNaN(curOffice) ){ curOffice = "false"; }
	$("#accordContactMain").accordion({header: 'h4', autoHeight: false, active: curOffice, collapsible: true});
	
	$("#accordContactMain .contactPerson").hover(
			function(){
				// over
				if( $(this).find("img").length > 0 ){
					$(this).find("img").stop().fadeTo(300, 1);
					//$("#fuelImage img").stop().fadeTo(500, 0.5);
				}
				
			}, function() {
				// out
				if( $(this).find("img").length > 0 ){
					$(this).find("img").stop().fadeTo(300, 0);
					//$("#fuelImage img").stop().fadeTo(500, 1);
				}
			}
	);
	
	if ( $("#accordUK").next().find("img").length > 0 && !isNaN(curOffice) ) {
		$("#fuelImage img").stop().fadeTo(500, 0);
	}
	
	$("#accordContactMain h4").click( function(){
		if( $(this).attr("id") == "accordUK" ||
			$(this).attr("id") == "accordBrazil" ||
			$(this).attr("id") == "accordChina"  ||
			$(this).attr("id") == "accordFrance" ||
			$(this).attr("id") == "accordHongKong" ||
			$(this).attr("id") == "accordKorea" ||
			$(this).attr("id") == "accordSingapore" ||
			$(this).attr("id") == "accordSouthAfrica" ) {
			if ( $(this).next().find("img").length > 0 ) {
				$("#fuelImage img").stop().fadeTo(500, 0);
			} else {
				$("#fuelImage img").stop().fadeTo(500, 1);				
			}
		} else {
			$("#fuelImage img").stop().fadeTo(500, 1);
		}
	});
	
	
});
