$(window).load(function() {
	
	$('.content-box').fadeIn('fast');
	$('#loading').fadeOut('fast');
	$('.left-arrow').css('opacity','0.5');
	$('.right-arrow').css('opacity','0.5');
	
	var liWidth = 0;
	var anLiWidth = 0;
	var clickedImage = '';
	$('.mask li').each(function() 
	{ 
	        anLiWidth = $(this).width();
	        liWidth = liWidth + anLiWidth;
	});   
	
	$('.main-image-viewer li').hide();
	$('.main-image-viewer li:first').show();
	$('.mask li img').css('opacity','0.5');
	$('.mask li img:first').css('opacity','1.0');
	
	$('.mask li img').hover(
		function(){
			if($(this).parent('a').hasClass('current-image')){
				// don't do anything
			} else {
				$(this).css('opacity','1.0');
			}
		},
		function(){
			if($(this).parent('a').hasClass('current-image')){
				// don't do anything
			} else {
				$(this).css('opacity','0.5');
			}
		}
	);
	
	// Show images when clicked
	
	$('.thumb-link').click(function(){
		clickedImage = $(this).find('a').attr('href');
		$('.main-image-viewer li:visible').fadeOut('fast', function(){
			$(clickedImage).fadeIn('fast');
		});
		$(this).find('img').css('opacity','1.0');
		$('.current-image').find('img').css('opacity','0.5');
		$('.thumb-link a').removeClass('current-image');
		$(this).find('a').addClass('current-image');
		return false;
	});
	
	// Scroll thumbs based on mouse position
	

	var x=0, 
	    y=0,
	    rate=0,
	    maxspeed=10;
	var scrollerL;
	var scrollerR;
	
	$('.left-arrow').hover(
		function(){
			$(this).css('opacity','1.0');
	        scrollerL = setInterval( moveLeft, 30 );
	    },
	    function(){
	        clearInterval(scrollerL);
	        var stayHere = $('.mask ul').css('left');
	        $(this).css('opacity','0.5');
	    }
	);
	
	$('.right-arrow').hover(
		function(){
			$(this).css('opacity','1.0');
	        scrollerR = setInterval( moveRight, 30 );
	    },
	    function(){
	        clearInterval(scrollerR);
	        $('.mask ul').stop(true, false);
	        $(this).css('opacity','0.5');
	    }
	);
	
	
	function moveLeft(){
		var w = 335;
	    rate = (120 + 1)/w;
	    x += maxspeed * rate;
	    var newpos = x+'px';
	    $('.mask ul').css('left',newpos);
	    console.log('poop');
	}
	
	function moveRight(){
		var w = 335;
	    rate = -(120 + 1)/w;
	    x += maxspeed * rate;
	    var newpos = x+'px';
	    $('.mask ul').css('left',newpos);
	}
	
	
	
	
	
	
	



});


















