
// text sizing cookie

function readCookie(cookieName) {

	 var theCookie=""+document.cookie;
	 var ind=theCookie.indexOf(cookieName);
	 if (ind==-1 || cookieName=="") return ""; 
	 var ind1=theCookie.indexOf(';',ind);
	 if (ind1==-1) ind1=theCookie.length; 
	 var cookieReturned = unescape(theCookie.substring(ind+cookieName.length+1,ind1));
	 return cookieReturned;	
}

function setCookie(cookieName, cookieValue) {
		var today = new Date();
		var expire = new Date();
		var cookieLength = 365;
		expire.setTime(today.getTime() + 3600000*24*cookieLength); 
		document.cookie = cookieName + "="+cookieValue+";expires="+expire.toGMTString();
}




$j(document).ready(function(){
					
					
		   // selectboxes
		   
		   $j('#booking select').selectbox();
		   
		   // jcarousel
		  	
			if($j('.carousel1').length && $j('.carousel1 > ul > li').size() > 1){
			
				$j('.carousel1').jCarouselLite({
					btnNext: ".carousel1 .next",
					btnPrev: ".carousel1 .previous",
					speed: 500,
					visible: 1,
					auto:4000
				});
				
				$j('.carousel1 .next').hover(function(){
					$j(this).addClass('nexthover');
				},function(){
					$j(this).removeClass('nexthover');
				});
	
				 $j('.carousel1 .previous').hover(function(){
					$j(this).addClass('previoushover');
				},function(){
					$j(this).removeClass('previoushover');
				});

			}
			else{
					
				$j('.carousel1 a.previous,.carousel1 a.next').hide();
			
			}
			
			
			if($j('.carousel2').length && $j('.carousel2 > ul > li').size() > 1){
			
			
				  $j('.carousel2').jCarouselLite({
					btnNext: ".carousel2 .next",
					btnPrev: ".carousel2 .previous",
					speed: 700,
					visible: 1
				});
				  
				$j('.carousel2 .next').hover(function(){
				$j(this).addClass('nexthover');
				},function(){
					$j(this).removeClass('nexthover');
				});






	
				 $j('.carousel2 .previous').hover(function(){
					$j(this).addClass('previoushover');
				},function(){
					$j(this).removeClass('previoushover');
				});

			}
			else{
					
				$j('.carousel2 a.previous,.carousel2 a.next').hide();
			
			}
			 
			if($j('.carousel3').length && $j('.carousel3 > ul > li').size() > 1){
			    $j('.carousel3').jCarouselLite({
				btnNext: ".carousel3 .next",
				btnPrev: ".carousel3 .previous",
				speed: 0,
				visible: 1,
				circular:true,
				 
				beforeStart: function(a) {
					a.find('img').fadeOut('slow');
				},
				afterEnd: function(a) {
					a.find('img').fadeIn('slow');
				}

			});
				
			$j('.carousel3 li img').hide();
			$j('.carousel3 li:nth-child(2) img').show();
				
			}
			else{
					
				$j('.carousel3 a.previous,.carousel3 a.next').hide();
			
			}


		   
		 
			
			// subnav
			
					
				var navigationWidth = $j('#navigation').width();
				var li = $j('#navigation > ul > li');	
				$j('#navigation .sub > li:last-child ').addClass("last");
				var firstActive = $j('#navigation > ul > li.active');
			    var isOver;  
				var t; // settimeout
				var t2;
				var t3;
				
								
				li.each(function(i){
				
				
				
					 // initialize
					 var delay = 300;
					 var l = $j(this);
					 var u = l.find('.sub');
					 var liPos = l.position();
					 var liPosLeft = liPos.left;
					 var ulWidth = 0;
					
					
					 							 
					u.find('li').each(function(j){
					
						
						var initalLiWidth = $j(this).outerWidth(true);
						initalLiWidth = parseInt(initalLiWidth);
					    ulWidth += initalLiWidth;	
						
					 });
					 
					 u.css('width',ulWidth); 
					 var totalWidth = ulWidth + liPosLeft;
					 
				
					 
					 // position u
					  if (totalWidth > navigationWidth){
							   		 
						  var diff = (liPosLeft - ulWidth) + l.width();
				
							if (diff >= 70){ 
							  diff = diff + '' + 'px';
							  u.css({'left':diff});


							}
							else{
							  u.css({'left':'87px','width':'870px'});
							}
						 
							
					 }
					 else{
						 u.css({'left':'auto','padding-left':'7px'});
					 }
								 
					 
					 

					// hover
					l.hover(function(){
									 
						isOver = true;
	
	
						$j(this).siblings('li').removeClass("sfhover").removeClass("active");
					    $j(this).addClass("sfhover");						
	

					},function(){
						
						isOver = false;
					
						$j(this).removeClass("sfhover");		
						
						 if(isOver == false) { 
								
							 firstActive.addClass("active");								 
					
						 }
						
												
					});
				
				
				});

			
			
			
			
					
	   
		   // switchmenu
		  
		  		 if ($j('.switchmenu').length){
			  
						   
					var firstImg = $j('.switchmenu ul li:first').find('img').attr('src');
					
					$j('.switchmenu ul li:first').addClass("lihover");
					$j('.switchmenu ul li:last').addClass("last");
					var imgContainer = $j('.switchmenu .img-container');				
					
					imgContainer.html('<img title="" alt="" />');
					imgContainer.find('img').attr('src',firstImg);
					
					$j('.switchmenu ul li:first').find('a').supersleight();  	
					
				
					$j('.switchmenu ul li').hover(function(){
						
						$j(this).addClass("lihover");
						$j(this).siblings().removeClass("lihover");
						var newImg = $j(this).find('img').attr('src');
						imgContainer.find('img').attr('src',newImg);
						$j(this).find('a').supersleight();
						$j(this).siblings('li').find('a').supersleightUndo();
						
					});		
					
				  }
			   
		 
	

		   
		   jQuery.fn.miniGallery = function(){
		   
		   	   var gallery = $j(this);
		   
			   if ($j(gallery).length){
				   
				   var firstImg = $j(gallery).find('.image img').attr('src');	
				   var imageParam = firstImg.substr(firstImg.indexOf("?"));
				   				
					$j(gallery).find('ul li').hover(function(){
																		
						var image = $j(gallery).find('.image img');
						var newImg = $j(this).find('img').attr('src');
						var thumbParam = newImg.substr(newImg.indexOf("?"));
						newImg = newImg.replace(thumbParam,imageParam);

						$j(image).attr('src', newImg);

					});		
				
			   }
		   
		   }
		   
		   
		   
		   
		// fotogallerij
		if($j("#gallery ul").length){
			$j("#gallery ul").pureGallery({visible: 7,offset:10, mainX: 590,mainY:330, thumbX:70,thumbY:70});
		}
		
		// overzicht
		
		
		$j('.overzicht #page .container .small:last,.small-container .small:last').andSelf().css('margin-bottom', '0');
		$j('.overzicht #page .container .small:odd').css('margin-right', '0');
			
		$j('.small-container').each(function(){
		
			$j('.small:odd',$j(this)).css('margin-right', '0');
		
		});

		// homepage rollovers
		
		var opacityArray = new Array ('evenementen','booking','nieuws','aanraders');
		
		jQuery.each(opacityArray, function() {

									  
			var el =  $j("#" + this);					  
		
			el.hover(function(){
			
				$j(this).addClass('over');
			
			},function(){
				$j(this).removeClass('over');
			});
		
		});
		
		
		// text resize function
		 var cookieSize = readCookie('text_size');
		 		 		  
		  if(cookieSize){
			  $j('body').addClass(cookieSize);
		  }
		  
		  $j('#fontSize a').click(function() {
				var textSize = $j(this).attr('class');
				var textSizeArray = textSize.split(' ');
				$j('body').removeClass('small medium big');
				$j('body').addClass(textSize);
			
				setCookie('text_size',textSize);
			
				return false;
			});
		
	
					  
});
