$(document).ready( function() {
	//Make the entire nav cell light up on hover
	$('#leftNav li').hover(
		function() {
			$(this).addClass('leftNavHover');
		},
		function() {
			$(this).removeClass('leftNavHover');
		}
	);
	// Make the entire navigation cell clickable
	$('#leftNav li').click(function(event) {
		window.location = $('a', this).attr("href");
	});
	// Make the video thumbnails light up on hover
	$('.video').hover(
		function() {
			$(this).removeClass('video');
			$(this).addClass('videoHover');
			//$(this).animate({opacity : 'toggle' }, 'slow');
		},
		function() {
			$(this).removeClass('videoHover');
			$(this).addClass('video');									
			//$(this).animate({opacity : 'toggle' }, 'slow');
		}
	);
	//Make the entire thumbnail div clickable
	$('.video').click(function(event) {
		window.location = $('a', this).attr("href");
	});
	//Prefill search box with helper text
	$('#search_term').focus(function() {
		if (this.value === 'Search Videos') {
			this.value = '';
		}
	});
	//Refill search box with helper text if empty on blur
	$('#search_term').blur(function() {
		if (this.value === '') {
			this.value = "Search Videos";
		}
	});
	// Apply jQuery UI button to certain links		
	$( "#takeActionLink" ).button();
	$( "#takeActionLink" ).click(function() { 
		window.location = $(this).attr("href");
	});	
	if ($("#takeActionLink").attr('href') == "") {
		$("#takeActionLink").hide();
	}
	
	// Call the rotating header image function
	var bgImage;
	bgImage = rotateHeaderImage();
	$('#headerAnimal').css("background-image", "url(" + bgImage + ")"); 	 
	
	//Initialize the AddThis buttons
	addthis.init();	
	
	//Deal with the iScroll element on the playlist
	$('#playlist_scroller').bind('touchmove', function(e){ e.originalEvent.preventDefault(); });
	scrollPlaylist = new iScroll('playlist_scroller' );			
}); // end document.ready()


function rotateHeaderImage() {
	var how_many_images = 10;
	var now = new Date()
	var sec = now.getSeconds()
	var image = sec % how_many_images;
	var imageUrl = 'http://video.humanesociety.org/assets/img/header_blank.png';
	image +=1;
	if (image==1) {
		  imageUrl="http://video.humanesociety.org/assets/img/header_monkeys.png";
	}
	if (image==2) {
		  imageUrl="http://video.humanesociety.org/assets/img/header_penguins.png";
	}
	if (image==3) {
		  imageUrl="http://video.humanesociety.org/assets/img/header_bears.png";
	}
	if (image==4) {
		  imageUrl="http://video.humanesociety.org/assets/img/header_horses.png";
	}
	if (image==5) {
		  imageUrl="http://video.humanesociety.org/assets/img/header_cats.png";
	}
	if (image==6) {
		  imageUrl="http://video.humanesociety.org/assets/img/header_chicken.png";
	}
	if (image==7) {
		  imageUrl="http://video.humanesociety.org/assets/img/header_deer_wildlife.png";
	}
	if (image==8) {
		  imageUrl="http://video.humanesociety.org/assets/img/header_dogs.png";
	}
	if (image==9) {
		  imageUrl="http://video.humanesociety.org/assets/img/header_geese_ducks.png";
	}
	if (image==10) {
		  imageUrl="http://video.humanesociety.org/assets/img/header_cows.png";
	}
	
	return imageUrl;
}


