$(function(){
        $('#background-overlay').hide();
        //$('#background-sequence').cycle({timeout: 2400, delay:0}).hide().fadeIn('slow'); 
        $('#background-sequence').cycle({timeout: 8000, delay:10000}).hide(); 

        $('#smallprint').hide();
        $('#nav').hide();
        $('h1').hide(); 
        $('a#skip-movie').hide();
        $('div#movie').hide();
        $('h1').fadeIn('slow', function(){
            $('a#skip-movie').fadeIn('slow');
            $('div#movie').fadeIn('slow');
        });
        
        /*
        $('h1').delay(8000).fadeIn(1000, function(){
            $('#background-sequence').cycle('pause');
            $('#nav').fadeIn(4000, function(){
                $('#background-overlay').fadeIn();
                $('#smallprint').fadeIn('slow');
            });
        });
        */
        $('a#skip-movie').click(function(){
            $('#rake-rankin-movie').remove();
            $('a#skip-movie').hide();
            $('div#movie').hide();
            $('#background-sequence').cycle('pause').cycle(0).fadeIn();
            $(window).trigger('resize');
            $('#nav').fadeIn(1000, function(){
                //$('#background-overlay').fadeIn(); //NO OVERLAY 
                $('#smallprint').fadeIn('slow');
            });
        });
        
        $('#nav > li > a').click(function(){
            if ($(this).next('div').css({'opacity':'0.2'}).hasClass('expanded')) {
                $(this).next('div').slideUp('slow').removeClass('expanded');
                $(this).parent().removeClass('current');
            } else {
                $('#nav > li > div.expanded').css({'opacity':'0.2'}).slideUp('slow').removeClass('expanded').fadeOut('slow');
                $('#nav > li').removeClass('current');
                $(this).next('div').slideDown('slow').addClass('expanded').css({'opacity':'1'});   
                $(this).parent().addClass('current');
                if ($(this).parent().hasClass('style-scrollable')) {
                    //$('#background-overlay').hide();
                    $('div#style-scroller').smoothDivScroll({ scrollingSpeed: 8, mouseDownSpeedBooster: 3, visibleHotSpots: 'always', hiddenOnStart: false });
                    $("div#style-scroller div.scrollingHotSpotRight").show(); //20110222
                    $(window).trigger('resize'); //20110222
                    $('#background-sequence').cycle(2);
                    
                    $('#scrollableArea a').mouseout(function(){
        $('#scrollableArea').css({'opacity':'0.1'});
    });
                    $(window).trigger('resize'); //20110317
                } else if ($(this).parent().hasClass('collection-scrollable')) {
                    $("div#contact-sheet-scrollable").smoothDivScroll({});
                    $("div#contact-sheet-scrollable div.scrollingHotSpotRight").show(); //20110222
                    //$(window).trigger('resize'); //20110222
                    $('#background-sequence').cycle(3);
                } else {
                    $('#background-sequence').cycle($(this).parent().index()+1);
                    //$('#background-overlay').fadeIn(); //NO OVERLAY
                }
            }
            $(window).trigger('resize');
        });
        
        $('.scrollableArea a').click(function(){
            if ($('#background-overlay').is(':visible')) {$('#background-overlay').fadeOut();}
        });
        
        
			
		$('.inner-film-upper a').hover(function(){$(this).children(':first-child').fadeTo('fast', 0.8)}, function(){$(this).children(':first-child').hide()});
    	$('.inner-film-lower a').hover(function(){$(this).children(':first-child').fadeTo('fast', 0.8)}, function(){$(this).children(':first-child').hide()});
        /*
        var showhash = window.location.hash ? '[hash=' + window.location.hash + ']' : '';
        if (showhash != '') {
            $('#nav a').filter(showhash).click();
            $(window).trigger('resize');
        }
        */    
        
        $('a.flareable').hover(
    		function () {
    			if (!($(this).parent().hasClass('flare'))) {
    				$(this).wrap('<div class="flare"></div>');
    			}
    		}, 
    		function () {
    			if (($(this).parent().hasClass('flare'))) {
    				$(this).unwrap();
    			}
    		}
    	);
    	    	
    	setupZoom();
    	
		$(window).bind("resize", function(){
		      
			$('#background-sequence img').width($(this).width());
			$('#background-sequence img').css({'height':768*$('#background-sequence img').width()/1152});

            //Logging
            //$('p#logger').show().text($('#background-sequence img').height());

        });
        
        $('#rake-rankin-movie').bind('ended', function() {
            $(this).delay(1000).fadeOut('slow', function(){
                $('a#skip-movie').trigger('click');
            });
        });
        
    });
    
function resizeBackgroundImage() {
    $imgs = $('#background-sequence img');
    $('#background-sequence img').css({'width':'100%','height':768*$(this).width()/1152});
}
 
    
    function bringStyle(obj,num) {
        $(obj).parent().children().fadeTo('fast', 0.1);$(obj).css({'cursor':'default'});$('#background-sequence').cycle(num);
    }
