function ReplaceContentInContainer(id,content) {
	var container = document.getElementById(id);
	container.innerHTML = content;
}

function ReplaceContentWithYouTube(id,url,title) {
	var flashvars = {};
	var params = 
	{
		'movie'				:url,
		'allowFullScreen'	:'true',
		'autoplay'			:1,
		'rel'				:0,
		'allowscriptaccess' :'always',
		'wmode'				:'window'
	};
	var attributes = {};
	swfobject.embedSWF(url, id, '516', '316', '9.0.28', 'swfs/expressInstall.swf', flashvars, params, attributes);
	var container = document.getElementById('video-title');
	container.innerHTML = title;
	/*container = document.getElementById('video');
	container.style.visibility = default;*/
}

function ShowSuspectInfo(pos,suspect) {
	//$(".suspect").removeClass("hidden");
	$(".suspect").addClass("hidden");
	$("#"+suspect).removeClass("hidden");
	
	$("#info-popover").removeClass("one two three visible");
	$("#info-popover").addClass("visible");
	$("#video").addClass("hidden");
	switch (pos){
		case 0:
			$("#info-popover").addClass("one");
			break;
		case 1:
			$("#info-popover").addClass("two");
			break;
		case 2:
			$("#info-popover").addClass("three");
			break;
	}
	//var popover = document.getElementById('info-popover');
	//popover.style.visibility = "visible";
}

function HideSuspectInfo() {
	//var popover = document.getElementById('info-popover');
	//popover.style.visibility = "hidden";
	$("#info-popover").removeClass("one two three visible");
	$("#video").removeClass("hidden");
}

$(document).ready(function() {
	


	var items = $(".slideshow-image");
	var titles = $(".thumbnail-title");
	
	
	if (items.length > 3) {
		var container = $(".slideshow-image-container");
		var mask = container.parent();
		$("#arrow-left").removeClass("normal disabled");
		$("#arrow-left").addClass("disabled");
		$("#arrow-right").removeClass("normal disabled");
		$("#arrow-right").addClass("normal");
	}
	
	/*
	items.each(function(i) {
		$(this).attr({
			name: $(this).find(".thumbnail-title").text(),
			id: i
		});
	});
	*/
	
	
	for (var i=0;i<items.length;i++) {
		$(items[i]).attr({
				//name:$(titles[i]).html(),
				name:$(items[i]).find(".thumbnail-title").text(),
				id:i
			});
		
		$(items[i]).mouseenter(function() {
			var pos = $(this).attr("id") - -(Math.round(parseInt(container.css("marginLeft"))/items.outerWidth(true)));
			ShowSuspectInfo(pos,$(this).attr("suspect"));
		});
		
		$(items[i]).mouseleave(function() {
			HideSuspectInfo();
		});
		
		$(items[i]).click(function() {
			if($(this).attr("href")){
				var popover = document.getElementById('info-popover');
				//popover.style.visibility = "hidden";
				$("#info-popover").removeClass("one two three visible");
				
				ReplaceContentWithYouTube('video',$(this).attr("href").replace('http://www.youtube.com/watch?v=','http://www.youtube.com/v/')+'&hl=en&fs=1&autoplay=1&rel=0&iv_load_policy=3',$(this).attr("name"));

			}
			return false;
		});
	}
	
	$("#arrow-left").click(function() {
		if (parseInt(container.css("marginLeft")) < 0 && !container.is(":animated")) {
			container.animate({ marginLeft: "+=" + items.outerWidth(true) + "px" });
			
			$("#arrow-right").removeClass("normal disabled");
			$("#arrow-right").addClass("normal");
			
			if (parseInt(container.css("marginLeft")) >= -((1) * items.outerWidth(true)))
			{
				$("#arrow-left").removeClass("normal disabled");
				$("#arrow-left").addClass("disabled");
			}
		}
		return false;
	});
	
	$("#arrow-right").click(function() {
		if (parseInt(container.css("marginLeft")) > -((items.length - 3) * items.outerWidth(true)) && !container.is(":animated")) {
			container.animate({ marginLeft: "-=" + items.outerWidth(true) + "px" });
			
			$("#arrow-left").removeClass("normal disabled");
			$("#arrow-left").addClass("normal");
			
			if (parseInt(container.css("marginLeft")) <= -((items.length - 4) * items.outerWidth(true)))
			{
				$("#arrow-right").removeClass("normal disabled");
				$("#arrow-right").addClass("disabled");
			}
		}
		return false;
	});

	// Slide to the selected slideshow-image if necessary
	var currentSlideshowImage = $(".slideshow-image.current");
	var currentSlideshowImageIndex = currentSlideshowImage.prevAll(".slideshow-image").length + 1;
	if (currentSlideshowImageIndex > 3) {
		var slideBy = currentSlideshowImage.position().left;
		slideBy -= items.outerWidth(true) * 3;
		container.animate({ marginLeft: "-=" + slideBy + "px" });
	}
	
	//ReplaceContentWithYouTube('video','http://www.youtube.com/v/O0rx1srLsh0&hl=en&fs=1',"Nancy makes a break for it");
	handleResize();
	$(items[0]).click();
});

window.onresize = function(e){
	
	handleResize();

}

function handleResize(){
	var bgDiv = document.body;
	if(window.innerWidth < 960)
	{
		bgDiv.style.backgroundPosition = "-250px 0px";
	}
	else
	{
		bgDiv.style.backgroundPosition = "top center";
	}
}
