$(document).ready(function(){


	function showpage(id) {
		
		$("#"+id).modal({
			opacity:80, 
			overlayClose:true, 
			onOpen: function (dialog) {
				dialog.overlay.fadeIn('fast', function () {
					dialog.container.slideDown('fast', function () {
						dialog.data.fadeIn('fast', function() { Cufon.replace('h2')('h3'); });
					});
				});
			}, 
			onClose: function (dialog) {
				dialog.data.fadeOut('fast', function () {
					dialog.container.hide('fast', function () {
						dialog.overlay.fadeOut('fast', function() { 
							$.modal.close();				
						});
					});
				});
	
			}});
	};

	function imagemodal(id,title) {

		$("#largeimg span").attr("innerHTML", "<img src='"+id+"' alt='' /><p>"+title+"</p>");
		
		$("#largeimg").modal({
			opacity:80, 
			overlayClose:true, 
			onOpen: function (dialog) {
				dialog.overlay.fadeIn('fast', function () {
					dialog.container.slideDown('fast', function () {
						dialog.data.fadeIn('fast', function() { Cufon.replace('h2')('h3'); });
					});
				});
			}, 
			onClose: function (dialog) {
				dialog.data.fadeOut('fast', function () {
					dialog.container.hide('fast', function () {
						dialog.overlay.fadeOut('fast', function() { 
							$.modal.close();				
						});
					});
				});
	
			}});
	};
	
	$("#largeimg").css("display", "none");
	$( ".vergrootpic a" ).fancybox({ 'overlayOpacity' : '0.8', 'overlayColor' : '#000' });
	
	var galleries = $('.ad-gallery').adGallery({
		loader_image: 'images/loading.gif',
		effect:'fade',
		animate_first_image: true, 
		animation_speed: 300,
		slideshow: { 
			autostart: true,
			start_label: 'start',
   			stop_label: 'stop',
			stop_on_scroll: true,
			countdown_prefix: '',
			countdown_sufix: ''
		}
	});

	
	/*.each(
		function(){
		$( this ).bind (
			"click", function(){ 
				imagemodal($(this).attr("href"),$(this).attr("title"));
				return false;
			}
		);
	});*/
	
	$( "#slideshowbar .thumb" ).each(
	function( intIndex ){
	$(this).css("opacity", 0.7);
		
			$( this ).bind (
				"mouseover", function(){ 
					$(this).css("opacity", 1);
					var naam = ($(this).attr("class"));
					$("."+naam+" dl").css("display", "block");
					$("."+naam+" dl").css("cursor", "pointer");
				});
			$( this ).bind (
				"mouseout", function(){ 
					$(this).css("opacity", 0.7);
					var naam = ($(this).attr("class"));
					$("."+naam+" dl").css("display", "none");
					$("."+naam+" dl").css("cursor", "auto");
				});
			$(this).bind(
				"click", function() {
					$("#slideshowlarge").attr("src", ($(this).parent("a").attr("href")));
					return false;
				});
			
		}
	);
	
		
	function showpage2(id) {
		
		$("#videoplayer").modal({
			opacity:80, 
			overlayClose:true, 
			onOpen: function (dialog) {
				dialog.overlay.fadeIn('fast', function () {
					dialog.container.slideDown('fast', function () {
						dialog.data.fadeIn('fast', function() { 
							Cufon.replace('h2')('h3'); 
							$("html").css("overflow", "hidden");
						});
					});
				});
			}, 
			onClose: function (dialog) {
				dialog.data.fadeOut('fast', function () {
					dialog.container.hide('fast', function () {
						dialog.overlay.fadeOut('fast', function() { 
							$("html").css("overflow", "scroll");
							$.modal.close();
						});
					});
				});
	
			}});
		};
	
	$('#tab_<? echo $othersite; ?>').mouseover(function() {
	  $('#tab_<? echo $thissite; ?>').addClass('inactive');
	});
	
	$('#tab_<? echo $othersite; ?>').mouseout(function() {
	  $('#tab_<? echo $thissite; ?>').removeClass('inactive');
	});

	$('.infoform').mouseup(function() {
	  showpage("infoformulier");
	});

	$('.video').mouseup(function() {
	  showpage2("video");
	});

	$('#annuleren').click(function() {
	  $.modal.close();
	});
	
	$(".sluiten").live ("click", function(){ 
	  $("html").css("overflow", "scroll");
	  $("#videoplayer").attr("innerHTML");
	  $.modal.close();
	});
	
	
	$('#belmij_submit').click(function() {
		$.ajax({
			url: 'mail_belmij.php?belmij_naam='+$('#belmij_naam').val()+'&belmij_nr='+$('#belmij_nr').val(),
			type: 'get',
			dataType: 'html',
			async: false,
			success: function(data) {
				alert(data);
			} 
		 });
	});

	$('#belmij_submit_en').click(function() {
		$.ajax({
			url: 'mail_belmij.php?belmij_naam='+$('#belmij_naam').val()+'&belmij_nr='+$('#belmij_nr').val()+'&taal=engels',
			type: 'get',
			dataType: 'html',
			async: false,
			success: function(data) {
				alert(data);
			} 
		 });
	});

	$('#nieuwsbrief_submit').click(function() {
		$.ajax({
			url: 'nieuwsbrief.php?adres='+$('#nieuwsbrief_adres').val()+'&type='+$('#nieuwsbrief_type').val(),
			type: 'get',
			dataType: 'html',
			async: false,
			success: function(data) {
				alert(data);
			} 
		 });
	});

	$('#nieuwsbrief_submit_en').click(function() {
		$.ajax({
			url: 'nieuwsbrief.php?adres='+$('#nieuwsbrief_adres').val()+'&type='+$('#nieuwsbrief_type').val()+'&taal=engels',
			type: 'get',
			dataType: 'html',
			async: false,
			success: function(data) {
				alert(data);
			} 
		 });
	});

	$("#verzenden").live ("click", function(){ 
		$("#infoformulier label").css("color", $(".infoformuliermessage").css("color"));
		if ($("#contactpersoon").val() == "") { $("label[for='contactpersoon']").css("color", "#c90000"); var fout = true; }
		if ($("#emailadres").val() == "") { $("label[for='emailadres']").css("color", "#c90000"); var fout = true; }
		if ($("#opmerkingen").val() == "") { $("label[for='opmerkingen']").css("color", "#c90000"); var fout = true; }
		if (fout == true) { $(".infoformuliermessage").attr("innerHTML", "Niet alle verplichte velden zijn ingevuld. Controleert u dit alstublieft."); return false; }
		else { 

			if ($("#nieuwsbriefcb:checkbox:checked").val() == "ja") { nieuwsbriefje = "ja"; }
			else { nieuwsbriefje = "nee"; }
			
			$.ajax({
				url: 'verstuur_infoform.php?bedrijfsnaam='+$("#bedrijfsnaam").val()+'&contactpersoon='+$("#contactpersoon").val()+'&functie='+$("#functie").val()+'&adres='+$("#adres").val()+'&postcode='+$("#postcode").val()+'&plaats='+$("#plaats").val()+'&land='+$("#land").val()+'&telefoon='+$("#telefoon").val()+'&fax='+$("#fax").val()+'&emailadres='+$("#emailadres").val()+'&internetadres='+$("#internetadres").val()+'&referentie='+$("#referentie").val()+'&nieuwsbrief='+nieuwsbriefje+'&opmerkingen='+$("#opmerkingen").val()+'&taal=nederlandstalige&site='+$("#formsite").val(),
				type: 'get',
				dataType: 'html',
				async: false,
				success: function(data) {
					if (data == "verzonden") {
						$(".infoformuliermessage").attr("innerHTML", "Uw informatieaanvraag is verzonden. <br />Wij nemen deze zo spoedig mogelijk in behandeling."); 
						$("#infoformulier form *").css("display", "none");
					}
					else {}
				} 
			 });
		}
	});

	$("#verzenden_en").live ("click", function(){ 
		$("#infoformulier label").css("color", $(".infoformuliermessage").css("color"));
		if ($("#contactpersoon").val() == "") { $("label[for='contactpersoon']").css("color", "#c90000"); var fout = true; }
		if ($("#emailadres").val() == "") { $("label[for='emailadres']").css("color", "#c90000"); var fout = true; }
		if ($("#opmerkingen").val() == "") { $("label[for='opmerkingen']").css("color", "#c90000"); var fout = true; }
		if (fout == true) { $(".infoformuliermessage").attr("innerHTML", "Some of the required fields are empty. Please check this."); return false; }
		else { 

			if ($("#nieuwsbriefcb:checkbox:checked").val() == "ja") { nieuwsbriefje = "ja"; }
			else { nieuwsbriefje = "nee"; }
			
			$.ajax({
				url: 'verstuur_infoform.php?bedrijfsnaam='+$("#bedrijfsnaam").val()+'&contactpersoon='+$("#contactpersoon").val()+'&functie='+$("#functie").val()+'&adres='+$("#adres").val()+'&postcode='+$("#postcode").val()+'&plaats='+$("#plaats").val()+'&land='+$("#land").val()+'&telefoon='+$("#telefoon").val()+'&fax='+$("#fax").val()+'&emailadres='+$("#emailadres").val()+'&internetadres='+$("#internetadres").val()+'&referentie='+$("#referentie").val()+'&nieuwsbrief='+nieuwsbriefje+'&opmerkingen='+$("#opmerkingen").val()+'&taal=engelstalige&site='+$("#formsite").val(),
				type: 'get',
				dataType: 'html',
				async: false,
				success: function(data) {
					if (data == "verzonden") {
						$(".infoformuliermessage").attr("innerHTML", "Your information request has been sent. <br />We will take care of with your request as soon as possible."); 
						$("#infoformulier form *").css("display", "none");
					}
					else {}
				} 
			 });
		}
	});

	$( "#impressieblokken div" ).each(
		function( intIndex ){
			$( this ).bind (
				"mouseover", function(){ 
					var naam = ($(this).attr("class"));
					$("."+naam+" dl").css("display", "block");
					$("."+naam+" dl").css("cursor", "pointer");
				});
			$( this ).bind (
				"mouseout", function(){ 
					var naam = ($(this).attr("class"));
					$("."+naam+" dl").css("display", "none");
					$("."+naam+" dl").css("cursor", "auto");
				});
		}
	);
	
	function getOffset( el ) {
		var _x = 0;
		var _y = 0;
		while( el && !isNaN( el.offsetLeft ) && !isNaN( el.offsetTop ) ) {
			_x += el.offsetLeft - el.scrollLeft;
			_y += el.offsetTop - el.scrollTop;
			el = el.parentNode;
		}
		return { top: _y, left: _x };
	}
	
	var anchid = $(".anch:last").attr("id"); 
	if (anchid == null) { $("#anchorfill").css("height", "20px"); }
	else { 
		var x = getOffset( document.getElementById(anchid) ).left;
		var extraheight = $(document).height()-100-x;
		$("#anchorfill").css("height", extraheight+"px");
	}

	if ($("#hi1").length) { 
	
	var teller = $('#header').find('img.headerimg').length;

	$(".headerimg").css("display", "block");

		setInterval(changeImg, 5000);
		
		function changeImg() { 
			if (teller != 1) { $("#hi"+(teller)).animate({"opacity": "0"}, 2000); teller--;}
			else { 
				teller = $('#header').find('img.headerimg').length; 
				$("#hi"+(teller)).animate({"opacity": "1"}, 2000, function() {
					$(".headerimg").animate({"opacity": "1"},0);
				});
				
			}
		}
	
	}

$( "a" ).each(
	function(){
	$( this ).bind (
		"click", function(){ 
		if ($(this).attr("href").substr(0,4) == "http") {
			$(this).attr("target", "_blank");
		}
	});
});

if ($.browser.mozilla) {
	$("#webcamload").css("display", "none");
	$("#webcamhomeinner").attr("src", "http://srv03.sittyweb.nl/~sitecam202/modules/CamCard/session_image.php?cid=MjQy");
 }

function getvid(url) {
	
		$.ajax({
		url: 'video.php?url='+url,
		type: 'get',
		dataType: 'html',
		async: false,
		success: function(data) {
			$("#videoplayer").attr("innerHTML", data);
			showpage2("video");
		} 
	});

	//showpage2("video");
}

$( ".videoblokje" ).click(function(){ 
	if ($(this).children('p').children('a').attr('href').substr(0,4) != "http") {
		getvid($(this).children('p').children('a').attr('href'));
	}
	else {  
		window.open($(this).children('p').children('a').attr('href'));
        return false; 
	}
});


});