$(function(){
	if ($("#intro").length == 1) {
		setTimeout(function(){
			$("body").fadeOut();
			document.location = './';
		},5000);
	}
	if ($("#slideshow").length == 1) {
		var addition = '';
		var currentheader = 1;
		var totalheaders = 3;
		var fadetime = 2000;
		var rotatetime = 6000;
		showcontrols = false;
		if ($("#slideshow").hasClass('maatwerk') == true) {
			addition = 'b';
			totalheaders = 2;		
		}
		if ($("#slideshow").hasClass('impressie') == true) {
			addition = 'c';
			totalheaders = 6;
			showcontrols = true;	
		}
		if (showcontrols == true) {
			$("#slideshow").append('<ul id="slideshowcontrols"></ul>');
			for(i=1;i<=totalheaders;i++) {
				$("#slideshowcontrols").append('<li id="slideshowcontrol'+i+'"></li>');
			}
			$("#slideshowcontrols li:first").addClass('active');
			$("#slideshowcontrols li").click(function(){
				var setactivecurrentheader = ($(this).attr("id").substr(16))-1;
				clearTimeout(executeslideshow);
				rotateheader(setactivecurrentheader, totalheaders, fadetime, rotatetime, true);
			});
		}
		function rotateheader(currentheader, totalheaders, fadetime, rotatetime, reset) {
			if (reset == true) {
				activerotatetime = 0;
			}
			else {
				activerotatetime = rotatetime;
			}
			executeslideshow = setTimeout(function(){
				$("#slideshow div").animate({
					opacity: 0
				}, fadetime, function() {
					$(this).css("background-image", "url(design/slideshow/"+currentheader+addition+".jpg)");
				}).animate({
					opacity: 1
				}, fadetime);
				currentheader++;
				setTimeout(function(){
					$("#slideshowcontrols li").removeClass('active');				
					$("#slideshowcontrol"+currentheader).addClass('active');								
				},2200);
				if (currentheader == totalheaders+1) {
					currentheader = 1;
				}
			rotateheader(currentheader, totalheaders, fadetime, rotatetime, false);
			}, activerotatetime);
		}
		
		rotateheader(currentheader, totalheaders, fadetime, rotatetime, false);
	}
	
	var gmap = false;
	onunload = function() {
		if (gmap)
		{
			location = self.location.href;
			window.open("http://maps.google.co.uk/maps?f=q&hl=en&geocode=&q=W1F+7TA&ie=UTF8&s=AARTsJowriHHOt7le7PzJka7tTgSleZODQ&view=map","googwin");
		}
	}
	
	$(".googlemaps").hover(function(){
		gmap = true;
	}, function(){
		gmap = false;
	});
});
