/* Author: 

*/
function repositionFooter() {
    var window_height = $(window).height();
    var body_height = $('body').height();
    var container_height = $('#container').height();
    // var footer_height = $('footer').height() + 10; // $('#footer').height() will say 58 but it's really 68 because of bottom margin
    var footer_height = $('footer').height();
    var difference = window_height - container_height;

    console.log("window height: " + window_height);
    console.log("body height: " + body_height);    
    console.log("container height: " + container_height);
    console.log("footer height: " + footer_height);    
     
    if ( container_height < window_height ) {
	    // $('#container').height( body_height - footer_height );
	    $('footer').css ( 'margin-top', window_height - container_height + 35 + 'px' );
	    // $('#container').height( window_height );
    }

	$('footer').show();
    
 /*   
    if (difference > 0) {
        // reposition footer to bottom if we're on a page with short content and the window is tall
        // Check that the content height is at minimum 360 so we don't readjust the footer in the case
        // that page_height is being incorrectly reported due to an unclosed div or something
        if (page_height > 360) {            
            var offset = difference - footer_height;            
            $('#footer').css('top', offset + 'px');            
        }
    } else {
        // This closes up any little gaps at the bottom in the case where the content is longer than the window 
        // Usually just in IE
        // page_height + footer_height should = body_height
        var gap = body_height - page_height;
        if (gap > 0) {
            $('#footer').css('top', gap + 'px');            
        }
    }
*/
    
}

$(window).load(function() {

	// Front page carousel start
	$('#carousel').cycle({
        fx:     'fade',
        speed:  'slow',
        timeout: 0,
        pager:  '#nav',
        after: function() {
        	$('#navfield h3').html($(this).find('.hdr').html());
        	$('#navfield .caption').html($(this).find('.bdy').html());
        }
    });
    
    if ( $('#cases').children().length > 1 ) {    
	    // Front page small carousel start
	    $('#cases').cycle({
	    	fx:	'scrollHorz',
	    	speed: 'fast',
	    	prev: '#prev',
	    	next: '#next',
	    	timeout: 0,
	    	after: function() {
	    		$('#casestudy .caption').html($(this).find('.desc').html());
	    	}
	    });
    } else {
    	$('#prev').css("background-image", "none");
    	$('#next').css("background-image", "none");
    	$('#casestudy .caption').html($('.desc').html());
    }

    // hook-up footer animation
    $('footer').hoverIntent(
            function() { 
            	if( $('footer #body').is(':hidden') ) {
	                $('footer #body').show(50, function() { 
	                	console.log('call back');
	                	//$('html').scrollTop( $('body').height() );
		                $('html,body').animate({ scrollTop: $('body').height() }, 500); // body to work in Chrome
	                });
				}
            },
            function() {
                // do nothing
            });

    repositionFooter();

	/*
	grayscale($('section.casegrid img'));
    $('section.casegrid img').css("visibility", "visible");
	$('section.casegrid img').hover(
    	function(){
    		grayscale.reset($(this));
    	},
    	function() {
    		grayscale($(this));
    	}
	);
	*/

    
});
