/**
 * @author maikelpl
   20111108 andrew: carrousel speed changed to 2500
   20111123 andrew: zoek js deleted and moved to zoek control
 */
$(document).ready(function(){
	
	//preload images
	$.preLoadImages('/images/vlag_nlH.png','/images/vlag_deH.png','/images/vlag_ukH.png','/images/home_link.png','/images/park_carousel_rightH.png','/images/park_carousel_leftH.png');
	
	//set #wrapperouter_top_submenuwrapper width
	setSubmenuWidth();$(window).resize(function(){setSubmenuWidth();});	
	
	//mainmenu
	moveSubmenus();
	disableMainmenuLinks();
	setSubmenusSameHeight();
	makeLastMainmenuItemWider();
	initiateSubmenuHover();
	
	//zoekbox
	initiateZoekInputHover();
	
	//ticketslink
	initiateTicketlinkHover();
	
	//buttons right and left
	setButtons();$(window).resize(function(){setButtons();});	
	animateButtonsRight();
	initiateHetweerlinkHover();
	
	if($('#header_carousel_list div').find('li').length > 1){
		if($('#header_carousel_list div').find('li').length == 2){
			var lastli = '<li>' + $('#header_carousel_list div').find('li').last().html() + '</li>';
			$('#header_carousel_list div').find('ul').append(lastli);
		}
		$('#header_carousel_list div').jCarouselLite({
			btnNext: '#carousel_right',
			btnPrev: '#carousel_left',
			auto: carrouselInterval,
			speed: carrouselSpeed
		});
	}
	else {
		$('#carousel_right').unbind('click').css('cursor','default').css('background','url(/images/park_carousel_right_1item.png)');
		$('#carousel_left').unbind('click').css('cursor','default').css('background','url(/images/park_carousel_left_1item.png)');
	}
});//end document ready

$(function(){
	$('#header_carousel_list div ul li p a').each(function(){
		if($(this).height() > 34){
			$(this).css('margin','12px 20px 0px 0px').css('line-height','38px');
		}
	});
});//end window load

/*****************
*** FUNCTIONS ****
*****************/
//initiate hetweer button hover
function initiateHetweerlinkHover(){
	$('#hetweer_button').hover(function(){
		if($(this).is(':animated')){$(this).stop(true,true);}
		$('#hetweer_button').animate({left: '-10px'},{ duration: 200, queue: false,easing: 'easeInOutBounce'});
	},function(){
		$('#hetweer_button').animate({left: '-66px'},{ duration: 300, queue: false,easing: 'easeInOutBounce'});
	});		
}

//set position of dieren
function setButtons(){
	var viewportWidth = $(window).width();
	if(viewportWidth > 1000){
		$('#kids_button_wrapper').css('right','0px');
		$('#events_button_wrapper').css('right','0px');
		if(viewportWidth > 1120){
			$('#rightbutton_bezoekook').show();
			$('#rightbutton_bezoekook_en').show();
		}
		else {
			$('#rightbutton_bezoekook').hide();
			$('#rightbutton_bezoekook_en').hide();
		}
	}
	else {
		$('#kids_button_wrapper').css('right', (viewportWidth - 1000) + 'px');
		$('#events_button_wrapper').css('right', (viewportWidth - 1000) + 'px');
		$('#rightbutton_bezoekook').hide();
		$('#rightbutton_bezoekook_en').hide();
	}	
}

//initiate ticketlink animation
function animateButtonsRight(){
	$('#rightbutton_bezoekook').delay(400).fadeIn(1500);
	$('#rightbutton_bezoekook_en').delay(400).fadeIn(1500);/*
	$('#kids_button_wrapper').delay(600).animate({width: '211px'},{ duration: 2500, queue: true,easing: 'easeInOutBounce'});
	$('#kids_button_wrapper').animate({width: '43px'},{ duration: 1000, queue: true,easing: 'easeInOutBounce'});*/
	$('#kids_button_wrapper').hover(function(){
		if($(this).is(':animated')){$(this).stop(true,true);}
		$('#kids_button_wrapper').animate({width: '211px'},{ duration: 200, queue: false,easing: 'easeInOutBounce'});
	},function(){
		$('#kids_button_wrapper').animate({width: '43px'},{ duration: 300, queue: false,easing: 'easeInOutBounce'});
	});
	/*$('#events_button_wrapper').delay(900).animate({width: '198px'},{ duration: 2500, queue: true,easing: 'easeInOutBounce'});
	$('#events_button_wrapper').animate({width: '30px'},{ duration: 1000, queue: true,easing: 'easeInOutBounce'});*/
	$('#events_button_wrapper').hover(function(){
		if($(this).is(':animated')){$(this).stop(true,true);}
		$('#events_button_wrapper').animate({width: '198px'},{ duration: 200, queue: false,easing: 'easeInOutBounce'});
	},function(){
		$('#events_button_wrapper').animate({width: '30px'},{ duration: 300, queue: false,easing: 'easeInOutBounce'});
	});	
}

//ticketslink hover's
function initiateTicketlinkHover(){
	$('#ticketslink').hover(function(){
		if($(this).is(':animated')){$(this).stop(true,true);}
		$('#ticketslink').animate({top: '40px'},{ duration: 200, queue: false,easing: 'easeInOutBounce'});
	},function(){
		$('#ticketslink').animate({top: '-67px'},{ duration: 300, queue: false,easing: 'easeInOutBounce'});
	});	
}

//initiate hover effect
function initiateSubmenuHover(){
	$('#wrapperouter_top_submenuwrapper').hide();
	$('#wrapperouter_top_submenuwrapper').css('height','251px');
	$('#mainmenu').mouseenter(function(){
		$('#wrapperouter_top_submenuwrapper').stop(true, true).slideDown();
	});
	$('#wrapperouter_top_back').mouseleave(function(){
		$('#wrapperouter_top_submenuwrapper').stop(true, true).slideUp();
	});
}

//last li in mainmenu fix (makes it wider)
function makeLastMainmenuItemWider(){
	$('#mainmenu > li').last().css('padding','0px 0px 0px 11px');
}

//set same height for all submenu's
function setSubmenusSameHeight(){
	var maxH = 0;
	$('#wrapperouter_top_submenu ul').each(function(){
		if($(this).height() > maxH){
			maxH = $(this).height();
		}
	});
	$('#wrapperouter_top_submenu ul').each(function(){
		$(this).height(maxH + 15);
	});	
}

//disable mainmenu items links (replace a -> span)
function disableMainmenuLinks(){
	$('#mainmenu > li').each(function(){
		var tn = $(this).find('a').eq(0);
		var tn_h = $(tn).html();
		$(this).prepend('<span>' + tn_h + '</span>');
		$(tn).remove();
		$('#wrapperouter_top_submenu ul').eq($(this).index()).css('width',$(this).width() + 34 + 'px');
		$('#wrapperouter_top_submenu ul').eq($(this).index()).find('li').css('width',$(this).width() + 42 + 'px');
	});	
}

//move submenus to right wrapper div
function moveSubmenus(){
	$('#mainmenu > li > ul').each(function(){
		var tul = $(this).html();
		$('#wrapperouter_top_submenu').append('<ul>' + tul + '</ul>');
		$(this).remove();
	});	
}

//set width of #wrapperouter_top_submenuwrapper
function setSubmenuWidth(){
	var viewportWidth = $(window).width();
	if(viewportWidth > 1000){
		$('#wrapperouter_top_submenuwrapper').css('width','100%');
	}
	else {
		$('#wrapperouter_top_submenuwrapper').css('width','1000px');
	}	
}

//initiate ticketlink animation
function animateTicketlink(){
	$('#ticketslink').animate({top: '0px'},{ duration: 2500, queue: true,easing: 'easeInOutBounce'});
	$('#ticketslink').animate({top: '-107px'},{ duration: 1000, queue: true,easing: 'easeInOutBounce'});
	$('#ticketslink').hover(function(){
		if($(this).is(':animated')){$(this).stop(true,true);}
		$('#ticketslink').animate({top: '0px'},{ duration: 200, queue: false,easing: 'easeInOutBounce'});
	},function(){
		$('#ticketslink').animate({top: '-107px'},{ duration: 300, queue: false,easing: 'easeInOutBounce'});
	});	
}

//preload images
(function($){var cache=[];$.preLoadImages=function(){var args_len=arguments.length;for(var i=args_len;i--;){var cacheImage=document.createElement('img');cacheImage.src=arguments[i];cache.push(cacheImage);}}})(jQuery)

