// JavaScript Document
function changelinks ()
{
  var re = /^(https?:\/\/[^\/]+).*$/;
  var currentHref = window.location.href.replace(re, '$1');
  var reLocal = new RegExp('^' + currentHref.replace(/\./, '\\.'));

  var links = document.getElementsByTagName("a");
  for (var i = 0; i < links.length; i++) // Alle links aanpassen
  {
	  
	
	var kind = links[i].firstChild;
	
	  
		var href = links[i].href;
		if (href == '' || reLocal.test(href) || !/^http/.test(href))
			  { // indien lokale link controle op inhoud voor fancybox
					
					if (/.flv/.test(href)){
							//window.alert("filmpje");
						links[i].rel = 'gallery';
						links[i].name = links[i].href;
						links[i].className = 'video_link';
						links[i].href = kind.src;
					} else if (/.jpg/.test(href) || /.JPG/.test(href) || /.jpeg/.test(href) || /.JPEG/.test(href) || /.gif/.test(href) || /.GIF/.test(href) || /.png/.test(href) || /.PNG/.test(href)){
							if (links[i].target == '_download'){
								var temp_href = href.split('upload');
								links[i].href = temp_href[0] + 'cms/modules/optional/downloads/dlindex.php?file=upload' + temp_href[1];
								links[i].removeAttribute('target');
								links[i].className = 'various3';
								
							} else {
								links[i].rel = 'gallery';
								links[i].name = 'image';
							}
					} else if (/.pdf/.test(href) || /.PDF/.test(href)){
							//window.alert("plaatje");
							if (links[i].target == '_download'){
								var temp_href = href.split('upload');
								links[i].href = temp_href[0] + 'cms/modules/optional/downloads/dlindex.php?file=upload' + temp_href[1];
								links[i].removeAttribute('target');
								links[i].className = 'various3';
								
							} else {
								links[i].className = 'commLinkPDF';
							}
					} 
				
			  } 
		
			//start_fancybox2();
			start_fancybox();
			
		
	
	
  }
  
  // fancybox starten
  $(document).ready(function() {

	var videoclip;
	var player;
	var vidid;
	var captions;
	var capShow;
	var ccbutShow;
	
	$(".video_link").hover(function(){
		vidid = $(".video_link").index(this);
		videoclip = $(".video_link").eq(vidid).attr("name");
		if ($(".video_link").eq(vidid).hasClass('captions')) {
		captions = $(".video_link").eq(vidid).attr("name")+'.srt';
		capShow = true;
		ccbutShow = { width: 20, height: 15, right: 5, bottom: 32, label: 'SUBS' };
		} else { 
		captions = 'videos/empty.srt';
		capShow = false;
		ccbutShow = null;
		}
	});
	
	$(".video_link").fancybox({
		'hideOnContentClick':false,
		'overlayOpacity' :.6,
		'zoomSpeedIn'    :400,
		'zoomSpeedOut'   :400,
		'easingIn'		 : 'easeOutBack',
		'easingOut'		 : 'easeInBack',
		
		'callbackOnShow' :function(){
			
			if (videoclip == 'image') {				
				
				$("#fancy_right, #fancy_left").css({height:$("#fancy_div").height(), bottom: '0'});
				
				} else {
			
				player = $f("fancy_content",{src: swfplayer, wmode: 'opaque'},{
							
				play:{opacity:0},
			  //key: '#$flowplayerkeycode',

				plugins: {
					
				
				captions: { 
					url: swfcaptions, 					 
					// pointer to a content plugin (see below) 
					captionTarget: 'content',
					showCaptions: capShow,
					button: ccbutShow
				}, 
				/* 
					configure a content plugin so that it  
					looks good for showing subtitles 
				*/ 
				content: { 
					url:swfcontent, 
					bottom: 25, 
					height:40, 
					backgroundColor: 'transparent', 
					backgroundGradient: 'none', 
					border: 0, 
					textDecoration: 'outline', 
					style: {  
						body: {  
							fontSize: 16,  
							fontFamily: 'Arial', 
							textAlign: 'center', 
							color: '#ffffff' 
						}  
					}  
				},
				
				controls:  {
				backgroundColor: 'transparent',
				progressColor: 'transparent',
				bufferColor: 'transparent',
				all:false,
                                //fullscreen:true,
				scrubber:true,
				volume:true,
				mute:true,
				play:true,
				height:30,
				autoHide: 'always'		

				}

				},
				clip:{
					autoPlay:true,
					autoBuffering:true,
					url:videopath+videoclip+'',
					captionUrl: videopath+captions+'', 
					onStart:function(clip){
						var wrap=jQuery(this.getParent());
						var clipwidth = clip.metaData.width;
						var clipheight= clip.metaData.height;
						var pos = $.fn.fancybox.getViewport();
						$("#fancy_outer").css({width:clipwidth+20,height:clipheight+20});
						$("#fancy_outer").css('left', ((clipwidth + 36) > pos[0] ? pos[2] : pos[2] + Math.round((pos[0] - clipwidth	- 36)	/ 2)));
						$("#fancy_outer").css('top',  ((clipheight + 50) > pos[1] ? pos[3] : pos[3] + Math.round((pos[1] - clipheight - 50)	/ 2)));
						$("#fancy_right, #fancy_left").css({height:clipheight-60, bottom: '70px'});
						
					},
					onFinish:function(){
						$('#fancy_close').trigger('click');
					}
				}
			});
			
			
				
			player.load();
			
		}
			
			$('#fancy_right, #fancy_right_ico').click(function(){
				vidid++;
				videoclip = $(".video_link").eq(vidid).attr("name");
				if ($(".video_link").eq(vidid).hasClass('captions')) {
				captions = $(".video_link").eq(vidid).attr("name")+'.srt';
				capShow = true;
				ccbutShow = { width: 20, height: 15, right: 5, bottom: 32, label: 'CC' };
				} else {
				captions = 'videos/empty.srt';
				capShow = false;
				ccbutShow = null;
				}
			});
			
			$('#fancy_left, #fancy_left_ico').click(function(){
				vidid--;
				videoclip = $(".video_link").eq(vidid).attr("name");
				if ($(".video_link").eq(vidid).hasClass('captions')) {
				captions = $(".video_link").eq(vidid).attr("name")+'.srt';
				capShow = true;
				ccbutShow = { width: 20, height: 15, right: 5, bottom: 32, label: 'SUBS' };
				} else {
				captions = 'videos/empty.srt';
				capShow = false;
				ccbutShow = null;
				}
			});
			
			
		},
		'callbackOnClose':function(){
			$("#fancy_content_api").remove();
		}
	});
	
}); 
}

window.onload = changelinks;

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function showToolTip(id) {
			divTip = document.getElementById(id);
			
			if(divTip.style.display == 'none') {
				divTip.style.display = 'block';
			}
			
}
			
function hideToolTip(id) {
				divTip = document.getElementById(id);
				
				if(divTip.style.display == 'block') {
					divTip.style.display = 'none';
				}
				
}


function eraseCookie(name) {
	createCookie(name,"",-1);
}
function changeStyle(size) {
document.getElementById('stylesheet').href = 'templates/default/css/style'+size+'.css';
eraseCookie('stylesheet_size');
createCookie('stylesheet_size', size, '3');
}

var x = readCookie('stylesheet_size');
if (x) {
	document.getElementById('stylesheet').href = 'templates/default/css/style'+x+'.css';
}

function reset_search(waarde){
	document.getElementById('zoek').value=waarde;
}

function reset_timeout(waarde){
	var t=setTimeout("reset_search('" + waarde + "')",2000);
	//var t=setTimeout("alert('I am displayed after 3 seconds!')",3000);
}

function start_fancybox(){
$(document).ready(function() {
			/*
			*   Examples - images
			*/

			$("a#example1").fancybox({
				'titleShow'     : false
			});

			$("a#example2").fancybox({
				'titleShow'     : false,
				'transitionIn'	: 'elastic',
				'transitionOut'	: 'elastic'
			});

			$("a#example3").fancybox({
			    'titleShow'     : false,
				'transitionIn'	: 'none',
				'transitionOut'	: 'none'
			});

			$("a#example4").fancybox();

			$("a#example5").fancybox({
				'titlePosition'  : 'inside'
			});

			$("a#example6").fancybox({
				'titlePosition'  : 'over'
			});

			$("a[rel=gallery]").fancybox({
				'transitionIn'		: 'none',
				'transitionOut'		: 'none',
				'titlePosition' 	: 'over',
				'titleFormat'       : function(title, currentArray, currentIndex, currentOpts) {
				    return '<span id="fancybox-title-over">Image ' +  (currentIndex + 1) + ' / ' + currentArray.length + '</span>';
				}
			});
			
			/*
			*   Examples - various
			*/
			
			$("#various1").fancybox({
				'titlePosition'		: 'inside',
				'transitionIn'		: 'none',
				'transitionOut'		: 'none'
			});
			
			$("#various2").fancybox({
				ajax : {
				    type	: "POST",
				    example	: 'myexample=test'
				}
			});
	
			$("#various3").fancybox({
			    'padding'           : 0,
				'autoScale'     	: true,
		        'transitionIn'		: 'none',
				'transitionOut'		: 'none',
				'type'				: 'iframe'
			});
			
			$(".youtube").fancybox({
			    'padding'           : 0,
				'width' 			: 662,
				'height'			: 410,
				'autoScale'     	: true,
		        'transitionIn'		: 'none',
				'transitionOut'		: 'none',
				'scrolling'			: 'no',
				'type'				: 'iframe'
			});
			
			$(".various3").fancybox({
			    'padding'           : 0,
				'autoScale'     	: true,
		        'transitionIn'		: 'none',
				'transitionOut'		: 'none',
				'type'				: 'iframe'
			});
			$(".variousajax").fancybox({
				'width' 			: 420,
				'height'			: 280,
				'autoScale'     	: true,
		        'transitionIn'		: 'none',
				'transitionOut'		: 'none',
				'type'				: 'iframe'
			});
			
			$("#various4").fancybox({
			    'padding'           : 0,
		        'autoScale'     	: false,
		        'transitionIn'		: 'none',
				'transitionOut'		: 'none'
			});
		});
}

function switchevent(nr){
 
 	//if(nr == 7){ var nr = 1; }
	var next = nr+1;
	var hide = nr;
	
	if (next == 5){
		var next = 1;
		var hide = 4;
	}
	
		document.getElementById('event_'+next).style.display = '';
		document.getElementById('event_'+hide).style.display = 'none';
		
	
	
	setTimeout('switchevent('+next+')',10000);
}
