willow.ready(function($) {
	// Menu data 
	willow.getMenu("115257|115258|115259|115260|115261",function(data){
		$('#L1').menu(data.menu,{showL3s:false,direction:'right'});
	});
	
	// Emergency Bulletin 
	willow.getNews("11131",function(data){$('#Form1').bulletin(data,{emButton: false});},{"backlink":window.location});
	
	$(".newsDesc").fsplit(50);
	
	var $thumbs = $('#videoThumbs .thumbPlay');
	
	if($.browser.msie){
		$('#videoThumbs li').hover(
			function(){
				$(this).children(".thumbPlay").addClass("hover");
			},
			function(){
				$(this).children(".thumbPlay").removeClass("hover");
			}
		);
	}
	
	if($thumbs.length > 6){ // If more then 6 videos add slide functionality
		$('#videoThumbs').jcarousel({scroll: 1, animation: 1000, wrap: 'circular'});
	}
	willow.curVideo($thumbs, $thumbs.eq(0).attr("vid")); // Add on class to current video
	$thumbs.click(function(){ // On clicking a thumb update the video
		var vID = $(this).attr("vid");
		$(".wh-video-custom").html(""); // clear curent video
		$("#vidTmpl").tmpl({id: vID}).appendTo(".wh-video-custom").wrap(function(){
			brightcove.createExperiences(); // Add clicked video and execute function to load it up
		});
		willow.curVideo($thumbs,vID);
	});
	
	brightcove.createExperiences();
});

// Function to loop through thumbs and add the 'on' class to the video that is showing
willow.curVideo = function($allTmbs, id){
	for(var i = 0; i < $allTmbs.length; i++){
		var $curTmb = $allTmbs.eq(i);
		if($curTmb.attr("vid") == id){
			$curTmb.addClass("on"); 
		}
		else{
			$curTmb.removeClass("on");
		}
	}
}


