/**
 * @author Michael Simard
 */

var imageInterval;
var COOKIE_NAME = "mofos_tour_allowed_trailer_scene";
$(document).ready(function(){	
	$(".watching_now .scene_185x155_with_info").hover(function(){
		var id = $(this).attr("id").replace("scene_", "");
		swapImage(id);
		
		imageInterval = setInterval("swapImage(" + id + ")", 1500);		
	}, function()	{
		clearInterval(imageInterval);  		
	});	
	
	$(".watching_now a").click(function(){
		var id = $(this).parents(".scene_185x155_with_info").attr("id").replace("scene_", "");
		$.cookie(COOKIE_NAME, id, { path: '/', expires: 1 });	
	});
	
	$(".col_latest_scenes a:lt(5)").click(function(){
		var id = $(this).attr("id").replace("latest_", "");		
		$.cookie(COOKIE_NAME, id, { path: '/', expires: 1 });	
	});
});

/*
 * Swap between 3 images at the interval set on the document ready
 */
function swapImage(id)
{
	var obj = $("#scene_"+ id);
	var img = obj.find("img");
	var imgNum = parseInt(img.attr("alt"));	
	nextimgNum = imgNum + 1;
	nextimgNum %= 5;
	nextimgNum += 1;
	
	img.attr("alt", nextimgNum );
		
	var src = img.attr("src");
	
	var newsrc = src.replace("br" + imgNum, "br" + nextimgNum);
	
	
	img.attr("src", newsrc);
	
}
