$(function(){	
	/****************************************
	*	JQUERY SLIDER
	****************************************/
	var bClicked = false;
	
	$("#background").hover(
		function () {
			if(bClicked == false) {
				if($(window).width() <= 1024) {
					$("#container").animate({marginTop: 200}, {duration: 600, easing: 'easeOutBack'});
				}
				else {
					$("#container").animate({marginTop: 250}, {duration: 600, easing: 'easeOutBack'});
				}
			}
		}, 
		function () {
			if(bClicked == false) {
				if($(window).width() <= 1024) {
					$("#container").animate({marginTop: 179}, {duration: 300});
				}
				else {
					$("#container").animate({marginTop: 179}, {duration: 300});
				}
			}
		}
	);
	
	
	
	/****************************************
	*	JQUERY SHIVER
	****************************************/
	/*
	var strMultyplier 				= '+';
	var iRandomMaxMargin 			= 70;
	var iRandomAnimateDuration 		= 1000;
	var iRepeatSlideShiverTime		= 0;
	var iStartpos					= 0;
	
	$("#background").mouseenter(function() {
		if($(window).width() <= 1024) {
			if($("#container").css("marginTop").replace("px","") != "350") {
				if($("#container").is(":animated")) {
					clearInterval(wait);
				}
				else {
					slideShiver(1);
				}
			}
		}
		else {
			if($("#container").css("marginTop").replace("px","") != "575") {
				if($("#container").is(":animated")) {
					clearInterval(wait);
				}
				else {
					slideShiver(1);
				}
			}
		}
	});
	
	function slideShiver(iTimes) {
		if(strMultyplier == '+') {

			$("#container").animate({marginTop: strMultyplier + '=' + Math.floor(Math.random() * iRandomMaxMargin) }, {duration: iRandomAnimateDuration/iRandomMaxMargin});
			strMultyplier = '+';
		}		
		else {
			$("#container").animate({marginTop: strMultyplier + '=' + Math.floor(Math.random() * iRandomMaxMargin) }, {duration: iRandomAnimateDuration/iRandomMaxMargin});
			strMultyplier = '+';
		}
		
		if(iTimes>1) {
			setInterval(slideShiver(iTimes-1), iRepeatSlideShiverTime);
		}
		else {
			if($(window).width() <= 1024) {
				if($("#container").css("marginTop").replace("px","") != "350") {
					$("#container").animate({marginTop: 179}, {duration: 800, easing: 'easeOutBack'});
				}
				else {
					$("#container").animate({marginTop: 350}, {duration: 800, easing: 'easeOutBack'});
				}
			}
			else {
				if($("#container").css("marginTop").replace("px","") != "575") {
					$("#container").animate({marginTop: 179}, {duration: 800});
				}
				else {
					$("#container").animate({marginTop: 575}, {duration: 800});
				}
			}
		}
	}
	*/
	
	/****************************************
	*	scrollTo / localScroll
	****************************************/
	
	$.localScroll('.detail_tags a', 800);
	
	var detailTags = $('.detail_tags a');
	
	detailTags.click(function(){
		detailTags.removeClass("over");
		$(this).addClass("over");
	})
	
	/****************************************
	*	FURTHER FUNCTIONS
	****************************************/
	
	$("#background").click(function(e) {
		if(e.target.parentNode.className.indexOf("maarwelgeluid") == -1 && e.target.className.indexOf("maarwelgeluid") == -1){
			if($(window).width() <= 1024) {
				if(bClicked == false) {
					bClicked = true;
					$("#container").animate({marginTop: 260}, {duration: 800, easing: 'easeOutBack'});
				}
				else {
					bClicked = false;
					$("#container").animate({marginTop: 150}, {duration: 800, easing: 'easeInBack'});
				}
			}
			else {
				if(bClicked == false) {
					bClicked = true;
					$("#container").animate({marginTop: 550}, {duration: 800, easing: 'easeOutBack'});
				}
				else {
					bClicked = false;
					$("#container").animate({marginTop: 200}, {duration: 800, easing: 'easeInBack'});
				}
			}
		}
	});
	
	$(".linkinsite").click(function(e) {
		$(".lightboxoverlap").fadeIn();
		$("body").addClass("lightbox");
		$(".lightboxoverlap .geefnaaremail").attr("value",$(this).attr("href").replace("mailto:",""));
		return false;
	});
	
	$(".lightboxoverlap .verstuur").click(function(e) {
		alert();
		$(".lightboxoverlap").fadeOut();
		$("body").removeClass("lightbox");
	});
	
	$(".lightboxoverlap").click(function(e) {
		if(e.target.parentNode.className == "lightbox") {
			$(this).fadeOut();
			$("body").removeClass("lightbox");
		}
	});
	
	$("#background .geluid_aan").click(
		function() {
			$("#background .geluid_uit").css("display","block");
			$(this).css("display","none");
		}
	);
	$("#background .geluid_uit").click(
		function() {
			$("#background .geluid_aan").css("display","block");
			$(this).css("display","none");
		}
	);
	
	/****************************************
	*	ZOOMING
	****************************************/
	$('#zoom_holder_afbeelding .img_bg_holder .img').width($('#zoom_holder_afbeelding .img_bg_holder .img img').width());
	$('#zoom_holder_afbeelding .img_bg_holder .img').width($('#zoom_holder_afbeelding .img_bg_holder .img img').width());
	$('#zoom_holder_afbeelding .img_bg_holder .img img').css("width","100%");
	
	iCurrentWidth = 0;
	iNextWidth = 0;
	iMulti = 0;
	
	$('#zoom_holder_afbeelding .img_bg_holder').mousemove(function(e){		
		//$(this).animate({"left": "+=50px"}, "slow");
		var x = e.pageX - this.offsetLeft;
		var y = e.pageY - this.offsetTop;
		setTimeout(function(){ iCurrentWidth = x; }, 0);
		setTimeout(function(){ iNextWidth = x; }, 1000);
		
		$('.sub_nav').html("X: " + x + " Y: " + y + " width: " + $(this).width()/2 + " height: " + $(this).height()/2 + " | " + parseInt((iNextWidth - iCurrentWidth)/100) + "");
		
		iMulti = parseInt((iNextWidth - iCurrentWidth)/100);
		//$(this).find(".img").animate({"marginLeft": "+="+iMulti*10+"px"}, "fast");
	});

	$('#zoom_holder_afbeelding .img_bg_holder').click(function() {
		$(this).find(".img").animate({"width" :  $("#zoom_holder_afbeelding").width()}, "slow");
	});
	
	/****************************************
	*	TWITTER
	****************************************/
	
	$(".tweet").tweet({
		join_text: "auto",
		username: "incmerkbeleving",
		count: 3,
		auto_join_text_default: "", 
		auto_join_text_ed: "",
		auto_join_text_ing: "",
		auto_join_text_reply: "",
		auto_join_text_url: "",
		loading_text: "tweets laden..."
	});
	
});
