// JavaScript Document used to make an element 100% of window height

//uses dimensions and jQem plugins

$.fn.heightFix = function(origWindowHeight, origDocHeight)
{
	var windowHeight = $(window).height(); //get current height
		
	//browser height has not changed OR browser was re-sized larger than original
	if(windowHeight >= origWindowHeight)
	{
		if(windowHeight	>= origDocHeight)
		{
			$(this).height(windowHeight);
		}
		else //window height is < origDocHeight
		{
			$(this).height(origDocHeight);
		}
	}
	
	//browser was re-sized smaller than original
	if(windowHeight < origWindowHeight)
	{
		if(origWindowHeight	>= origDocHeight)
		{
			$(this).height(origWindowHeight);
		}
		else //orig doc height was larger than origWindowHeight
		{
			$(this).height(origDocHeight);
		}
	}
	
	return this;
}

var emChanged = function(origWindowHeight)
{
	var currentDocHeight = $(document).height();
	
	$('#outer').heightFix(origWindowHeight, currentDocHeight);
}

$(document).ready(function()
{  
    var origWindowHeight = $(window).height(); //orignal window height
	var origDocHeight = $(document).height(); //store orginal document height
	
	$('#outer').heightFix(origWindowHeight, origDocHeight); //do this as soon as doc is ready
	 
	$(window).resize(function() //call again every time the window is re-sized
	{
		$('#outer').heightFix(origWindowHeight, origDocHeight);					
	});
	
	//call on font-resize
	$.jqem.bind( function()
	{
		emChanged(origWindowHeight);
	});
});