/*SHADOWBOX
=====================================*/
Shadowbox.init({
	language: "nl",
	overlayColor: "#000",
	handleOversize: "none",
	displayNav: "false",
	viewportPadding: "0"
});

/*DATEPICKER
=====================================*/
$(function(){
	$('.date-pick').datePicker();
});

/*CUFON
=====================================*/
Cufon.replace('div#usp, ul#menu, body#home div.tekst p, a.call-to-action, div.right a, div.themas a, div.artikelen h3', {hover: true});
Cufon.replace('ul.stars, body#pagina h1, body#popup h1, h2, h3, .bulletsubtitlestyle, .hoofdMenu li a, div#usp, div.tagcloud, ul#menu, body#home div.tekst p, div.themas, a.call-to-action, div.right a, div.maandNaam, div.triggerHead', { fontFamily: 'Boton BQ' });

/*SLIDESHOW
=====================================*/
$(document).ready(function() {
	$('#slideshow').cycle({
		fx: 'fade',
		timeout: 8000
	});
});

/*HOOFDMENU
=====================================*/
$(function(){
  $("ul.hoofdMenu li:first").addClass('hMenu1');
  $("ul.hoofdMenu li:last").addClass('hMenu3');
});

/*FOOTERMENU
=====================================*/
$(function(){
  $("div#footermenu div ul li:first").addClass('first');
});

/*ALBUM
=====================================*/
$(function() {
		$("div.scrollable").scrollable();
	});

	$(function() {
		$(".items img").click(function() {
			var url = $(this).attr("src").replace("_small", "");
			var wrap = $("#image_wrap");   //.fadeTo("medium", 0.5)
			var img = new Image();
			img.onload = function() {
				wrap.fadeTo("fast", 1);
				wrap.find("img").attr("src", url);
			};
			img.src = url;
		}).filter(":first").click();
	});

/*BROWSERSTYLE
=====================================*/
function dynamicStyle() {
	var screenW = (document.body) ? document.body.clientWidth : innerWidth
	var theStyle = (screenW > 1260) ? 'huge' : (screenW > 960) ? 'big' : 'small';
	var i, a;

	for (i = 0; a = document.getElementsByTagName('link')[i]; i++) {
		if (a.getAttribute('href').indexOf("huge") >= 0 || a.getAttribute('href').indexOf("big") >= 0 || a.getAttribute('href').indexOf("small") >= 0) {
			if (a.getAttribute('href').indexOf(theStyle) != -1) {
				a.disabled = false;
			} else {
				a.disabled = true;
			}
		}
	}
}

//window.onload = window.onresize = dynamicStyle;
if (window.addEventListener) {
	window.addEventListener("load", dynamicStyle, false);
	window.addEventListener("resize", dynamicStyle, false);
 }  else if (window.attachEvent)  {
	window.attachEvent("onload", dynamicStyle);
	window.attachEvent("onresize", dynamicStyle);
}

/* INPUT
=====================================*/
(function($) {
	$.fn.defaultValue = function() {
		return this.each(function() {

			$(this).data("originalText", $(this).val());

			$(this).blur(function() {
				if ($(this).val() == "") {
					$(this).val($(this).data("originalText"));
					$(this).removeClass("enabled");
				}
			});

			$(this).focus(function() {
				if ($(this).val() == $(this).data("originalText")) {
					$(this).val("");
					$(this).addClass("enabled");
				}
			});

		});
	}
})(jQuery);


$(document).ready(function() {
	$("#saddr, #saddr2").defaultValue();
});

/* UITKLAPPEN
=====================================*/
$(function(){
	$("div.collapse").each(function() {
		if (!$(this).next().next().hasClass("collapse")) {
			$(this).css({
				"margin-bottom": "0"
			}).find("div.block").css({
				"margin-bottom": "0"
			})
		}
	});

	$(".toggle_container").hide();
	
	$("div.trigger").click(function(){
		if ($(this).attr("active") == "true") {
			$(this).removeAttr("active");
			$(this).removeClass("active").next(".toggle_container").slideUp("slow");
		} else {
			$("div.trigger").removeClass("active").removeAttr("active");	
			$(this).attr("active", "true");
			$(".toggle_container").slideUp();
			$(this).addClass("active").next(".toggle_container").slideToggle("slow");
		}
	});
	//$("span.trigger").eq(0).click();
});

function initCarousel(carousel) {
	carousel.scroll(1);
}

/* AUTOMATISCH UITKLAPPEN
=====================================*/
$(document).ready(function() {
	$(document).find('*[active]').each(function(index){
		$(this).next(".toggle_container").slideToggle("slow");
	});
});


/* AUTOMATISCH UITKLAPPEN
=====================================*/
this.tooltip = function(){	
	/* CONFIG */		
		xOffset = 10;
		yOffset = 20;		
		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result		
	/* END CONFIG */		
	$("div.uitleg").hover(function(e){											  
		this.t = this.title;
		this.title = "";									  
		$("body").append("<p id='tooltip'>"+ this.t +"</p>");
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");		
    },
	function(){
		this.title = this.t;		
		$("#tooltip").remove();
    });	
	$("div.uitleg").mousemove(function(e){
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});			
};



// starting the script on page load
$(document).ready(function(){
	tooltip();
});

$(window).load(function(){
	var hash = window.location.hash.replace('#', '');
	if(hash == 'reserveernu') {
		Shadowbox.open({
			content : 'http://www.yankeedoodle.nl/pageid=206/structure=19/Reserveren.html',
			player : 'iframe',
			width : 540,
			height : 420
			});
	}
	if(hash == 'reserveernugroningen') {
		Shadowbox.open({
			content : 'http://www.yankeedoodle.nl/pageid=206/structure=19/vest=gr/Reserveren.html',
			player : 'iframe',
			width : 540,
			height : 420
			});
	}
});
