/*
* google maps loading code
*/
/*var map;
var gDir;
var point

function gMapLoad() {
	if (GBrowserIsCompatible()) {

		map = new GMap2(document.getElementById("map"));
		point= new GLatLng(52.588842,-1.254706); //52.523147,-1.296558
		map.setCenter(point, 11);
		map.addControl(new GSmallZoomControl());

		var marker=new GMarker(point);
		var windowContent="<b>Freestyle Designs &amp; Fabrication Ltd</b><br />The Old Sawmill<br />Enderby Road<br />Thurlaston<br />Leicester<br/>LE9 7TF<br /><br />\n\
<strong>01455 888 618</strong><br /><br /><form action=\"http://maps.google.co.uk/maps\" method=\"get\" target=\"_blank\">\n\
<input id=\"daddr\" class=\"text\" type=\"hidden\" size=\"10\" value=\"LE9 7TF\" name=\"daddr\"/><label for='saddr'>Enter your postcode</label><br /><input id=\"saddr\" class=\"text\" type=\"text\" size=\"10\" value=\"\" name=\"saddr\" style=\"margin-right:10px;\" /><input type='submit' value='Get Directions!' name='submit'  /><br /><p style=\"font-size:10px;\">directions open in a new window</p></form>"
		map.addOverlay(marker);
		//GEvent.addListener(marker, "click", function() {
		marker.openInfoWindowHtml(windowContent);
		//});
		GEvent.addListener(marker,"click",function(){
			marker.openInfoWindowHtml(windowContent);
		});

		gDir=new GDirections(map,document.getElementById("directionsCon"));
		GEvent.addListener(gDir,"load",onGDirectionsLoad);
		GEvent.addListener(gDir, "error", handleErrors);
	//setDirections("LE11 1NL");

	}

}

function setDirections(fromAddress){
	//alert (fromAddress);
	gDir.load("from: "+fromAddress+", UK to: 52.588842,-1.254706");
}

function onGDirectionsLoad(){
//don't know what to do here....
//document.getElementById("directionsCon").innerHTML = gDir.getStatus().code;
}

function handleErrors(){
	if (gDir.getStatus().code == G_GEO_UNKNOWN_ADDRESS)
		alert("No corresponding geographic location could be found for one of the specified addresses. This may be due to the fact that the address is relatively new, or it may be incorrect.\nError code: " + gDir.getStatus().code);
	else if (gDir.getStatus().code == G_GEO_SERVER_ERROR)
		alert("A geocoding or directions request could not be successfully processed, yet the exact reason for the failure is not known.\n Error code: " + gDir.getStatus().code);

	else if (gDir.getStatus().code == G_GEO_MISSING_QUERY)
		alert("The HTTP q parameter was either missing or had no value. For geocoder requests, this means that an empty address was specified as input. For directions requests, this means that no query was specified in the input.\n Error code: " + gDir.getStatus().code);

	// else if (gDir.getStatus().code == G_UNAVAILABLE_ADDRESS) <--- Doc bug... this is either not defined, or Doc is wrong
	// alert("The geocode for the given address or the route for the given directions query cannot be returned due to legal or contractual reasons.\n Error code: " + gDir.getStatus().code);

	else if (gDir.getStatus().code == G_GEO_BAD_KEY)
		alert("The given key is either invalid or does not match the domain for which it was given. \n Error code: " + gDir.getStatus().code);

	else if (gDir.getStatus().code == G_GEO_BAD_REQUEST)
		alert("A directions request could not be successfully parsed.\n Error code: " + gDir.getStatus().code);

	else alert("An unknown error occurred.");
}*/
		 
function removeFilter() {
	var el = document.getElementById("colorbox");
	if (el.style.filter && el.style.removeAttribute){
		el.style.removeAttribute("filter");
	}
}

		 
//jQuery
$(document).ready(function() {

	//$( "#datepicker" ).datepicker({ dateFormat: 'dd/mm/yy' });
	$("#solarEstimator").colorbox({
		width:"990px",
		height:"80%",
		iframe:true,
		onLoad:
		function(){
			$(".videoModule").hide();
		},
		onClosed:
		function(){
			$(".videoModule").show();
		}
	});
	$("#windspeedChecker").colorbox({
		width:"990px",
		height:"80%",
		iframe:true,
		transition:"none",
		onLoad:
		function(){
			$(".videoModule").hide();
			var el = document.getElementById("colorbox");
			if (el.style.filter && el.style.removeAttribute)
			{
				el.style.removeAttribute("filter");
			}
		},
		onClosed:
		function(){
			$(".videoModule").show();
		},
		onComplete:
		function(){
			removeFilter();
		}
		
	});

	var maxModuleHeight = 0;
	$('.greyBoxes .greyBox').each(function(){
		if ($(this).height() > maxModuleHeight )
			maxModuleHeight = $(this).height();
	}).css('height',maxModuleHeight);
	
	$('.picture-slides-thumbnails li a').each(function() {
		var $el = $(this);
		$el.attr('href', $el.attr('rel'));
	});

	jQuery.PictureSlides.set({
		// Switches to decide what features to use
		useFadingIn : true,
		useFadingOut : true,
		useFadeWhenNotSlideshow : true,
		useFadeForSlideshow : true,
		useDimBackgroundForSlideshow : true,
		loopSlideshow : false,
		usePreloading : true,
		useAltAsTooltip : true,
		useTextAsTooltip : false,

		// Fading settings
		fadeTime : 500, // Milliseconds
		timeForSlideInSlideshow : 2000, // Milliseconds

		// At page load
		startIndex : 1,
		startSlideShowFromBeginning : true,
		startSlideshowAtLoad : false,
		dimBackgroundAtLoad : false,

		thumbnailActivationEvent : "click",

		// Classes of HTML elements to use
		mainImageClass : "picture-slides-image", // Mandatory
		imageLinkClass : "picture-slides-image-link",
		fadeContainerClass : "picture-slides-fade-container",
		imageTextContainerClass : "picture-slides-image-text",
		previousLinkClass : "picture-slides-previous-image",
		nextLinkClass : "picture-slides-next-image",
		imageCounterClass : "picture-slides-image-counter",
		startSlideShowClass : "picture-slides-start-slideshow",
		stopSlideShowClass : "picture-slides-stop-slideshow",
		thumbnailContainerClass: "picture-slides-thumbnails",
		dimBackgroundOverlayClass : "picture-slides-dim-overlay"
	});

	
	jQuery.PictureSlides.init();

	$.fn.dCF=function(settings){
		var config={
			'index':0,
			'showTime':5000,
			'transitionTime':1000,
			'doHoverPause':true,
			'maxZIndex':100
		};

		var timeOut=null;
		var itemArray=[];
		function cancelXFade(){
			if(timeOut!==null){
				window.clearTimeout(timeOut);
				timeOut=null;
			}
		}
		function doXFade(){
			timeOut=window.setTimeout(function(){
				var currentIndex=config.index;
				var nextIndex=(config.index>=itemArray.length-1)?0:config.index+1;
				itemArray[currentIndex].css('z-index',(config.maxZIndex-1)+'');
				itemArray[nextIndex].css('z-index',config.maxZIndex+'');
				itemArray[nextIndex].fadeIn(config.transitionTime,function(){
					itemArray[currentIndex].hide();
				});
				config.index=nextIndex;
				doXFade();
			},config.showTime);
		}
		if(settings)$.extend(config,settings);
		this.each(function(){
			(itemArray.length===config.index)?$(this).show():$(this).hide();
			if(config.doHoverPause){
				$(this).hover(function(){
					cancelXFade();
				},function(){
					cancelXFade();
					doXFade();
				});
			}
			itemArray[itemArray.length]=$(this);
		});
		doXFade();
		return this;
	};

	$('.content table tr:even').addClass('evenRow');

	// make the boiler size dropdown only show when needed
	$('#boilerField').css('display','none');
	$('#boilerSize').attr('disabled', true);

	$('#enquiryType').change(function(){
		var selId = $(this).val();
		boilerSel = false;
		for(var i=0;i<globalBoilerFieldIds.length;i++)
			if(selId == globalBoilerFieldIds[i]) boilerSel = true;

		if(boilerSel){
			$('#boilerField').slideDown();
			$('#boilerSize').removeAttr("disabled");
		}else{
			$('#boilerField').slideUp();
			$('#boilerSize').attr('disabled', true);
		}

	});

	// Bind up the lightbox links
	$('.lightboxIframe').colorbox({
		width:"940px",
		height:"780px",
		scrolling:false,
		iframe:true
	});
	
});
