var animations = [
	function(){		
		$(".active .weather_anim_1").animate({
			top: -40
		},{
			duration: 2000,
			easing: "easeOutQuad"
		}).animate({
			top: -20
		}, {duration: 2000, easing: "easeInQuad"},function(){
		
		});
		
	},
	function(){
		$(".active .weather_anim_2").animate({
			top: -25
		},{
			duration: 2000,
			easing: "easeOutQuad"
		}).animate({
			top: -5
		}, {duration: 2000, easing: "easeInQuad"},function(){
		
		});
	},
	function(){
		$(".active .weather_anim_3").animate({
			top: -20
		},{
			duration: 2000,
			easing: "easeOutQuad"
		}).animate({
			top: 0
		}, {duration: 2000, easing: "easeInQuad"},function(){
		
		});
	}
];

var startbutton_id = "";
var startbutton_clicked = false;

function rand(input)
{
	return (Math.floor(Math.random()*input));
}

var current_weather = "";
var next_weather = "";

function check_weather()
{
	$.post(webroot+"/het_weer",{},function(data){
		if(data == current_weather) return;
		next_weather = data;
		
		if(current_weather == "sunny"){
			$("#bloemetjes").animate({
				bottom: -119
			},{easing: "easeInQuint", duration: 1000});
		}
		
		if(next_weather == "sunny"){
			$("#bloemetjes").stop().animate({
				bottom: -0
			},{easing: "easeOutQuint", duration: 1000});
		}
		
		$(".weather_layer.active").animate({
			top: -300
		},{easing: "easeInQuint", duration: 2600, complete:function(){
		
			$(this).removeClass("active");
		
		}});
		
		current_weather = next_weather;
		$("#"+next_weather).animate({
			top: 0
		},{easing: "easeOutQuint", duration: 2600,complete: function(){
			$(this).addClass("active");
		}});
	});
}

$("document").ready(function(){

	$("#lief").click(function(){
		window.location = "http://www.lieflifestyle.nl/";
	});
	current_weather = $('body').attr("rel");
	
	setInterval(function(){
		check_weather();
	},3000);
	
	$("#logo_jan").mouseenter(function() {
		$("#doodle").show();
	}).mouseleave(function() {
		$("#doodle").hide();
	});
	
	setTimeout(function(){
		if(startbutton_clicked == false) $(startbutton_id).click();
	},6000);

	Cufon.replace('.cufon');
	
	$(".product").products();
	
	if($("#intro_animation").length>0){
		startbutton_id = "#start_button";
		$("#koe").css({
			height: 157,
			bottom: -70
		});
	
		$("#start_button").show();
		$(".animated_wrapper").hide();
		$("#start_button").click(function(){
			startbutton_clicked = true;
			$(this).animate({
				top:-180
			},300,function(){
				$(this).remove();
			});
			$(".animated_wrapper").show();
			$("#wolk1").animate_top(-160,1500);
			$("#wolk2").animate_top(-90,1500, 500);
			$("#wolk3").animate_top(-70,1500, 1000);
			$("#ballon").animate_top(-370,4500, 1700,"easeOutQuad");
			$("#content_wrapper").animate_top(-700,1500, 850, "easeOutBounce");
			$("#stoel").animate_bottom(920,1500,0,"easeOutBounce");
			$("#stoel2").animate_bottom(920,1500,300,"easeOutBounce");
			$("#tafel").animate_bottom(904,1500, 400,"easeOutBounce");
			$("#verp_pof").animate_bottom(904,1500, 200,"easeOutBounce");
			$("#verp_nat").animate_bottom(904,1500, 400,"easeOutBounce");
			$("#koe").animate_bottom(904,1500, 400,"easeOutBounce");
			$("#verp_spek").animate_bottom(904,1500, 500,"easeOutBounce");
			$("#stapel").animate_bottom(904,1500, 900,"easeOutBounce");
			pb_height =  parseInt($("#pb_holder").height()) + 00;
			
			$("#pb_holder").animate_bottom(pb_height+1000,1500,200,"easeOutBounce");
			
			setTimeout(function(){
				$("#verp_nat, #verp_spek, #verp_pof").grasverp();
				set_random_animation();
			},2000);
			
		});
	
	}else if($("#intro_animation2").length>0){
	
		startbutton_id = "#start_button2";
	
		$("#pb_body").css("padding-bottom","100px");
		$("#start_button2").show();
		$(window).resize(function(){
			var windowHeight = $(document).height();
			$("#graphics_front, #pb_holder, #gras_front, #graphics_bottom, #gras").css("bottom",windowHeight+100);
			$("#content_wrapper, #graphics_back").css({
				"top": -((windowHeight)+100)
			});
		});
		
		var windowHeight = $(document).height();
		$("#graphics_front, #pb_holder, #gras_front, #graphics_bottom, #gras").css("bottom",windowHeight+100);
		$("#content_wrapper, #graphics_back").css({
			"top": -((windowHeight)+100)
		});
		
		$("#verp_pof,#verp_nat,#verp_spek").css({
			bottom: 0,
			"padding-bottom":0
		});
				
		$("#start_button2").click(function(){
			startbutton_clicked = true;
			
			$(window).unbind("resize");
			var windowHeight = $(window).height();

			//set_random_animation();
			$("#graphics_front, #pb_holder, #gras_front, #graphics_bottom, #gras").animate({
				bottom: 0
			},{duration:4000, easing: "easeOutElastic",complete:function(){
				$("#verp_nat, #verp_spek, #verp_pof").grasverp();
			}});
			$("#content_wrapper").animate({
				top: 0
			},{duration:4000, easing: "easeOutElastic"});
			
			setTimeout(function(){
				$("#graphics_back").animate({
					top: 0
				},{duration:4000, easing: "easeOutQuad",complete:function(){
				set_random_animation();
			}});
			},2000);
			
			$(this).animate({
				top:windowHeight+100
			},{duration:4000, easing: "easeOutElastic"},function(){
				$(this).remove();
			});
		});
	
	}else if($("#intro_animation3").length>0){
	
		var windowHeight = $(window).height();
		$("#start_touwtje").css("height",windowHeight);
		$("#pb_body").css("padding-bottom","100px");
		var windowHeight = $(document).height();
		$("#graphics_front, #pb_holder, #gras_front, #graphics_bottom, #gras").css("bottom",-(windowHeight+100));
		$("#content_wrapper").css({
			"top": ((windowHeight)+100)
		});
		
		$("#graphics_back").css({
			"top": -400
		});
		
		startbutton_id = "#start_touwtje_button";
		
		$("#start_touwtje_button").click(function(){
			startbutton_clicked = true;
			$("#graphics_front, #pb_holder, #gras_front, #graphics_bottom, #gras").animate({
				"bottom":0
			},1500,function(){
				$("#verp_nat, #verp_spek, #verp_pof").grasverp();
			});
			$("#content_wrapper").animate({
				"top": 0
			},1500);
			$("#start_touwtje, #start_touwtje_button").animate({
				top:-1*$(window).height()
			},1500);
			setTimeout(function(){
				$("#graphics_back").animate({
					"top": 0
				},{duration:2000,easing:'easeOutQuad',complete:function(){
					set_random_animation();
				}});
			},1000);
			
		});
			
	}else{
		$("#verp_nat, #verp_spek, #verp_pof").grasverp();
		set_random_animation();
	}
	popup_actions();
	
	if($("#cs_one.vragen").length>0)
	{
		form_actions();
	}

	
});

function form_actions()
{
	$("#checkbox").checkbox();
	$("#contact_formulier").submit(function(){
		check_form();
		return false;
	});
	
	$('p.send_button').click(function(){
		check_form();
	});
}

function check_form(){
	var error = false;
	var _name = $("#contact_name").val();
	var _email = $("#contact_email").val();
	var _adres = $("#contact_adres").val();
	var _postcode = $("#contact_postcode").val();
	var _woonplaats = $("#contact_woonplaats").val();
	var _telefoon = $("#contact_telefoon").val();
	var _message = $("#contact_message").val();
	
	if(_name == "" || _name == false)
	{
		$("#contact_name").addClass("error");
		error = true;
	}
	
	if(_email == "" || _email == false)
	{
		$("#contact_email").addClass("error");
		error = true;
	}
	
	var filter = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
	if (filter.test(_email) == false)
	{
		$("#contact_email").addClass("error");
		error = true;
	}
	
	if(_message == "" || _message == false)
	{
		$("#contact_message").addClass("error");
		error = true;
	}
	
	if(error)
	{
		setTimeout(function(){
			$("input.error,textarea.error").removeClass("error");
		}, 2500);
		//alert(error);
		return false;
	}
	
	$("#contact_formulier").hide();
	
	//alert("mail");
	
	var _newsletter = $("#contact_nieuwsbrief").val();
	
	$.post(webroot+"/jan/mailen/",{
		name: _name,
		email: _email,
		adres: _adres,
		postcode: _postcode,
		woonplaats: _woonplaats,
		telefoon: _telefoon,
		message: _message,
		newsletter: _newsletter
	},function(data){
		//alert(data);
	});
	
	$(".contact_succes").show();
	
}

var animation_interval = false;
var last_animation = 0;
var kill_random = false;
function set_random_animation()
{
	//return;
	$("#bloemetjes").show();
	animation_interval = setInterval(function(){
		//if(kill_random == true) return;
		//alert(2);
		var num = rand(animations.length);
		
		while(num == last_animation)
		{
			num = rand(animations.length);
		}
		last_animation = num;
		
		animations[num].call();
	},4500);
	
	setTimeout(function(){
		hook_animation();
	},2000);
	
	setInterval(function(){
		$("#koe").css("background-position","0px -167px");
		setTimeout(function(){
			$("#koe").css("background-position","0px 0px");
		},1500);
	},8500);
	
}

function popup_actions(){
	$.overlay({id:"popup_overlay"});
	$(".pop_exit, #popup_overlay").click(function(){
		$(".pop_up").animate({
			top: -800
		}, 600,function(){
			$.overlay.hide_overlay();
		}).css("cursor","pointer");
	});
}

function update_popup(image,size)
{

	//alert(image);
	$("#pop_up_image"+size).attr("src",image);
}

function show_popup(image,size)
{
	if(!size) size="";
	update_popup(image,size);
	$.overlay.show_overlay(function(){
		$("#pop_up"+size).animate({
			top: -97
		},{duration: 1500, easing:"easeOutBounce"});
	});
}


var hook_anim_bussy = false;
function hook_animation(){
	if(hook_anim_bussy == true) return;
	hook_anim_bussy = true;
	var _height = parseInt($(document).height()) - 453 + 143 - 20;
	if(_height < 0 )
	{
		hook_anim_bussy = false;
		return;
	}
	
	$("#long_rope").animate({
		height: _height
	}, 2000, function(){
		$("#rope_hook").addClass("with_pancake");
		setTimeout(function(){
			
			$("#long_rope").animate({
				height: 0
			},700, function(){
				$("#rope_hook").removeClass("with_pancake");
				hook_anim_bussy = false;
			});
			
		},500);
	});
	
	setTimeout(function(){
		hook_animation();
	},10000);
	
};










