var currentAsset = 0;
var sizeInterval = 0;
$(document).ready(function(){

	
	sizeInterval = setInterval("calculateSizes()",200);
	var TimeOut = false;
	
	calculateSizes();

	$(window).resize(function() {
	calculateSizes();
	});
	
	$("img").lazyload({
		container:"#media_set",
		effect : "fadeIn",
	    placeholder : "/images/transparent.gif"
	});
	
	$("#scroll_nav").fadeIn();
	$("#left_arrow").css('left',-15);
	$("#right_arrow").css('right',-15);
	
	$("#left_arrow").mouseover(function(){
			$("#left_arrow").animate({
				left: '0'
			}, 0)
	});
	
	
	$("#left_arrow").mouseout(function(){
			$("#left_arrow").animate({
				left: '-15'
			}, 100)
	});
	
	
	$("#right_arrow").mouseover(function(){
			$("#right_arrow").animate({
				right: '0'
			}, 0)
	});
	
	
	$("#right_arrow").mouseout(function(){
			$("#right_arrow").animate({
				right: '-15'
			}, 100)
	});
	
	
	$("#scroll_left").click(function(){
			if (currentAsset > 0)
			{
				
				currentAsset-=1;
				
				$("#media_set").scrollTo($("#media_set").children("ul").children("li").get(currentAsset), 300);
				updateScroll();
				
			}
	});
	
	$("#scroll_right").click(function(){
		if (currentAsset < $("#media_set").children("ul").children("li").length-1)
		{
			
			currentAsset+=1;
			
			$("#media_set").scrollTo($("#media_set").children("ul").children("li").get(currentAsset), 300);
			updateScroll();
		}
	});
	
	updateScroll();
	
});
$(window).load(function(){
calculateSizes();
clearInterval(sizeInterval);

});


function updateScroll() {
	
	$('#scroll_left').show();
	$('#scroll_right').show();
	if (currentAsset == 0)
	{
		$('#scroll_left').hide();
	}
	
	if (currentAsset == $("#media_set").children("ul").children("li").length-1)
	{
		$('#scroll_right').hide();
	}
}
function calculateSizes(){
	
	$('#media_set_description').css('width',$(window).width() * .38);
	$('#media_set_description').css('top', $(window).height() *.5 - ($('#media_set_description').height()*.5));
	$('#scroll_nav').css('top',$('#container').height() * .5);
	
	$('li.media_asset_display').each(function(index) {
		$(this).height(Math.floor($(window).height()));
		$(this).width(Math.floor($(window).width()));
		
	});
	
	$('img.media_asset_display').each(function(index) {
	
		if ( ($(window).height() >= $(this).height()))
		{

			$(this).css("height","100%");
				$(this).css("width","");
			
		}
		
		if ( ($(window).width() >= $(this).width()))
		{

			$(this).css("width","100%");
			$(this).css("height","");
			
		}
	
		
		$(this).css("left", - ($(this).width() - $(window).width())/2);
		$(this).css("top", - ($(this).height() - $(window).height())/2);
		
		
	});
	
	
	$('#media_set ul').css("width",$('li').length*$('#container').width());

	$('#media_set ul').css("height",$(window).height());
	
	$("#media_set").scrollTo($("#media_set").children("ul").children("li").get(currentAsset));
}