jQuery(document).ready(function(){

	// news flicker
	
	
	jQuery('#news ul li a').click(function(e){
		
		e.preventDefault();
		flickNews(jQuery(this));	
		
	
	});
	
	
	jQuery("#homefeature > div.video a").click(function(e){
	
		e.preventDefault();
		var vidID = jQuery(this).attr('id');
		
		jQuery("#video-overlay").css('width', jQuery(window).width()).animate({"height" : jQuery(window).height()}, 200, function(){
		
			jQuery(this).children("div").animate({"height" : 505}, 500, function(){ jQuery(this).html(getVideo(vidID)); });
			
		
		});
		
			
	});
	
	jQuery("#video-overlay a").live("click", function(e){
		
		e.preventDefault();
	
		jQuery("#video-overlay").animate({"height" : 0}, 200, function(){
		
			jQuery(this).children("div").html("none").css("height", 0);
			
		
		});
		
		
	
	});
	
	
	jQuery('.shim').mouseenter(function(){
		
		jQuery(this).fadeTo('fast', 0.5);
		
	});
	
	jQuery('.shim').mouseenter(function(){
	
		jQuery(this).fadeTo('fast', 1).stop();
	
	});
	
	
});

jQuery(window).load(function(){
	
	/*
	var startHome;
	var numberofpanels = jQuery('#homefeature > div.shim').length;
	
	jQuery('#homefeature').mouseenter(function(){
		
		clearInterval(startHome);
		
		startHome = setInterval(function(){
	
		var randomnumber=Math.floor(Math.random()*numberofpanels);
		jQuery('#homefeature > div.shim').eq(randomnumber).fadeTo('fast', 0.5).fadeTo('fast', 1);
		
		}, 1000);


	}).mouseleave(function(){

      	clearInterval(startHome);
      	
    });
	*/
	
	

});

function flickNews(clicked){
	
		var flickTo = 0 - (clicked.parent().index() * jQuery('.newshold div').outerWidth());
		jQuery('#news ul').fadeOut('fast', function(){
			
			jQuery('#news ul li a').removeClass('active');
			clicked.addClass('active');
			
			jQuery('.newshold').animate({'marginLeft' : flickTo}, 500, function(){
		
				jQuery('#news ul').fadeIn();			
				
			});
	
		});	
}

function getVideo(videoID){

	var rcontent;
	var playername;

	switch(videoID){
	
		case 'promo':
			
			playername = 'musspromo2011';
		
		break;
		
		case 'worldskills':
			
			playername = 'video-player-worldskills';
		
		break;
		
		}
		
		if(jQuery.support.htmlSerialize){
	
		rcontent = '<object height="466" width="830" id="flash_14387723" type="application/x-shockwave-flash" data="/flash/' + playername + '.swf"><param value="opaque" name="wmode"></object>';
		
		}else{
		
		rcontent = '<embed src="/flash/' + playername + '.swf" height="466" width="830" allowscriptaccess="always" allowfullscreen="true" id="player1" name="player1" />';
		
		}
		
	
	
	
	rcontent += '<a href="" class="button">Close</a>';
	return rcontent;

}
