﻿var lastHeight = 0;

function getWindowHeight() {
	var thisHeight = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		thisHeight = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		thisHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		thisHeight = document.body.clientHeight;
	}
	
	return thisHeight;
}

jQuery(document).ready(function(){
  	
	//get the min top height
	var headWrapHeight = jQuery(".HeadWrapper").height();
	var mainWrapHeight = jQuery(".MainNav").height();
	var footNavHeight = jQuery(".FootNav").height();
    var leftLightHeight = jQuery(".LeftHighlights").height();
    
    //25 is the top margin on main wrapper
    var minTop = mainWrapHeight + headWrapHeight + 25;
	var offset = 50;
	
	lastHeight = getWindowHeight();
	
	//if it's ie6 then add to the offset
	if (navigator.userAgent.toLowerCase().indexOf("msie 6") != -1){ 
		offset = 55;
		minTop = minTop + 10;
	}
	//if it's ie7 then add to the offset
	else if (navigator.userAgent.toLowerCase().indexOf("msie 7") != -1){ 
		offset = 50;
	}
	//if it's safari then add to the offset
	else if (navigator.userAgent.toLowerCase().indexOf("safari") != -1){ 
		offset = 50;
	}
	
	//if the height to stretch is more than the main nav 
	var newTop = lastHeight - footNavHeight - leftLightHeight - offset;
	if(newTop > minTop){
		jQuery(".FootNavWrapper").css("top", newTop);
	}
	else {
		jQuery(".FootNavWrapper").css("top", minTop);
	}
	jQuery(".FootNavWrapper").css("left", "0");
	
	//on resize set the top
    jQuery(window).resize(function () {   
        		
		//if there is no more scroller then go to menuyloc
		var thisTop = getWindowHeight() - footNavHeight - leftLightHeight - offset;
		if(thisTop > minTop){
			jQuery(".FootNavWrapper").css("top", thisTop);
		}
		else {
			jQuery(".FootNavWrapper").css("top", minTop);
		}
	});
    
    //onscroll set the top
	jQuery(window).scroll(function () {   
        
        //if there is no more scroller then go to menuyloc
		var thisTop = getWindowHeight() - footNavHeight - leftLightHeight - offset + jQuery(document).scrollTop();
		
		if(thisTop > minTop){
			jQuery(".FootNavWrapper").css("top", thisTop);	
		}
		else {
			jQuery(".FootNavWrapper").css("top", minTop);
		} 
    });
});


