/* CUFON
-------------------------*/
Cufon.replace('h1, h2, h4', { fontFamily: 'Avenir LT Std' });
Cufon.replace('h3', { fontFamily: 'Angelina' });

/* TOGGLE FUNCTION
-------------------------*/
$(function(){
	$('[class^=toggle-item]').hide();
	$('[class^=toggle-link]').click(function() {
		var $this = $(this);
		var x = $this.attr("className");
		$('.toggle-item-' + x).slideToggle();
		
		return false;
	});
});

/* IMAGE DROPDOWN CHANGER
-------------------------*/
$(function(){
	$("#imagedropdown").change(function() {
		changeImage();
	});

	$(document).ready(function() {
		changeImage();
	});
	
	function changeImage() {
		var src = $("#imagedropdown").val();
		if(src == 'openhuis') $(".date").show(); else $(".date").hide();
		$("#overlay").removeClass($("[class^=hyves-overlay]").attr('class'));
		$("#overlay").addClass('hyves-overlay-' + src);
	}
});

/* CLEAR ONFOCUS
-------------------------*/
$(function(){
	$(".onfocus-clear").focus(function() {
		if($(this).val() == $(this).attr("title")) {
			$(this).val("");
		}
	}).blur(function() {
		if(!$(this).val().length) {
			$(this).val($(this).attr("title"));
		}
	});
});


/* RESIZE CONTENT
-------------------------*/
$(document).ready(function() {
		resizeContent();
	});
	
	$(window).bind("resize", function() { resizeContent(); });
	
	function resizeContent() {
		$("body div#content").height($(window).height() - 100);
		$("body div#sb_l").height($(window).height() - 100);
		$("body div#sb_r").height($(window).height() - 100);
		$("div#body.page-aantekeningen div#content").height($(window).height() - 160);
		$("div#body.page-aantekeningen div#sb_l").height($(window).height() - 160);
		$("div#body.page-aantekeningen div#sb_r").height($(window).height() - 160);
		$("div#body.page-vergelijkaantekeningen div#content").height($(window).height() - 160);
		$("div#body.page-vergelijkaantekeningen div#sb_l").height($(window).height() - 160);
		$("div#body.page-vergelijkaantekeningen div#sb_r").height($(window).height() - 160);
	}

/* ALBUM
-------------------------*/
$(function() {
		$("div.scrollable").scrollable();
	});

$(function() {
	$(".items img").click(function() {
		var url = $(this).attr("src"); //.replace("_small", "");
		url = url.substring(0, url.indexOf('?')) + "?width=580&height=380&resize=3";
		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;

		if($(".scrollable img.active").next(".scrollable img").length > 0){
			$("a.nextImg").css("display", "block");
		} else {
			$("a.nextImg").css("display", "none");
		}
		if($(".scrollable img.active").prev(".scrollable img").length > 0){
			$("a.prevImg").css("display", "block");
		} else {
			$("a.prevImg").css("display", "none");
		}

	}).filter(":first").click();


	$("#image_wrap > img").click(function() {
		var urlmainimage2 = $(this).attr("src").replace("?width=580&height=380&resize=3", "?resize=4");
		window.open(urlmainimage2);
	});


	$("a.nextImg").click(function() {
		$(".scrollable img.active").next(".scrollable img").click();
		if($(".scrollable img.active").next(".scrollable img").length > 0){
			$(this).css("display", "block");
		} else {
			$(this).css("display", "none");
		}
		if($(".scrollable img.active").prev(".scrollable img").length > 0){
			$("a.prevImg").css("display", "block");
		} else {
			$("a.prevImg").css("display", "none");
		}
	});

	$("a.prevImg").click(function() {
		$(".scrollable img.active").prev(".scrollable img").click();
		if($(".scrollable img.active").prev(".scrollable img").length > 0){
			$(this).css("display", "block");
		} else {
			$(this).css("display", "none");
		}
		if($(".scrollable img.active").next(".scrollable img").length > 0){
			$("a.nextImg").css("display", "block");
		} else {
			$("a.nextImg").css("display", "none");
		}
	});
});

/* AANTEKENING
-------------------------*/
$(function() {
	$(".aantekening > textarea").each(function(){
		var cookieValue = getCookie($(this).attr("name"));
		if (cookieValue) {
			var $div = $(this).val(cookieValue).parents("div:first").slideToggle();
		}
	}).blur(function(){
		var cookieName = $(this).attr("name");
		if($(this).val().length > 0 && $(this).val() != $(this).attr("title")) {
			setCookie(cookieName, $(this).val());
		} else {
			deleteCookie(cookieName);
		}
	})
	
})	
