$(document).ready(function(){
	
	$('#work-content').css('overflow','hidden');
	$("#work-right").css("background","url(assets/images/bookshelf/next.gif) center no-repeat");
	
	//alert($('.shelf-row .shelf').length + ' divs!');
	//alert($('.shelf').width());
	//alert($('.shelf').width() * $('.shelf-row .shelf').length);
	
	var gapBetweenDivs = 17;
	var totalElements = $('ul#work-screens li').length;
	var singleWidth = $('ul#work-screens li').width();
	var maxWidth = totalElements * (singleWidth + gapBetweenDivs);
	
	//var totalWidth = ($('.shelf').width() + 10) * $('.shelf-row .shelf').length;
	
	$('ul#work-screens').css('width', maxWidth);
	
	var defaultPos =- 0;
	
	$('#work-left').click(function()	{
		  
		  defaultPos += 217;
          //alert(defaultPos);
			if (defaultPos > 0){
				$("#work-left").css("background-image","none");
				$("#work-right").css("background","url(assets/images/bookshelf/next.gif) center no-repeat");
				defaultPos = 0;
			}
            else if(defaultPos <= 0){
				
                $("#work-left").css("background","url(assets/images/bookshelf/prev.gif) center no-repeat");
                $("#work-right").css("background","url(assets/images/bookshelf/next.gif) center no-repeat");
        
				$("ul#work-screens").animate({marginLeft: defaultPos + "px" },{duration:500});
				
		    }
		
		
	});
	
	$('#work-right').click(function()	{
		defaultPos -= 217;
		//alert(defaultPos);
			if (defaultPos <= -maxWidth)
            {
                $("#work-left").css("background","url(assets/images/bookshelf/prev.gif) center no-repeat");
                $("#work-right").css("background-image","none");
				defaultPos = -maxWidth + singleWidth + gapBetweenDivs;
            }
            else if(defaultPos > -maxWidth){
                //alert(-maxWidth);
				$("#work-left").css("background","url(assets/images/bookshelf/prev.gif) center no-repeat");
                $("#work-right").css("background","url(assets/images/bookshelf/next.gif) center no-repeat");
				
				$("ul#work-screens").animate({marginLeft: defaultPos + "px"},{duration:500});
            }
			
		
    }); 
	 
});
