// CHANGED
function colorboxVideo(embed) {
	if($(embed + ':contains("iframe")')){ 
		// haal de hoogte en breedte eruit als het een iframe is, want hij kan normaal niet de hoogte en breedte uit een filmpje in een iFrame halen
		var words = [];
		words = embed.split('width=');
		var width_arr = [];
		var width_arr = words[1].split(' ');
		var width = width_arr[0].split('"').join('');
		
		words = embed.split('height=');
		var height_arr = [];
		var height_arr = words[1].split(' ');
		var height = height_arr[0].split('"').join('');
		
		$.fn.colorbox({html:''+embed+'', innerWidth: width, innerHeight: height });
	}
	else 
	{
		 $.fn.colorbox({html:''+embed+''});
	}
}

$(document).ready(function() {
	
	$("li.followus").hover(
	  function () {
		  $("a.followus").css({'color': '#222222'});
	  },
	  function () {
		  $("a.followus").css({'color': '#999'});
	  }
	);	
	
	$("a#readmore").click(function() {		
		$(this).next("div.more").toggle();
		return false;	
	});
	
	$("ul.more li ul li a").mouseover(function(){
		$(this).next("div.popup").show();
	});
	$("ul.more li ul li a").mouseout(function(){
		$(this).next("div.popup").hide();
	});	
	$("ul.more li ul li div.popup").mouseover(function(){
		$(this).show();
	});	
	$("ul.more li ul li div.popup").mouseout(function(){
		$(this).hide();
	});		
	
	
	$("ul.media li.video a span img").mouseover(function() {
		var src = baseUrl+'/default/img/videoBckHover.gif';
        $(this).attr("src", src);
	});
	$("ul.media li.video a span img").mouseout(function() {
		var src = baseUrl+'/default/img/videoBck.gif';
        $(this).attr("src", src);
	});	
	
	$("div.mailing li a").click(function() {
		var link = $(this).attr('href');
		$("iframe").attr("src", link)

		var height = $(this).attr('alt');
		$("iframe").attr("height", height)
		
		$("ul.more li.mailinglijst a").css({
			'color': '#999'
		});
		
		$(this).css({
			'color': '#222222'
		});

		$("iframe").show();
		return false;	
	});
	
	$("a.tickets").mouseover(function() {
		$("div.popup").hide();
		$(this).parent().children("div.popup").show();
	});
	$("a.tickets").mouseout(function() {
		$("div.popup").hide();		
	});	
	
	$("ul.list li div.popup").mouseout(function() {
		$(this).hide();
	});	
	$("ul.list li div.popup").mouseover(function() {
		$(this).show();
	});
		
	/*
 	$("ul#news li a img").mouseover(function() {
		$("body").css({
			'overflow': 'hidden'
		});
		$("div#wrapper").css({
			'visibility': 'hidden'
		});			
	});
	*/
	
	// verander lettertype grootes voor windows, mac groottes worden gezet in css
	if ($.client.os == "Windows") {		
		$("ul#mainNav").css({
			'font-size': '28px',
			'line-height': '34px'
		});	
		$("ul#main li, ul#news li").css({
			'height': '34px'
		});	 
/*		$("div#content").css({
			'font-size': '11px',
			'line-height': '14px'
		});
		*/
	}
	if ($.client.os == "Mac") {	
		$("h1, a.side, a.back").css({
			'font-size': '26px'			
		});		
	}
	
	// verander display voor ie 7 en safari
//	if ($.browser.version > 7) {	
	if ((($.client.browser == "Explorer") & ($.browser.version > 7)) | (($.client.browser != "Safari")&($.client.browser != "Explorer"))) {		
		$("ul#news li a span").css({
			'display': 'inline-block'
		});
	}
	if ($.client.browser == "Safari") {		
		$("ul#news li a span").css({
			'background': 'url(../img/bgMediaLoading.gif) 0 10px no-repeat'
		});
	}	
	
	//$imgWidth = $("ul#bckMedia li.m1 img").width();
	//$imgHeight = $("ul#bckMedia li.m1 img").height();
	$("ul#bckMedia li").hide();
	
	// media maten opslaan in array
	$sizeArray = new Array();
	$imgWidth = new Array();	
	$imgHeight = new Array();	
	
		$('ul#bckMedia li').each(function() {
			
			var index = $("ul#bckMedia li").index(this) + 1;
			
			$sizeArray[index] = false;
			
			// aan voor local debug test
			//$("ul.media li.m"+index+" img, ul#news li a span.m"+index+" img").css({					
			//	'visibility': 'visible'
			//});				
			//$sizeArray[index] = "set";
			// aan voor local debug test
			
			// load functie, als img geladen is thumbnail laten zien
			$(this).children('img').load(function() {
				
				$("ul.media li.m"+index+" img, ul#news li a span.m"+index+" img, ul.download li span.m"+index+" img").css({					
					'visibility': 'visible'
				});				
				$sizeArray[index] = "set";				
		    });			

			// check cache functie, als img in cache staat dan thumbnail laten zien
			if ($("ul#bckMedia li.m"+index+" img")[0].complete == true) {
				$("ul.media li.m"+index+" img, ul#news li a span.m"+index+" img, ul.download li span.m"+index+" img").css({					
					'visibility': 'visible'
				});	
				$sizeArray[index] = "set";
			}

		
		});
	
		
		/*ul#bckMedia li {display:none;}*/
					
// tonen media op detail pagina's 
	$("ul.media li, ul#news li a span, ul.download li span").mouseover(function() {
		
		$imageView = true;

		var index = $("ul.media li").index(this) + 1;
		 
		$class = $(this).attr('class');	
		$index = $class.slice(1);			
		
		//var visibilityCheck = $(this).children("img").css("visibility");
	   // if (visibilityCheck == "visible"){
	   if ($sizeArray[$index] == "set" | $sizeArray[$index] == "ready") {
					       
			$("body").css({
				'overflow': 'hidden'
			});		
			$("div#wrapper").css({
				'visibility': 'hidden'
			});	
			$("ul.media li, ul#news li a span, ul.download li span").css({
				'visibility': 'hidden'
			});	
			
			$bgTop = "5px"
			if ($(this).attr('tagName') == "SPAN") {
				if ($.client.browser == "Safari") {$bgTop = "16px"}
			}
			$(this).css({
				'visibility': 'visible',
				'background':'url('+baseUrl+'/default/img/bgMedia.gif) 0 '+$bgTop+' no-repeat'
			});
		
			$("ul.media li img, ul#news li a span img, ul.download li span img").css({
				'visibility': 'hidden'
			});			
			$("ul#footer").hide();		
	
			$windowWidth = $(window).width();
			$windowHeight = $(window).height();
			$windowScroll = $(window).scrollTop();

			//alert($windowWidth+"-"+$windowHeight);
		
			$("ul#bckMedia li."+$class).css({
				'visibility': 'visible'
			});	
			$("ul#bckMedia li."+$class).show();
			
			if ($sizeArray[$index] == "set") {			
				$imgWidth[$index] = $("ul#bckMedia li.m"+$index+" img").width();
				$imgHeight[$index] = $("ul#bckMedia li.m"+$index+" img").height();
				
				//alert($imgWidth + "-" + $imgHeight);
				
				$sizeArray[$index] = "ready";
			}
			
			if (!$(this).parent().parent().hasClass("download"))
			{
				if ($windowWidth > $windowHeight) {								
					$setWidth = $windowWidth;
					$setHeight = ($windowWidth/$imgWidth[$index]) * $imgHeight[$index]	
	
	   				if ($windowHeight > $setHeight) {
						$setHeight = $windowHeight;
						$setWidth = ($windowHeight/$imgHeight[$index]) * $imgWidth[$index];						                                                            
		   				if ($windowWidth > $setWidth) {
							$setWidth = $windowWidth;
							$setHeight = ($windowWidth/$imgWidth[$index]) * $imgHeight[$index];						
						}					                                                           	                                                           
					} 					                                                           
					if ($windowWidth > $setWidth) {
						$setWidth = $windowWidth;
						$setHeight = ($windowWidth/$imgWidth[$index]) * $imgHeight[$index]						                                                             
	       				if ($windowHeight > $setHeight) {
	    					$setHeight = $windowHeight;
	       				}
					} 					
		
					
					$("ul#bckMedia li."+$class+" img").css({		
						'width': $setWidth+'px',
						'height': $setHeight+'px'
					});	
				
					
				} else {
					$setHeight = $windowHeight;
					$setWidth = ($windowHeight/$imgHeight[$index]) * $imgWidth[$index]
					                                                           
					if ($windowWidth > $setHeight) {
						$setWidth = $windowWidth;
						$setHeight = ($windowWidth/$imgWidth[$index]) * $imgHeight[$index]		
	      				if ($windowHeight > $setHeight) {
	    					$setHeight = $windowHeight;
	    					$setWidth = ($windowHeight/$imgHeight[$index]) * $imgWidth[$index];   					                                             
	       				}					                                                           
					} 
					if ($windowHeight > $setWidth) {
						$setHeight = $windowHeight;
						$setWidth = ($windowHeight/$imgHeight[$index]) * $imgWidth[$index]		
	   	   				if ($windowWidth > $setWidth) {
							$setWidth = $windowWidth;
							$setHeight = ($windowWidth/$imgWidth[$index]) * $imgHeight[$index];						
						}						                                                           
					} 				
	
					$("ul#bckMedia li."+$class+" img").css({
						'height': $setHeight+'px',
						'width': $setWidth+'px'
					});	
				}
			}
			else 
			{
				if ($imgHeight[$index] > $windowHeight)
				{
					// afbeelding = portrait
					$width = $imgWidth[$index] * ($windowHeight / $imgHeight[$index]);
					$("ul#bckMedia li."+$class+" img").css({		
						'width': $width+'px',
						'height': $windowHeight+'px'
					});	
					
				}
			}
			
			$("ul#bckMedia").css({
				//'top': $windowScroll+'px'
			});	

	    }
		
	});

	$("ul.media li, ul#news li a span, ul.download li span").mouseout(function() {
		
			var visibilityCheck = $(this).children("img").css("visibility");
			$class = $(this).attr('class');
			$index = $class.slice(1);
			
			$("body").css({
				'overflow': 'visible'
			});
			
			$video = false;
			if ($class.indexOf("video")!= -1) {
				$video = true;
			}
			//alert($sizeArray[$index]);
			
			//if (visibilityCheck == "hidden" ){
			if ($sizeArray[$index] == "ready" | $video == true) {
			
				var index = $("ul.media li").index(this) + 1;
				if ($sizeArray[$index] == "ready" | $video == true) {			
					$("div#wrapper").css({
						'visibility': 'visible'
					});
		
					$('ul#bckMedia li').each(function() {
						var index = $("ul#bckMedia li").index(this) + 1;
						
						if ($sizeArray[index] != false) {	
							$("ul.media li.m"+index+", ul#news li a span.m"+index+", ul.download li span.m"+index+"").css({
								'visibility': 'visible',
								'background':'none'
							});		
							$("ul.media li.m"+index+" img, ul#news li a span.m"+index+" img, ul.download li span.m"+index+" img").css({
								'visibility': 'visible'
							});
							$("ul.media li.video").css({
								'visibility': 'visible',
								'background':'none'
							});		
							$("ul.media li.video img").css({
								'visibility': 'visible'
							});						
						} else {

							$("ul.media li.m"+index).css({
								'visibility': 'visible',
								'background':'url('+baseUrl+'/default/img/bgMediaLoading.gif) 0 5px no-repeat'
								//'background':'#C6C6C6'
							});			
							$("ul.media li.video").css({
								'visibility': 'visible',
								'background':'none'
							});		
							$("ul.media li.video img").css({
								'visibility': 'visible'
							});							
							
						}
					});
						
					//if ($video == true) {
					//	$("a#player object").hide();
					//	$f().stop();
					//}
					
					$("ul#footer").show();			
					$("ul#bckMedia li."+$class).hide();
				}
		    }
		
	});	
//		
	
// reset z-index van de li's eigenlijk vanwege ie7 z-index bug,
// maar staat voor alles aan om zelfde scripting voor alles te kunnen gebruiken 
//	if(($.browser.msie)&($.browser.version < 8)){
		$(function() {
			var zIndexNumber = 1000;
			$('ul#mainNav li').each(function() {
				$(this).css('zIndex', zIndexNumber);
				zIndexNumber -= 10;
			});
			
		});	
//	}
	
	// functie om cycle te starten
	function runCycle() {
		if($.browser.msie){
		    $('a.cycle').cycle({
		    	speed:0,
				timeout: 4000, 
				delay:  -1000,
				timeoutFn: calculateTimeout				
		    });
		} else {
		    $('a.cycle').cycle({
					fx: 'fade',
					timeout: 4000, 
					delay:  -1000,
					timeoutFn: calculateTimeout				
			});
		}
	}
	
	function calculateTimeout(numRand) {
		var numRand = Math.floor(Math.random()*5000)+2000;
		return numRand;
	}
	
	if ($setMenu == false) {
		// start sequence site zwart valt in menu naar beneden
		//$("ul#mainNav li.header a").animate({color:'#C6C6C6'}, 1500);
		$("ul#mainNav li.main a.menu, ul#mainNav li.news a.menu").animate({color:'#222222'}, 1500,
			function callback() {
	
				$("li.main a.main").css({
					'color': '#747474'
				});			
				if (($slideActive != "news")&($slideMain == false) & ($slideNews == false)) {			
					$("ul#news").slideDown();
					$slideActive = "news";
				}
			}			
		);
			
		// show eerste div cycle
		$("a.cycle div:first-child").css({display:'block'});
	} else {		
		$("ul#mainNav li.header a").css({color:'#C6C6C6'});
		$("ul#mainNav li.main a.menu").css({color:'#222222'});		
	}
	
	// variabelen om te zorgen dat slide main en news
	// niet te gelijk uitgevoerd worden
	$slideMain = false;
	$slideNews = false;
	$slideActive = "";
	$cycleActive = false;
	$mainActive = false;
	
	// slide main
	$("ul#mainNav li.main a").mouseover(function() {
		
		//alert("active:"+$slideActive+" - main:"+$slideMain+" - news:"+$slideNews+" - mainactive:"+$mainActive)

		//if (($slideActive == "news")&($slideMain == false) & ($slideNews == false) & ($mainActive == true)) {	
		//	$("ul#news").slideUp(
		//		function callback() {
		//			$slideNews = false;
		//		}						
		//	);

		//	$slideActive = "main";
		//	$mainActive = true;					
		//}
		
		//if (($slideMain == false) & ($slideNews == false)) {		
		if (($slideActive == "news") & ($slideMain == false) & ($slideNews == false)) {	
			
			$slideNews = true;
			
			$('ul#main a em').hide();
			
			$(this).parent().children("ul:first").find("a").css({
				'color': '#C6C6C6'
			});	
			$("li.main a.main").css({
				'color': '#222222'
			});	
			$("li.news a.news").css({
				'color': '#747474'
			});	
			$(this).parent().children("ul").find("ul").hide();
			
			$('a.cycle').cycle('pause');
			
			$("ul#news").slideUp(
					function callback() {
						$slideNews = false;
					}						
			);
			
			if ($setMenu == false) {			
			//if ($mainActive == false) {
				$slideMain = true;
				$("ul#main").slideDown(
					function callback() {
						$slideMain = false;
						
						if ($cycleActive == true) {
							$('a.cycle').cycle('resume');
						} else {
							runCycle();
							$cycleActive = true;
						}
					}		
				);	
			}

			$slideActive = "main";
			$mainActive = true;			

		}
	});

	// slide news
	$("ul#mainNav li.news a").mouseover(function() {
		
		//alert("active: "+$slideActive+" main: "+$mainActive+" slidenews: "+$slideNews+" slidemain: "+$slideMain)
		
		if ((($slideActive == "main")&($mainActive == true))&($slideNews == false)&($slideMain == false)) {		
			$slideMain = true;
			$slideNews = true;		
				
			$('ul#main a em').hide();
			
			$(this).parent().children("ul:first").find("a").css({
				'color': '#747474'
			});	
			$("li.news a.news").css({
				'color': '#222222'
			});	
			$("li.main a.main").css({
				'color': '#747474'
			});	
			
			$('a.cycle').cycle('pause');
			
			if ($setMenu == false) {
				$("ul#main").slideUp(
					function callback() {
						$slideMain = false;
					}					
				);	
			}
			
			$("ul#main ul").hide();
			$("ul#main li a.cycle").css({
				'color': '#C6C6C6'
			});	
			
			$("ul#news").slideDown(
				function callback() {
					$slideMain = false;
					$slideNews = false;
				}					
			);
			$slideActive = "news";	
		}
	});		
	
 	$("ul#news li").mouseover(function() {
		$("ul#news li a").css({
			'color': '#747474'//75%
		});	 
		$(this).children("a").css({
			'color': '#222222'//100%
		});	 		
 	});
	
	// variabele om te checken of
	// mouseover loop moet worden gereset
	var $loopCount;
	$loopCount = 0;
	$("ul#main li").mouseout(function() {
		$loopCount = 0;		
	});

 	$("ul#main li.n1 a div").mouseover(function() {
 		$class = $(this).parent().parent().attr('class');		
 		//alert($class);
 		if ($class == "n1") {
		
			// cycle resumen
			$('a.cycle').cycle('resume');
			$('a.cycle').css({
				'z-index': '0'
			});		
			
			$(this).parent('a.cycle').cycle('pause');	
			
			// zet em visible bij actieve a
			$(this).children("em").show();		
			
			var position = $(this).parent("a").position();
			
			// vind breedte om positie uitklap UL te bepalen																						
			$(this).parent().children("div").each(function(i){
				var displayCheck = $(this).css("display");
			    if (displayCheck == "block"){
				    $divWidth = $(this).width();
				    $displayLeft = $divWidth + 26;
			    }					   								 
			});	
			$posLeft = $displayLeft;
	
			$liWidth = 0;
			// vind breedte om breedte uitklap UL te bepalen																						
			$(this).parent().parent().children("ul").children("li").children("a").each(function(i){
				if ($(this).width() > $liWidth ) {
				    $liWidth = $(this).width() + 36;
				}					   										   
			});	
			
			// set positie uitklap UL
			$posTop = position.top;
			$(this).parent().parent().children("ul").css({
				'left': $posLeft,
				'top': $posTop,
				'width': $liWidth
			});					
			
			// zet kleur actieve LI
			$(this).parent().parent().children("a").css({
				'color': '#222222'//100%
			});			
			// zet kleur actieve uitklap UL
			$(this).parent().parent().children("ul").find("a").css({
				'color': '#222222'//100%
			});		
			$(this).parent().parent().children("ul").find("a").children("em").hide();
			
			$(this).parent().parent().siblings().children("a").css({
				'color': '#C6C6C6'//25%
			});	
			$(this).parent().parent().siblings().children("a").children("div").children("em").hide();
			
			// hide niet actieve uitklap UL's zelfde nivo 
			if(!$.browser.msie){
				$(this).parent().parent().siblings().children("ul").stop().fadeTo(0, 0);
			}				
			$(this).parent().parent().siblings().children("ul").hide();	
			// hide actieve uitklap UL's dieper nivo			
			if(!$.browser.msie){
				$(this).parent().parent().children("ul").find("ul").stop().fadeTo(0, 0);
			}				
			$(this).parent().parent().children("ul").find("ul").hide();
				 			 	
			// show eerste actieve uitklap UL
			if($.browser.msie){
				$(this).parent().parent().children("ul:first").show();
			} else {
				//$(this).parent().parent().children("ul:first").fadeIn();
				$(this).parent().parent().children("ul:first").show();
				$(this).parent().parent().children("ul:first").stop().fadeTo(500, 1);				
			}	 		
 		}
 	});
	
 	$("ul#main li").mouseover(function() {
 		$class = $(this).attr('class');		
 		if ($class != "n1") {
//		if (($slideMain == false) & ($slideNews == false)) {

			if ($loopCount == 0) {
				
				// zet em visible bij actieve a
				$(this).children("a").children("em").show();
				
				var position = $(this).children("a").position();
				
				// vind breedte om positie uitklap UL te bepalen																	
				$posLeft = $(this).children("a").width() + 10;
						
				// set positie uitklap UL
				$posTop = position.top;
				$(this).children("ul").css({
					'left': $posLeft,
					'top': $posTop - 1
				});		
	
				// zet kleur in niet actieve UL, alleen eerste nivo
				$(this).parent().parent().siblings("li").find("a").css({
					'color': '#C6C6C6'//25%
				});	
				
				// zet kleur in actieve UL
				$(this).siblings().children("a").css({
					'color': '#747474'//75%
				});	
				$(this).siblings().children("a").children("em").hide();								

				// zet kleur actieve LI
				$(this).children("a").css({
					'color': '#222222'//100%
				});	
					
				// zet kleur actieve uitklap UL
				$(this).children("ul").find("a").css({
					'color': '#222222'//100%
				});				
				$(this).children("ul").find("a").children("em").hide();	
				
				// hide niet actieve uitklap UL's zelfde nivo 
				if(!$.browser.msie){
					$(this).siblings().children("ul").stop().fadeTo(0, 0);
				}
				$(this).siblings().children("ul").hide();	
				// hide actieve uitklap UL's dieper nivo
				if(!$.browser.msie){
					$(this).children("ul").find("ul").stop().fadeTo(0, 0);
				}			
				$(this).children("ul").find("ul").hide();
	
				// show actieve uitklap UL
				if($.browser.msie){
					$(this).children("ul:first").show();
				} else {
					$(this).children("ul:first").show();
					$(this).children("ul:first").stop().fadeTo(500, 1);
				}		    	
		    	
				// check breedste li van uitklap UL				
				$displayWidth = 0;
				$(this).children("ul:first").children("li").children("a").each(function(i){
					   $aWidth = $(this).width();
					   if ($aWidth > $displayWidth){
						   $displayWidth = $aWidth;
					   }					   								 
				});			
				
				// zet deze breedte voor de bck van de uitklap UL 
				$(this).children("ul").css({
					'width': $displayWidth + 36
					//,'border': '1px solid blue'
				});	
				$(this).children("ul").children("li").css({
					'width': $displayWidth + 10,
					'background': 'transparent url(noimg;)'
					// background transparent is voor ie7 bug
					// zodat hij niet een li lager triggered
				});	
//				$(this).siblings().children("a").css({
//					'width': $displayWidth + 10,
//					'border': '1px solid blue'
//				});	
				
				$loopCount = $loopCount + 1;
			}
		}
 	 	
 				
	});

 
/* test voor zetten menu
 */  
	if ($setMenu == true) { 	
		$slideActive = "main";
		$mainActive = true;	
		
		runCycle();
		$cycleActive = true;
		
		$("ul#main").show();
		
		// onderstaande id in array en loopen		
		$idArray = new Array();
		$idArray = sessionArray.split("-");
		
		//alert($idArray[0]+"-"+$idArray[1]+"-"+$idArray[2]+"-"+$idArray[3]+"-")
		//$idArray = new Array();
		//$idArray[0] = 'n1a2';
		//$idArray[1] = 'n2a1';
		//$idArray[2] = 'n3a3';
		
		$counter = 0;
		$idPath = "";
		$.each($idArray, function() {
			$idPath += $idArray[$counter];
			//alert($idPath);
			$("li#"+$idPath+" ul:first").show();
						
			$posLeft = $("li#"+$idPath+" a").width() + 10;
			if ($counter == 0){				
				$posLeft = $("li#"+$idPath+" a div").width() + 26;
				$("li#"+$idPath+"").children('a.cycle').cycle('pause');
				$("li.n1").children('a.cycle').children('div').children('em').hide();
				$("li#"+$idPath+"").children('a.cycle').children('div').children('em').show();
			}						
		 	
			$("li#"+$idPath+" a").css({
				'color': '#222222'		
			});	
			$counter = $counter + 1;

			if ($counter == $idArray.length) {
				$color = "#747474";
			} else{
				$color = "#C6C6C6";				
			}			
		 	$("li#"+$idPath+"").siblings().children("a").css({
				'color': $color		
			});
		 	
		 	$("li#"+$idPath+"").siblings().children("a").children("em").css({
				'display': 'none'		
			});			 	
		 	$("li#"+$idPath+" ul").css({
				'left': $posLeft		
			});				
		 				
			$idPath += "-";			
		});
	 	
		$('a.cycle').css({
			'z-index': '0'
		});				 	
	
	}
	
});
