//$ switched to jQuery because of noConflict mode

function getPageHeight() {
	return self.innerHeight || (document.documentElement.clientHeight || document.body.clientHeight);
}

function getScrollY() {
    var scrOfY = 0;
    if (typeof(window.pageYOffset) == 'number') {
        //Netscape compliant
        scrOfY = window.pageYOffset;
    } else if (document.body && (document.body.scrollTop)) {
        //DOM compliant
        scrOfY = document.body.scrollTop;
    } else if (document.documentElement && (document.documentElement.scrollTop)) {
        //IE6 standards compliant mode
        scrOfY = document.documentElement.scrollTop;
    }
    return scrOfY;
}

function handleFooter() {
	var D = document;
    var pageHeight = Math.max(
        Math.max(D.body.scrollHeight, D.documentElement.scrollHeight),
        Math.max(D.body.offsetHeight, D.documentElement.offsetHeight),
        Math.max(D.body.clientHeight, D.documentElement.clientHeight)
    );

    //var windowHeight = getPageHeight();
	var magicNumber = pageHeight-900;
    var pageY = getScrollY();

   if (pageY > magicNumber) {
	    //console.log("should be animating up")
        jQuery("#footer_slide").stop().animate({
            bottom: "0px"
        }, 1000);
    } else {
		//console.log("should be animating down")
        jQuery("#footer_slide").stop().animate({
            bottom: "-118px"
        }, 700);
    }
}

jQuery(document).ready(function() {

    jQuery("#footer_slide").css({
        'bottom': '-110px'
    });

    jQuery(window).scroll(function() {
        handleFooter();
    });
	
	jQuery(window).bind('resize', function() {
    	handleFooter();	
    });
	
	handleFooter();
});
