$(document).ready(function() {
	$("#trailer img").hover(
		function(){
			$(this).attr('src','../images/trailer-active.png');
		}
		,
		function(){
			$(this).attr('src','../images/trailer.png');
		}
	);
	$("#trueevents img").hover(
		function(){
			$(this).attr('src','../images/true-events-active.png');
		}
		,
		function(){
			$(this).attr('src','../images/true-events.png');
		}
	);
	$(".pop-home").hover(
			function(){
				$(this).attr('src','../images/content-home-active.png');
			}
			,
			function(){
				$(this).attr('src','../images/content-home.png');
			}
		);

	var player = $f("player", "js/flowplayer/flowplayer-3.2.2.swf");
	// setup button action. it will fire our overlay 
	$("img[rel]").each(function(i) {
		if(i==0){
			// trailer
			$(this).overlay({
				top: 120,
				fixed: false,
				// when overlay is opened, load our player
				onLoad: function() {
					mask();
					$("#jpId").jPlayer('pause');
					player.load();
				},
				// when overlay is closed, unload our player
				onClose: function() {
					unmask();
					$("#jpId").jPlayer('play');
					player.unload();
				}
			});
		}else{
			// true events
			$(this).overlay({
				top: 70, 
				fixed: false,
				// when overlay is opened
				onLoad: function() {
					mask();
				},
				// when overlay is closed
				onClose: function() {
					unmask();
				}
			});
		}
	});

	// load animations
	$("#clinic img").delay(1500).fadeIn(1500);
	$("#the img").delay(3000).fadeIn(1500);
	$("#tags img").delay(4500).fadeIn(1500);
	$("#actors img").delay(6000).fadeIn(1500);
	$("#credits img").delay(6000).fadeIn(1500);
	$("#trailer img").delay(7500).fadeIn(1500);
	$("#trueevents img").delay(7500).fadeIn(1500);
	$("#links img").delay(9000).fadeIn(1500);

	// mp3 player
	$("#jpId").jPlayer( {
	  ready: function () {
	    this.setFile("assets/music.mp3");
	    this.play();
	  }
	}).jPlayer("onSoundComplete", function() {
		   this.element.jPlayer("play");
	  });
			
});

function mask(){
	$("#mask img").show();
	$(".maskable img").hide();
}
function unmask(){
	$(".maskable img").show();
	$("#mask img").hide();
}
