var $j = jQuery.noConflict();

$j(document).ready(function() {
	
	// AJAX for Rotating Images
	if ($j('#slider img').length > 1)
	{
		$j('#slider').nivoSlider({
			effect: 'fade',
			animSpeed: 1000,
			pauseTime: 4000,
			directionNav: false,
			controlNav: false
		});
		
		$j("#header_vid").click(function() {
			var vid = 'videoseries?list=PL03211455D8C97D83';
			
			$j(this).remove();
			$j('#header_contest').remove();
			
			$j('#slider').fadeOut('400', function(){
				$j('#slider').replaceWith('<iframe width="745" height="500" src="http://www.youtube.com/embed/'+vid+'&theme=light&color=white&hd=1&showinfo=0&wmode=transparent&modestbranding=1&autoplay=1&rel=0" frameborder="0" allowfullscreen></iframe>');
			});
		});
	}
	
	// Remove TV Ad and Main Image; Replace with Video
	$j(".header_youtube").click(function(e) {
		e.preventDefault();
		
		var youtube = $j(this).attr('id');
		var seperator = youtube.substring(youtube.length-1, youtube.length);
		
		if (/\?/.test(youtube))
		{
		   seperator = '&';
		}
		else
		{
			seperator = '?';
		}
		
		$j('#main_img').fadeOut('400', function(){
			$j('#main_img').replaceWith('<iframe width="745" height="500" src="http://www.youtube.com/embed/'+youtube+seperator+'theme=light&color=white&hd=1&showinfo=0&wmode=transparent&modestbranding=1&autoplay=1&rel=0" frameborder="0" allowfullscreen></iframe>');
		});
	});
	
	// Remove TV Ad and Main Image; Replace with Video
	$j(".header_youtube_large").click(function(e) {
		e.preventDefault();
		
		var youtube = $j(this).attr('id');
		var seperator = youtube.substring(youtube.length-1, youtube.length);
		
		if (/\?/.test(youtube))
		{
		   seperator = '&';
		}
		else
		{
			seperator = '?';
		}
		
		$j(this).fadeOut('400', function(){
			$j(this).replaceWith('<iframe width="745" height="500" src="http://www.youtube.com/embed/'+youtube+seperator+'theme=light&color=white&hd=1&showinfo=0&wmode=transparent&modestbranding=1&autoplay=1&rel=0" frameborder="0" allowfullscreen></iframe>');
		});
	});
	
});
