$(window).load(function() {
 $('#splash').fadeIn(2000, function() {
	$(this).delay(500).fadeOut(2000, function() { 
		$('#containersplash, #reelsplash').fadeIn(1000); });
	   });  
});

$(window).load(function() {
 $('#skip').fadeOut(3500); 
});

$(function(){
    var navbar = $('#navbar'),
        navbarLinks = $(".navbarlink", navbar);
  
navbarLinks.hover(function () {             
   navbarLinks.not(this).stop().animate({opacity: 0.3}, "slow");
    }, function () {      
        navbarLinks.stop().animate({opacity: 1.0}, "slow");       
    }); 
});

$(function(){
    var footer = $('#footer'),
        footerLinks = $(".footerlink", footer),
        allFadeables = $('.divider', footer).add(footerLinks);
  
footerLinks.hover(function () {             
   allFadeables.not(this).stop().animate({opacity: 0.3}, "slow");
    }, function () {      
        allFadeables.stop().animate({opacity: 1.0}, "slow");       
    }); 
});

$(function(){
    var footer = $('#footerhome'),
        footerLinks = $(".footerlink", footer),
        allFadeables = $('.divider', footer).add(footerLinks);
  
footerLinks.hover(function () {             
   allFadeables.not(this).stop().animate({opacity: 0.3}, "slow");
    }, function () {      
        allFadeables.stop().animate({opacity: 1.0}, "slow");       
    }); 
});

$(function(){
    var copy = $('#copy'),
        copyLinks = $(".picturethumb", copy);
  
copyLinks.hover(function () {             
   copyLinks.not(this).stop().animate({opacity: 0.3}, "slow");
    }, function () {      
        copyLinks.stop().animate({opacity: 1.0}, "slow");       
    }); 
});

$(function(){
    var navthumb = $('#navthumb'),
        navthumbLinks = $(".thumb", navthumb);
  
navthumbLinks.hover(function () {             
   navthumbLinks.not(this).stop().animate({opacity: 0.3}, "slow");
    }, function () {      
        navthumbLinks.stop().animate({opacity: 1.0}, "slow");       
    }); 
});

$(function() {
    var scrollX = 0;
    var n = 0;
    var triggerID;
    var speed = 4000;  //speed in ms
    var endTime=0;
    var remainingTime;
    var iTimeOut=0; 
    var scrollHorIsRunning = false;
    
    function rearrange() {
        $('.scrollimg').last().clone().insertBefore($('.scrollimg:eq(0)')).css({width: 0, marginRight: 0});
        $('.scrollimg').last().remove();
    }
/*    function scrollHor(time) {
        endTime = time + (new Date()).getTime();
        $('.scrollimg:eq(0)').animate({width: 816, marginRight: 47}, time);
    }*/
    
    function scrollHor(time,bRearrange) {
        if (!scrollHorIsRunning) {
			if (bRearrange !== undefined && bRearrange === true)
				rearrange();
            scrollHorIsRunning=true;
             endTime = time + (new Date()).getTime();
             $('.scrollimg:eq(0)').animate(
                  {width: 816, marginRight: 47},
                  time,
                  function() {  // Animation complete.
                        scrollHorIsRunning=false;
						endTime = 0;
                  });
       }
    }
    
    $(window).load(function() {
//        rearrange();
        scrollHor(2000,true);
        triggerID = setInterval(function(){//rearrange(); 
			scrollHor(2000,true);}, speed);
    });
        
    $("#scrollArea").hover( function(){
		if (endTime != 0){
			remainingTime = endTime - (new Date()).getTime();
		}
		else {
			remainingTime = 0;
		}
        clearInterval(triggerID);
        $('.scrollimg:eq(0)').stop(true, false);
        scrollHorIsRunning=false;
    }, function() {
        scrollHor(remainingTime,false);
		if (iTimeOut == 0) {
	        iTimeOut = setTimeout(function() {
				iTimeOut = 0;
				triggerID = setInterval(function(){//rearrange(); 
					scrollHor(2000,true);}, speed);
			}, remainingTime);
		}
    });
 });
