$(document).ready(function(){
//newsscroll 
setTimeout ("newsscroll();", 15000);
setTimeout ("rssscroll();", 15000);



//gegevens alvast invullen voor de klant
			if($.cookie("email")){
				var email = $.cookie("email");
				datemail = '';
				split = email.split("&");
				$.grep(split, function(i,n){
					core = i.split("=");
					id=core[0];
					value=core[1].replace("+", " ").replace("%40", "@");
					if(id == "date"){
						var dateemail = value;

					$("#mail_notice .hd").html("<img src='/images/icons/mail_dark_left.png' border='0' align='middle'> U heeft uw email op "+dateemail+" doorgegeven.");
					$("#mail_notice .hd").mouseover(function(){
						$(this).html("<img src='/images/icons/mail_dark_new_1.png' border='0' align='middle'> Klik om opnieuw door te geven.").mouseout(function(){
						$(this).html("<img src='/images/icons/mail_dark_left.png' border='0' align='middle'> U heeft uw email op "+dateemail+" doorgegeven.");
					});
				})
					
					}
					else{
						$("#"+id).val(value);
					}
					});


				

			}	
//gegevens alvast invullen voor de klant
			if ($.cookie("question")) {
				var cookie = $.cookie("question");
				split = cookie.split("&");
				$.grep(split, function(i,n){
					core = i.split("=");
					id=core[0];
					value=core[1].replace("+", " ").replace("%40", "@");
					$("#"+id).val(value);
					
					});
				
			}
				if(location.hash){
					hash(" ");
				}
				else{
					window.location = "#Home";
					hash(" ");
				}
	
				$("#menu li").click(function(){
					
					var page = location.hash; 
					setTimeout("hash('"+page+"')", 1);
					
				});

				$("#nieuws").click(function(){
					var page = location.hash;
					setTimeout("hash('"+page+"')", 1);
				});

				$("#menu li a img").mouseover(function(){
					var current_image = $(this).attr("src");
					state = current_image.substring(33,36);
					if(state=="off"){
						var title = $(this).attr("title");
						var highlite = "/index/navigation/state/logo_nav_off_highlite/name/"+title;	
						$(this).attr("src",highlite);
						$(this).mouseout(function(){
													var current_image_on = $(this).attr("src");
													state_on = current_image_on.substring(33,36);
													if (state_on == "off") {
														$(this).attr("src", current_image);
													}
													else{
														return false;
													}
							});
					}
					else{
						return false;
					}
				});				
			
				$("#particulier").hide();	
//div boxen intro

			
			$("#p_button").click(function(){
					$("#zakelijk li").each(function(){
						$(this).slideUp(500);
					}).parent().slideUp(500, function(){

					$("#particulier li").hide();
					$("#particulier").slideDown(500, function(){
						$("#particulier li").each(function(){
							$(this).slideDown(500);
						});
					});
							
							
					});	
					$(this).css("color","#c7ff00");	
					$("#z_button").css("color","#ffffff");			
					});

			$("#z_button").click(function(){
					$("#particulier li").each(function(){
						$(this).slideUp(500);
					}).parent().slideUp(500, function(){

					$("#zakelijk li").hide();
					$("#zakelijk").slideDown(500, function(){
						$("#zakelijk li").each(function(){
							$(this).slideDown(500);
						});
					});
							
							
					});
			$(this).css("color","#c7ff00");	
			$("#p_button").css("color","#ffffff");		
			});
			
//right_top menu
			$(".verplicht_doc").mouseover(function(){
				tempsrc = $(this).attr("src");
				split = tempsrc.split("/");
				newsrc = "/index/navigation/state/rt_on/name/"+split[6];
				$(this).attr("src", newsrc);
				var info = $(this).attr("ref");
				$("#verplichte_doc_melding").html($("#"+info).html());
				$(this).mouseout(function(){
					$(this).attr("src", tempsrc);
				$("#verplichte_doc_melding").html("");					
				});
			});

//mailblock animation
			$("#mail_notice .hd").click(function(){
				var state = $("#mail_notice .bd").attr("ref");
				if(state == "off"){
					$("#mail_notice .bd").attr("ref", "on");	
					$("#mail_notice .bd").slideDown(500, function(){
						$("#email_notice_send").show();
					});
				}
				else{
					$("#mail_notice .bd").attr("ref", "off");	
					$("#email_notice_send").hide();
					$("#mail_notice .bd").slideUp(500);
					
				}
			});
//mail send 
			$("#email_notice_send").click(function(){
				var content = $("#mail_notice_form").serializeArray();
				var action = true;
				$.grep(content, function(i,n){
					var name = i['name'];
					var value = i['value'];	
					if(value == ""){
						$("#"+name).css("background-color","#dcd29d");
					action = false;
					}
					else{
					//postcode check
						if (name == "postcode_email_notice") {
							postcode = regcatch("postcode",value);
							if(postcode){
								$("#"+name).css("color", "#ff0000");
								$("#"+name).css("background-color","#dcd29d");
							action = false;
							}
							else{
								$("#"+name).css("color", "#000000");
								$("#"+name).css("background-color","#ffffff");								
							}
						}
						else if (name == "emailadres_email_notice") {
							email = regcatch("email",value);
							if(email){
								$("#"+name).css("color", "#ff0000");
								$("#"+name).css("background-color","#dcd29d");
							action =  false;
							}
							else{
								$("#"+name).css("color", "#000000");
								$("#"+name).css("background-color","#ffffff");								
							}
						}
						else {
							$("#"+name).css("background-color", "#ffffff");
						}
					}
			});
				if(action == true){
					var formcontent =$("#mail_notice_form").serialize();

							$.ajax({
								  url: "/index/email",
								  cache: false,
								  data: formcontent,
								  success: function(html){
								  				var currentTime = new Date();
												var month = currentTime.getMonth() + 1;
												var day = currentTime.getDate();
												var year = currentTime.getFullYear();
												var date = day+"-"+month+"-"+year; 
								               	var options = { path: '/', expires: 182 };
                			    				$.cookie("email", formcontent+"&date="+date, options);
	                				//emailblock slide up and change markup
												$("#mail_notice .hd").html("<img src='/images/icons/mail_light_stuffed.png' border='0' align='middle'> Bedankt voor uw aktie.");
												$("#mail_notice .bd").attr("ref", "off");	
												$("#email_notice_send").hide();
												$("#mail_notice .bd").slideUp(500);
								  }
								});

				}


			});
			

			
//laat ons uw emailadres weten button			
			$(".button").hover(function(){
                $(".button img")
                .animate({top:"-10px"}, 200).animate({top:"-4px"}, 200) // first jump
                .animate({top:"-7px"}, 100).animate({top:"-4px"}, 100) // second jump
                .animate({top:"-6px"}, 100).animate({top:"-4px"}, 100); // the last jump
            });

//contact

	$("ul.gallery li").hover(function() { //On hover...
		
		var thumbOver = $(this).find("img").attr("src"); //Get image url and assign it to 'thumbOver'
		
		//Set a background image(thumbOver) on the &lt;a&gt; tag 
		$(this).find("a.thumb").css({'background' : 'url(' + thumbOver + ') no-repeat center bottom'});
		//Fade the image to 0 
		$(this).find("span").stop().fadeTo('normal', 0 , function() {
			$(this).hide() //Hide the image after fade
		}); 
	} , function() { //on hover out...
		//Fade the image to 1 
		$(this).find("span").stop().fadeTo('normal', 1).show();
	});

//eind contact			


//logofooters			
			$("#kifid").mouseover(function(){
				$(this).attr("src", "/images/footer/c_kifid_logo.png").mouseout(function(){
					$(this).attr("src", "/images/footer/g_kifid_logo.png");
				});
			}).click(function(){
				window.open("http://www.kifid.nl/");
			});

			$("#nva").mouseover(function(){
				$(this).attr("src", "/images/footer/c_nva.png").mouseout(function(){
					$(this).attr("src", "/images/footer/g_nva.png");
				});
			}).click(function(){
				window.open("http://www.nva.nl/");
			});


//endlogofooters
			

//rssfeeds
				$.ajax({
								  url: "/index/rssfeeds/index/0",
								  cache: false,
								  success: function(html){
									return false;
									$("#right_news_feeds_bd").html(html);
										
								  }
								});







			});
			
			function hash(lastpage){
			$(window).scrollTop(0);

			 var page = location.hash; 

			$("#toolbar").hide();
				$("#menu").find(".selected").removeClass("selected");
				$("#menu li a").each(function(){
					var title = $(this).find("img").attr("title");
					var linkon = "/index/navigation/state/logo_nav_on/name/"+title;
					var linkoff = "/index/navigation/state/logo_nav_off/name/"+title;

					if($(this).attr("href") == page){

					$(this).find("img").attr("src", linkon);
					}
					else{
					$(this).find("img").attr("src", linkoff);						
					}
				});	
					
					if(lastpage != page){
						
						loc = "/index/content/req/"+page.substring(1);
						
						$("#content").animate({
									      "height": "0", "opacity": "toggle"
									    }, "fast");
						$.ajax({
								  url: loc,
								  cache: false,
								  success: function(html){

								    $("#content").html(html);
									
								if(page == "#Nieuws"){
									$("#search_column").hide();
									}
									$("#content").animate({
									      "height": "100%", "opacity": "toggle"
									    }, "slow");
								  logsuspect(page.substring(1), "top");
								  }
								});
						
							
							
							}
					else{
						return false;
					}	
			}
		
			function content(i, naam){
				$("#toolbar_helper").val(naam);
				$("#content").animate({
									      "height": "0", "opacity": "toggle"
									    }, "slow", function(){
											$("#toolbar").hide();
										});
						$.ajax({
								  url: "/index/contentmenuitems/req/"+i,
								  cache: false,
								  success: function(html){
								    $("#content").html(html).animate({
									      "height": "100%", "opacity": "toggle"
									    }, "slow", function(){
											$("#toolbar").show();								
										});
								  logsuspect(naam, 'rightmenu');
								  }
								});
				
			
			}
			function contentrighttop(i){
				$("#content").animate({
									      "height": "0", "opacity": "toggle"
									    }, "slow", function(){
											$("#toolbar").hide();
										});
						$.ajax({
								  url: "/index/contentrighttop/req/"+i,
								  cache: false,
								  success: function(html){
								    $("#content").html(html).animate({
									      "height": "100%", "opacity": "toggle"
									    }, "slow");
								  logsuspect(i, "righttopmenu")
								  }
								});
			}

			function contentnews(i){
				$("#content").animate({
									      "height": "0", "opacity": "toggle"
									    }, "slow", function(){
											$("#toolbar").hide();
										});
						$.ajax({
								  url: "/index/contentnews/req/"+i,
								  cache: false,
								  success: function(html){
								    $("#content").html(html).animate({
									      "height": "100%", "opacity": "toggle"
									    }, "slow");
								  logsuspect(i, "news")
								  }
								});
			}


			
			function showcollega(id){
				var state = $("#"+id).attr("ref");
				
				if(state == "show"){	
					$("#"+id+" .thumb").slideUp("slow", function(){$("#"+id+" .thumbinfo").slideDown("slow", function(){
					$("#"+id).attr("ref", "hide");	
					});});
					
					}
				else{	
					$("#"+id+" .thumbinfo").slideUp("slow", function(){$("#"+id+" .thumb").slideDown("slow", function(){
					$("#"+id).attr("ref", "show");	
					});});
					}

			}

function checkvragenform(){
		var text = $("#vraag_question").html();
		var image = $("#vraag_question").next().is("img");
		var content = $("#vragenonderwerpform").serializeArray();
		var action = true;
		text2 = false;
		
		$.grep(content, function(i, n){
			var name = i['name'];
			var value = i['value'];
				check = check_input($("#"+name));
				if(!check){
					action = false;
				}
			});
			if(action && text != ""){
				if (image) {
				$("#vraag_question").next().attr('src', '/images/tick.png');	
				}else{	
				$("#vraag_question").after("<img src='/images/tick.png' border='0' style='vertical-align:middle;'/>");	
				}
				var question = $("#vraag_question").html();
				var contentform = $("#vragenonderwerpform").serialize();
			
				var options = { path: '/', expires: 182 };
							$.ajax({
								  url: "/index/question",
								  type:"POST",
								  cache: false,
								  data: "question="+question+"&"+contentform,
								  success: function(html){
          			    				$.cookie("question", contentform, options);
										$("#vragenonderwerp").dialog("close");
										$("#vraag_question").html("");
										alert_user("Emailbericht is verzonden!");
										
								  }
								});
				
				
			}
			else if(action && text == ""){
				if (image) {
				$("#vraag_question").next().attr('src', '/images/exclamation.png');	
				}else{	
				$("#vraag_question").after("<img src='/images/exclamation.png' border='0' style='vertical-align:middle;'/>");	
				}
			}
}		



$("#vragenonderwerp").dialog("close"); 

		$(function(){
				$('#vragenonderwerp').dialog({
					autoOpen: false,
					width: 600,
					modal:true,
					open:function(){
						var value = $("#toolbar_helper").val();
						$("#vraag_onderwerp").val(value);
					},
					buttons: {
						"Annuleer": function() { 
							$(this).dialog("close"); 
						}, 
						"Verstuur": function() { 
						checkvragenform();

						} 
					}
				});
		
		$("#toolbar li").mouseover(function(){
			$(this).find("span").attr("class","ui-icon ui-icon-mail-open");
			$(this).attr("class", "ui-state-hover ui-corner-all").mouseout(function(){
				$(this).attr("class", "ui-state-default ui-corner-all");
				$(this).find("span").attr("class","ui-icon ui-icon-mail-closed");
			}).click(function(){
				
				$("#vragenonderwerp").dialog("open");
			});
		});
		
		$("#vraag_question").autogrow({
		maxHeight: 300,
		minHeight: 100,
		lineHeight: 16
			});
		
		$("#vraag_aanhef").click(function(){
			$("#vraag_aanhef_helper").show()
			
		});
		
	$("#vraag_aanhef_helper li").click(function(){
		$("#vraag_aanhef").val($(this).html());
		$("#vraag_aanhef_helper").hide();
		check_input($("#vraag_aanhef"));
	})			
		
		$("#vragenonderwerpform input").blur(function(){
			check_input($(this));
		})
		

		$("#scrollforward").click(function(){
			newsscrollfw();
		});
		$("#scrollback").click(function(){
			newsscrollbw();
		});
		


	$(function(){
		$('#call_notice_send').click(function(){
			var ext = $('#call_ext').val();
			if(ext != ''){
				$('#calltext').html('Moment geduld aub '+ext+' wordt gebeld!').fadeIn('slow');
			$.ajax({
				  url: '/call/calldo/calto/'+'0'+ext+'/afdeling/carter',
				  cache:false,
				  success: function(data) {
				  	if(data == ''){
						setTimeout("$('#calltext').fadeOut('slow').html('');", 1000);	
					}
				  	else{
						$('#calltext').html(data);
						setTimeout("$('#calltext').fadeOut('slow').html('');", 2000);	
					}					
					$('#call_ext').val('');
				  }
				});	
			}
			else{
				$('#calltext').html('Geef een nummer in aub.').fadeIn('slow');
				$('#call_ext').focus();
				setTimeout("$('#calltext').fadeOut('slow').html('');", 1000);
			}
		});
	})



});	
		
function alert_user(txt){
	$("#alert_text").html(txt);
	$("#alert").fadeIn('slow', function(){
		setTimeout("$('#alert').fadeOut('slow')", 3000);
	});
}

	function newsscroll(){
		return false;
			var page = $("#right_news_count").attr("ref");
						$.ajax({
								  url: "/index/newsscroll",
								  type:"POST",
								  cache: false,
								  data: "page="+page,
								  success: function(html){
								$("#right_news_bd").html(html);
								setTimeout ("newsscroll();", 15000);
								  }
								});
		}
		
function rssscroll(){
			return false;
								var i = (parseInt($("#right_rss_count").attr("ref"))+1);
							$.ajax({
								  url: "/index/rssfeeds/index/"+i,
								  cache: false,
								  success: function(html){
									$("#right_news_feeds_bd").html(html);
									setTimeout ("rssscroll();", 15000);		
								  }
								});
								
									
	
}		
		
		
		
		
 
 	function newsscrollfw(i){
			return false;
			var page = i;
						$.ajax({
								  url: "/index/newsscroll",
								  type:"POST",
								  cache: false,
								  data: "page="+page,
								  success: function(html){
								$("#right_news_bd").html(html);
								  }
								});
		}

 	function newsscrollbw(i){
return false;
			var page = i;
							$.ajax({
								  url: "/index/newsscroll",
								  type:"POST",
								  cache: false,
								  data: "page="+(page-1),
								  success: function(html){
								$("#right_news_bd").html(html);
								  }
								});
		}

 	function logsuspect(page, position){
		$.ajax({
		   type: "POST",
		   url: "/index/logsuspect",
		   data: "page="+page+"&position="+position,
		   cache : false
		 });

	}
 
 function rssnextitems(i){
					$.ajax({
								  url: "/index/rssfeeds/index/"+i,
								  cache: false,
								  success: function(html){
									$("#right_news_feeds_bd").html(html);
										
								  }
								});
	
	
 }
 
 function maps(){
 $(function() { 
    $('#map_canvas').googleMaps({
		geocode: '34 Korte Kleverlaan Bloemendaal, 2061 EE',
        markers: {
            latitude: 52.400894,
            longitude: 4.617831

        }
    }); 
}); 

 }
 
 
