$(document).ready(function(){
	
	// remove dotted line in IE
	$('a, button').focus(function(){ this.blur();} );
	
	$("a.over").hover(function(){
		
		if (!$(this).hasClass('current')) {
			bgI = $(this).css('background-image');
			bgip = bgI.split(".png");
			bgI = bgip[0] + "_over.png\")";
			
			$(this).css('background-image', bgI);
			$(this).css('color','#ff6600');
		}
		
	},function(){
		
		if (!$(this).hasClass('current')) {
			bgI = $(this).css('background-image');
			bgip = bgI.split("_over.png");
			bgI = bgip[0] + ".png\")";
			
			$(this).css('background-image', bgI);
			$(this).css('color','#000000');
		}
		
	});
	
	$("img.over").hover(function(){
		
		srcI = $(this).attr('src');
		srcip = srcI.split(".png");
		srcI = srcip[0]+"_over.png";
		$(this).attr('src',srcI);
		
	},function(){
		
		srcI = $(this).attr('src');
		srcip = srcI.split("_over.png");
		srcI = srcip[0]+".png";
		$(this).attr('src',srcI);
		
	});
	
	$("a.subover").hover(function(){
		
		srcI = $(this).find("img").attr('src');
		srcip = srcI.split(".png");
		srcI = srcip[0]+"_over.png";
		$(this).find("img").attr('src',srcI);
		
		$(this).css('color','#fff');
		
	},function(){
		
		srcI = $(this).find("img").attr('src');
		srcip = srcI.split("_over.png");
		srcI = srcip[0]+".png";
		$(this).find("img").attr('src',srcI);
		
		$(this).css('color','#ccc');
		
	});
		
	$(window).hashchange(function(){
		
		$("#contentwrapper").slideUp(function(){
			
			loadContent();
			
			curHash = getHash();
			
			if(curHash=="#informatie"){
				loadMap(language);
			}
			
			if (curHash.toString() != "#home" && curHash.toString() != "") {
				$("#contentwrapper").slideDown();
			}
			
			updateLangLink();
			
			// remove colouring
			$('.button').each(function(){
				$(this).removeClass('current');
				bgI = $(this).css('background-image');
				bgip = bgI.split("_over.png");
				
				if (bgip[0].indexOf(".png") == -1) {
					bgI = bgip[0] + ".png\")";
				}
							
				$(this).css('background-image', bgI);
				$(this).css('color','#000000');
			});
			
			if (curHash != "#home" && curHash != "") {
				curButton = curHash + "b";
				// add colouring
				$(curButton).addClass('current');
				$(curButton).css('color', '#ff6600');
				bgI = $(curButton).css('background-image');
				bgip = bgI.split(".png");
				bgI = bgip[0] + "_over.png\")";
				$(curButton).css('background-image', bgI);
			}
					
		});
					
	});
	
	// load navigation
	$(window).hashchange();

	$.supersized({
		
			//Functionality
			slideshow               :   1,		//Slideshow on/off
			autoplay				:	1,		//Slideshow starts playing automatically
			start_slide             :   8,		//Start slide
			slideshow_interval      :   15000,	//Length between transitions
			slide_interval      	:   6000,	//Length between transitions
			transition              :   1, 		//0-None, 1-Fade, 2-Slide Top, 3-Slide Right, 4-Slide Bottom, 5-Slide Left, 6-Carousel Right, 7-Carousel Left
			transition_speed		:	1000,	//Speed of transition
			new_window				:	1,		//Image links open in new window/tab
			pause_hover             :   0,		//Pause slideshow on hover
			keyboard_nav            :   1,		//Keyboard navigation on/off
			performance				:	1,		//0-Normal, 1-Hybrid speed/quality, 2-Optimizes image quality, 3-Optimizes transition speed // (Only works for Firefox/IE, not Webkit)
	
			//Size & Position
			min_width		        :   0,		//Min width allowed (in pixels)
			min_height		        :   0,		//Min height allowed (in pixels)
			vertical_center         :   0,		//Vertically center background
			horizontal_center       :   0,		//Horizontally center background
			fit_portrait         	:   0,		//Portrait images will not exceed browser height
			fit_landscape			:   0,		//Landscape images will not exceed browser width
			
			//Components
			navigation              :   0,		//Slideshow controls on/off
			thumbnail_navigation    :   0,		//Thumbnail navigation
			slide_counter           :   0,		//Display slide numbers
			slide_captions          :   0,		//Slide caption (Pull from "title" in slides array)
			slides 					:  	[		//Slideshow Images
												{image : 'http://www.morlang.nl/img/bg/background_1.jpg'},
												{image : 'http://www.morlang.nl/img/bg/background_7.jpg'},
												{image : 'http://www.morlang.nl/img/bg/background_2.jpg'},
												{image : 'http://www.morlang.nl/img/bg/background_3.jpg'},
												{image : 'http://www.morlang.nl/img/bg/background_9.jpg'},
												{image : 'http://www.morlang.nl/img/bg/background_10.jpg'},
												{image : 'http://www.morlang.nl/img/bg/background_4.jpg'},
												{image : 'http://www.morlang.nl/img/bg/background_5.jpg'},
												{image : 'http://www.morlang.nl/img/bg/background_6.jpg'},
												{image : 'http://www.morlang.nl/img/bg/background_8.jpg'},
												{image : 'http://www.morlang.nl/img/bg/background_12.jpg'},
												{image : 'http://www.morlang.nl/img/bg/background_13.jpg'},
												{image : 'http://www.morlang.nl/img/bg/background_14.jpg'},
												{image : 'http://www.morlang.nl/img/bg/background_15.jpg'},
												{image : 'http://www.morlang.nl/img/bg/background_11.jpg'}
										]
										
		});	
		
		$.preLoadImages('http://www.morlang.nl/img/bg/background_1.jpg','http://www.morlang.nl/img/bg/background_7.jpg','http://www.morlang.nl/img/bg/background_2.jpg', 'http://www.morlang.nl/img/bg/background_3.jpg', 'http://www.morlang.nl/img/bg/background_9.jpg', 'http://www.morlang.nl/img/bg/background_10.jpg', 'http://www.morlang.nl/img/bg/background_4.jpg', 'http://www.morlang.nl/img/bg/background_5.jpg', 'http://www.morlang.nl/img/bg/background_6.jpg', 'http://www.morlang.nl/img/bg/background_8.jpg', 'http://www.morlang.nl/img/bg/background_11.jpg', 'http://www.morlang.nl/img/bg/background_12.jpg', 'http://www.morlang.nl/img/bg/background_13.jpg', 'http://www.morlang.nl/img/bg/background_14.jpg', 'http://www.morlang.nl/img/bg/background_15.jpg');
		
});

function getHash(){
	
	curHash = window.location.hash;
	
	if (curHash.length > 0) {
		curHash = "#" + curHash.substring(2);
	}
	
	return curHash;
	
}

function loadContent(){
	
	curHash = getHash();
	
	$(".content").css('display','none');
	$(curHash).css('display','block');
	
	return curHash;
	
}

function updateLangLink(){
	
	newHref = "?lang=en"+window.location.hash;
	$("#langen").attr('href',newHref);
	
	newHref = "?lang=nl"+window.location.hash;
	$("#langnl").attr('href',newHref);
	
}

(function($) {
  var cache = [];
  // Arguments are image paths relative to the current page.
  $.preLoadImages = function() {
    var args_len = arguments.length;
    for (var i = args_len; i--;) {
      var cacheImage = document.createElement('img');
      cacheImage.src = arguments[i];
      cache.push(cacheImage);
    }
  }
})(jQuery)

var mapLoaded = false;
	
function loadMap(language){
	
	if(!mapLoaded){
		
		var myLatlng = new google.maps.LatLng(52.366376,4.886397);
		var myOptions = {
			zoom: 14,
			center: new google.maps.LatLng(52.371903,4.889356),
			mapTypeId: google.maps.MapTypeId.ROADMAP
		}
		
		var map = new google.maps.Map(document.getElementById("gMap"), myOptions);
		
		if (language == "nl") {
			var contentString = "<p><b>Restaurant Morlang</b><br/>" +
			"Voor route, maak gebruik van de <a target='_blank' href='http://maps.google.com/maps?f=q&source=s_q&hl=en&geocode=&q=Restaurant+Morlang,+Keizersgracht+451,+1017+DK+Amsterdam&daddr=Restaurant+Morlang,+Keizersgracht+451,+1017+DK+Amsterdam&aq=&sll=52.366533,4.886405&sspn=0.009735,0.027874&ie=UTF8&hq=Restaurant+Morlang,&hnear=Keizersgracht+451,+Grachtengordel-West,+Amsterdam,+Noord-Holland,+Netherlands&ll=52.366376,4.886405&spn=0.009735,0.027874&t=h&z=16&iwloc=A&f=d' title='Routeplanner'>routeplanner</a>.</p>";
		}
		else if (language == "en") {
			var contentString = "<p><b>Restaurant Morlang</b><br/>" +
			"Use online <a target='_blank' href='http://maps.google.com/maps?f=q&source=s_q&hl=en&geocode=&q=Restaurant+Morlang,+Keizersgracht+451,+1017+DK+Amsterdam&daddr=Restaurant+Morlang,+Keizersgracht+451,+1017+DK+Amsterdam&aq=&sll=52.366533,4.886405&sspn=0.009735,0.027874&ie=UTF8&hq=Restaurant+Morlang,&hnear=Keizersgracht+451,+Grachtengordel-West,+Amsterdam,+Noord-Holland,+Netherlands&ll=52.366376,4.886405&spn=0.009735,0.027874&t=h&z=16&iwloc=A&f=d' title='Routeplanner'>routeplanner</a>.</p>";
		}
		
		var infowindow = new google.maps.InfoWindow({
		    content: contentString,
			maxWidth: 180
		});
		
		var marker = new google.maps.Marker({
		    position: myLatlng,
		    map: map,
		    title:"Restaurant Morlang"
		});
		
		google.maps.event.addListener(marker, 'click', function() {
		  infowindow.open(map,marker);
		});
		
		infowindow.open(map,marker);
		
		mapLoaded = true;
		
	}
			
}
