(function (b) {
	var c = b.scrollTo = function (e, d, f) {
		c.window().scrollTo(e, d, f)
	};
	c.defaults = {
		axis: "y",
		duration: 1
	};
	c.window = function () {
		return b(b.browser.safari ? "body" : "html")
	};
	b.fn.scrollTo = function (e, d, f) {
		if (typeof d == "object") {
			f = d;
			d = 0
		}
		f = b.extend({},
		c.defaults, f);
		d = d || f.speed || f.duration;
		f.queue = f.queue && f.axis.length > 1;
		if (f.queue) {
			d /= 2
		}
		f.offset = a(f.offset);
		f.over = a(f.over);
		return this.each(function () {
			var k = this,
				i = b(k),
				l = e,
				p, o = {},
				j = i.is("html,body");
			switch (typeof l) {
			case "number":
			case "string":
				if (/^([+-]=)?\d+(px)?$/.test(l)) {
					l = a(l);
					break
				}
				l = b(l, this);
			case "object":
				if (l.is || l.style) {
					p = (l = b(l)).offset()
				}
			}
			b.each(f.axis.split(""), function (h, r) {
				var q = r == "x" ? "Left" : "Top",
				u = q.toLowerCase(),
				g = "scroll" + q,
				t = k[g],
				s = r == "x" ? "Width" : "Height";
				if (p) {
					o[g] = p[u] + (j ? 0 : t - i.offset()[u]);
					if (f.margin) {
						o[g] -= parseInt(l.css("margin" + q)) || 0;
						o[g] -= parseInt(l.css("border" + q + "Width")) || 0
					}
					o[g] += f.offset[u] || 0;
					if (f.over[u]) {
						o[g] += l[s.toLowerCase()]() * f.over[u]
					}
				} else {
					o[g] = l[u]
				}
				if (/^\d+$/.test(o[g])) {
					o[g] = o[g] <= 0 ? 0 : Math.min(o[g], m(s))
				}
				if (!h && f.queue) {
					if (t != o[g]) {
						n(f.onAfterFirst)
					}
					delete o[g]
				}
			});
			n(f.onAfter);

			function n(g) {
				i.animate(o, d, "swing", g &&
				function () {
					g.call(this, e)
				})
			}
			function m(h) {
				var g = j ? b.browser.opera ? document.body : document.documentElement : k;
				return g["scroll" + h] - g["client" + h]
			}
		})
	};

	function a(d) {
		return typeof d == "object" ? d : {
			top: d,
			left: d
		}
	}
})(jQuery);
(function (a) {
	a.extend(a.fx.step, {
		backgroundPosition: function (d) {
			if (d.state === 0 && typeof d.end == "string") {
				var f = a.curCSS(d.elem, "backgroundPosition");
				f = c(f);
				d.start = [f[0], f[2]];
				var b = c(d.end);
				d.end = [b[0], b[2]];
				d.unit = [b[1], b[3]]
			}
			var e = [];
			e[0] = ((d.end[0] - d.start[0]) * d.pos) + d.start[0] + d.unit[0];
			e[1] = ((d.end[1] - d.start[1]) * d.pos) + d.start[1] + d.unit[1];
			d.elem.style.backgroundPosition = e[0] + " " + e[1];

			function c(h) {
				h = h.replace(/left|top/g, "0px");
				h = h.replace(/right|bottom/g, "100%");
				h = h.replace(/([0-9\.]+)(\s|\)|$)/g, "$1px$2");
				var g = h.match(/(-?[0-9\.]+)(px|\%|em|pt)\s(-?[0-9\.]+)(px|\%|em|pt)/);
				return [parseFloat(g[1], 10), g[2], parseFloat(g[3], 10), g[4]]
			}
		}
	})
})(jQuery);


$(document).ready(function () {
	var c = $("#scroll-venster");
	var a = $("#menuScroll1");
	var j = $("#menuScroll2");
	var i = $("#menuScroll3");
	var d = 1600;

	function g() {
		c.stop().scrollTo($("#home"), d, {
			axis: "x",
			offset: {
				left: 0,
				top: 0
			}
		});
		a.stop().animate({
			backgroundPosition: "(0px 0px)"
		},
		1000);
		j.stop().animate({
			backgroundPosition: "(0px 0px)"
		},
		d,"easeOutBack");
		i.stop().animate({
			backgroundPosition: "(0px 0px)"
		},
		d,"easeOutBack");
		return false
	}
	function f() {
		c.stop().scrollTo($("#programma"), d, {
			axis: "x",
			offset: {
				left: 0,
				top: 0
			}
		});
		a.stop().animate({
			backgroundPosition: "(-300px 0px)"
		},
		1000);
		j.stop().animate({
			backgroundPosition: "(-150px 0px)"
		},
		1400,"easeOutBack");
		i.stop().animate({
			backgroundPosition: "(-120px 0px)"
		},
		1600,"easeOutBack");
		return false
	}
	function e() {
		c.stop().scrollTo($("#sponsors"), d, {
			axis: "x",
			offset: {
				left: 0,
				top: 0
			}
		});
		a.stop().animate({
			backgroundPosition: "(-600px 0px)"
		},
		1000);
		j.stop().animate({
			backgroundPosition: "(-300px 0px)"
		},
		1400,"easeOutBack");
		i.stop().animate({
			backgroundPosition: "(-240px 0px)"
		},
		1600,"easeOutBack");
		return false
	}
	function b() {
		c.stop().scrollTo($("#doel"), d, {
			axis: "x",
			offset: {
				left: 0,
				top: 0
			}
		});
		a.stop().animate({
			backgroundPosition: "(-900px 0px)"
		},
		1000);
		j.stop().animate({
			backgroundPosition: "(-450px 0px)"
		},
		1400,"easeOutBack");
		i.stop().animate({
			backgroundPosition: "(-360px 0px)"
		},
		1600,"easeOutBack");
		return false
	}
	function historie() {
		c.stop().scrollTo($("#historie"), d, {
			axis: "x",
			offset: {
				left: 0,
				top: 0
			}
		});
		a.stop().animate({
			backgroundPosition: "(-1200px 0px)"
		},
		1000);
		j.stop().animate({
			backgroundPosition: "(-600px 0px)"
		},
		1400,"easeOutBack");
		i.stop().animate({
			backgroundPosition: "(-480px 0px)"
		},
		1600,"easeOutBack");
		return false
	}
	function gblink() {
		c.stop().scrollTo($("#gastenboek"), d, {
			axis: "x",
			offset: {
				left: 0,
				top: 0
			}
		});
		a.stop().animate({
			backgroundPosition: "(-1500px 0px)"
		},
		1000);
		j.stop().animate({
			backgroundPosition: "(-750px 0px)"
		},
		1400,"easeOutBack");
		i.stop().animate({
			backgroundPosition: "(-600px 0px)"
		},
		1600,"easeOutBack");
		return false
	}
	function contactlink() {
		c.stop().scrollTo($("#contact"), d, {
			axis: "x",
			offset: {
				left: 0,
				top: 0
			}
		});
		a.stop().animate({
			backgroundPosition: "(-1800px 0px)"
		},
		1000);
		j.stop().animate({
			backgroundPosition: "(-900px 0px)"
		},
		1400,"easeOutBack");
		i.stop().animate({
			backgroundPosition: "(-720px 0px)"
		},
		1600,"easeOutBack");
		return false
	}
	$("#menu-home").live("click", g);
	$("#menu-programma").live("click", f);
	$("#menu-sponsors").live("click", e);
	$("#menu-doel").live("click", b);
	$("#menu-historie").live("click", historie);
	$("#menu-gastenboek").live("click", gblink);
	$("#menu-contact").live("click", contactlink);
	
	$("#menu li a").hover(
		function(){
			$(this).animate({"color": "#FFFFFF"},{queue: false, duration: 250});
		},
		function(){
			if($(this).parent().attr("class")!="current"){
				$(this).animate({"color": "#A7A7A7"},{queue: false, duration: 250});
			}
		}
	);
	
	$("#menu").lavaLamp();
	
	$('.programma-deel').cycle({ 
		fx:    'fade', 
		speed:  1000,
		timeout: 5000
	 });
	
	$('#sponsors-animatie').cycle({ 
		fx:    'fade', 
		speed:  500,
		timeout: 2500
	 });
	
	$('#particuliere_sponsors').cycle({ 
		fx:    'fade', 
		speed:  300,
		timeout: 1500
	 });
	
	//smsfunctie();
	//setInterval("smsfunctie()",5000);
	
	$("#contactformulier").submit(function(){
		var errors=false;
		$("#contactformulier input[class!='input-submit'],#contactformulier textarea").each(function(i){
			if($(this).val()==$(this).attr("title")||$(this).val()==""){
				if(errors==false){
					$(this).focus();
					alert("Je hebt geen "+$(this).attr("rel")+" ingevuld!");
					errors=true;
				}
			}
		});
		
		if(errors==false){
			$.post("contact.php", { 
				naam: $("#contact-naam").val(),
				email: $("#contact-email").val(),
				onderwerp: $("#contact-onderwerp").val(),
				bericht: $("#contact-bericht").val()
				},
			   function(data){
				$("#contact-naam").val("");
				$("#contact-email").val("");
				$("#contact-onderwerp").val("");
				$("#contact-bericht").val("");
				 alert("Bedankt voor je berichtje! We zullen spoedig contact met je opnemen.");
			   }
			);
		}
		
		return false;
	});
	
	$("#gastenboekformulier").submit(function(){
		var errors=false;
		$("#gastenboekformulier input[class!='input-submit'][type!='hidden'],#gastenboekformulier textarea").each(function(i){
			if($(this).val()==$(this).attr("title")||$(this).val()==""){
				if(errors==false){
					if($(this).attr("rel")!="foto-upload"){
						$(this).focus();
						alert("Je hebt geen "+$(this).attr("rel")+" ingevuld!");
						errors=true;
					}
				}
			}
		});
		
		if(errors==false){
			if(gastenboekbetaald){
				return true;
			}else{
				if(confirm("Zou jij \u00E9\u00E9n euro missen? Waarschijnlijk niet. Voor het goede doel zal deze euro wel veel betekenen. Als je vrijblijvend eenmalig belt naar "+$("#gastenboek-steunen-info").attr("rel")+" (\u20AC1,00 per gesprek) en "+$("#gastenboek-steunen-code").html()+" intoets laat je ook meteen de hele wereld zien dat je iets doet aan het goede doel. Er komt dan namelijk bij je bericht een attentie te staan dat JIJ gedoneert hebt. Klik op OK nadat je gebeld hebt of klik op Annuleren om je bericht te plaatsen.")){
					return true;
				}else{
					return true;
				}
			}
		}else{
			return false;
		}
	});
	
	$("#opbrengst-ik_wil_steunen").colorbox({width:"400px", height:"300px", inline:true, href:"#ikwilsteunen"});
	
	$("#icoontjes img").tipsy({gravity: 'e',fade: 'true', title: 'alt'});
	
	
	
	var div = $('div.sc_menu'),
		ul = $('ul.sc_menu'),
		ulPadding = 10;
	
	var divWidth = div.width();

	div.css({overflow: 'hidden'});
	
	var lastLi = ul.find('li:last-child');
	
	div.mousemove(function(e){
		var ulWidth = lastLi[0].offsetLeft + lastLi.outerWidth() + ulPadding;	
		var left = (e.pageX - div.offset().left) * (ulWidth-divWidth) / divWidth;
		div.scrollLeft(left);
	});
	
	$(".gastenboek-menu-bericht").click(function(){
		if($("#gastenboek-bericht").attr("rel")!=$(this).attr("rel")){
			$(".item-aan").removeClass("item-aan").animate({"opacity":"0.6"},{queue:false,duration:500});
			$(this).addClass("item-aan");
			$(".gastenboek-titel").html(berichten[$(this).attr("rel")][0]);
			$(".gastenboek-bericht").html(berichten[$(this).attr("rel")][1]);
			$("#gastenboek-foto").attr("src","gastenboek/"+$(this).attr("rel")+"_groot.jpg");
			$("#gastenboek-foto").attr("alt",berichten[$(this).attr("rel")][0]);
			$("#gastenboek-bericht").attr("rel",$(this).attr("rel"));
		}
	});
	
	$(".sc_menu li").hover(
		function(){
			$(this).animate({"opacity":1},{queue:false,duration:200});
		},
		function(){
			if($(this).is(".item-aan")){
				
			}else{
				$(this).animate({"opacity":0.6},{queue:false,duration:500});
			}
		}
	);
	
	$(".input-textarea[name='bericht']").focus(function(){
		$("#gastenboek-steunen").fadeIn(300);
	});
	
	$(".input-textarea[name='bericht']").blur(function(){
		$("#gastenboek-steunen").fadeOut(300);
	});
	
	var gastenboekbetaald=false;
	$("#gastenboek-steunen-controleer").click(function(){
		$.ajax({
		  url: "controle.php",
		  cache: false,
		  success: function(html){
			if(html=="true"){
				alert("Bedankt voor je telefoontje, ook jouw steun is van belang! Wanneer je nu je bericht plaats zal een attentie erbij verschijnen dat jij ons gesteund hebt.");
				$("#gastenboek-input-bericht").focus();
				var gastenboekbetaald=true;
			}else{
				alert("Er is nog geen telefoontje ontvangen, de lijnen staan open!");
				$("#gastenboek-input-bericht").focus();
			}
		  }
		});
	});
	
	$("input[class!='input-submit'][type!=file],textarea").each(function(i){
		$(this).val($(this).attr("title"));
		$(this).addClass("input-clean");
	});
	
	$("input[class!='input-submit'][type!=file],textarea").focus(function(){
		if($(this).attr("title")==$(this).val()){
			$(this).val("");
			$(this).removeClass("input-clean");
			$(this).addClass("input-focus");
		}
	});
	
	$("input[class!='input-submit'][type!=file],textarea").blur(function(){
		if($(this).attr("title")==$(this).val()||$(this).val()==""){
			$(this).val($(this).attr("title"));
			$(this).addClass("input-clean");
			$(this).removeClass("input-focus");
		}
	});
	
	$("input[type=file]").filestyle({ 
		image: "images/submit-foto-trans.png",
		imageheight : 30,
		imagewidth : 100,
		width : 178
	});
	
	$(".foto-blok img").hover(
		function(){
			$("> div").animate({"opacity":1},{duration: 250, queue: false});
		},
		function(){
			$("> div").animate({"opacity":0},{duration: 1000, queue: false});
		}
	);
	
	$("#link-vrijdag-vvk").hover(
		function(){
			$("#info-vrijdag-vvk").slideDown(200,"easeInOutQuad");
		},
		function(){
			$("#info-vrijdag-vvk").slideUp(400,"easeInOutQuad");
		}
	);
	
	$("#link-zaterdag-vvk").hover(
		function(){
			$("#info-zaterdag-vvk").slideDown(200,"easeInOutQuad");
		},
		function(){
			$("#info-zaterdag-vvk").slideUp(400,"easeInOutQuad");
		}
	);
	
	$(".programma-artiesten li").click(function(){
		$(".programma-artiesten li").removeClass("aan");
		$(this).addClass("aan");
		if($(this).data("youtube")!=""){
			$("#programma-artiest-meer").hide();
			$("#programma-artiest-geen").hide();
			$("#programma-artiest-video").html('<iframe width="320" height="172" src="http://www.youtube.com/embed/'+$(this).data("youtube")+'?autoplay=1&hd=1" frameborder="0" allowfullscreen></iframe>').show();
		}else{
			$("#programma-artiest-meer").hide();
			$("#programma-artiest-video").hide();
			$("#programma-artiest-geen").show();
		}
	});
});

var sms=new Array();
var smsi=1;
	
function smsfunctie(){
	$("#doyousms-sms").jTypeWriter({duration:1.5,text:sms[smsi]});
	
	if(sms[(smsi+1)]){
		smsi++;
	}else{
		smsi=1;
	}
}
