//DESCRIBES VARIABLES
//describe the minmum width and height
var flashWidthMin = 664;
var flashWidthMax = 1046;
var flashWidthMax = false;

var sideBarWidthMin = 236;
var sideBarWidthMax = 236;

var heightMin = 570;
var heightMax = 800;
var heightMax = false;

var flashWidth = 0;
var sideBarWidth = 0;

//limit for srinking of window 
var winW = 0;
var winH = 0;
var calH = 0;


var ns4 = false;
var op5 = false;
var menutop = 255;
var menusingle = 18;

//checks for page resize
function initWindow()
{
	window.onresize = function()
	{
		squeeze();
		
	};
	window.onresize();
	return true;
}

//functions amends all page content if page is siz eis smaller than limit
function squeeze()
{
	//gets the height for the window
	getWindowData();

	//calculates the height for the window
	//in respect to the set min and max
	processHeight();
		
	//calculate two other elements widths
	calculateSideBar();
	calculateFlash();
	
	//do specific needs of resize here	
	var sideBar = document.getElementById('sidebar');	
	sideBar.style.height = calH +"px";
	sideBar.style.width = sideBarWidth + "px";
	//sideBar.innerHTML = sideBarWidth+' x '+calH;
	
	var flash = document.getElementById('flash');
	flash.style.height = calH +"px";
	flash.style.width = flashWidth + "px";
	//flash.innerHTML = flashWidth+' x '+calH;
	
	//flash and sidebar vertical centering
	if(heightMax)
	{
		if(winH > heightMax)
		{
			flash.style.top = ((winH-heightMax)/2)+ "px";
			sideBar.style.top = ((winH-heightMax)/2)+ "px";
		}
		else
		{
			flash.style.top = "auto";
			sideBar.style.top = "auto";
		}
	}
	
	//flash horizontal centering
	if(flashWidthMax)
	{
		var flashWidthSpace = winW - sideBarWidth;
		if(flashWidthSpace > flashWidthMax)
		{
			flash.style.left = (sideBarWidth + ((flashWidthSpace-flashWidthMax)/2))+ "px";
		}
		else
		{
			flash.style.left = sideBarWidth + "px";
		}
	}
	
	//sidebar horizontal centering
	if(sideBarWidthMax)
	{
		var sideBarWidthSpace = winW - flashWidth;
		if(sideBarWidthSpace > sideBarWidthMax)
		{
			sideBar.style.left = ((sideBarWidthSpace-sideBarWidthMax)/2) + "px";
		}
		else
		{
			sideBar.style.left = 0 + "px";
		}
	}
	
	//address positioning
	var address = document.getElementById('address');
	if(winH < calH)
	{
		address.style.bottom = "auto";
		var menuheight = getElementHeight('menu');
		var addresstop = 400;
		if((menutop + menuheight) > addresstop)
		{
			addresstop = (menutop + menuheight + (menusingle*2));
			if((menutop + menuheight + (menusingle*2) + getElementHeight('address')) < calH)
			{
				addresstop = (menutop + menuheight + (menusingle*2));
			}
		}
		address.style.top = addresstop + "px";
	}
	else if(winH > calH)
	{
		address.style.top = (calH - 110) + "px";
	}
	else
	{
		address.style.top = "auto";
		address.style.bottom = 25 + "px";
	}
	//address.innerHTML = curPos+' , '+addPos;

	return false;
}

function getWindowData() 
{
	if( typeof( window.innerWidth ) == 'number' ) 
	{
		//Non-IE
		winW = window.innerWidth;
		winH = window.innerHeight;
	} 
	else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) 
	{
		//IE 6+ in 'standards compliant mode'
		winW = document.documentElement.clientWidth;
		winH = document.documentElement.clientHeight;
	} 
	else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) 
	{
		//IE 4 compatible
		winW = document.body.clientWidth;
		winH = document.body.clientHeight;
	}
}

function processHeight()
{
	calH = winH;	
	if(heightMin)
	{
		if(calH < heightMin)
		{
			calH = 	heightMin;
		}
	}
	
	if(heightMax)
	{
		if(calH > heightMax)
		{
			calH = 	heightMax;
		}
	}
}

function calculateSideBar()
{
	sideBarWidth = winW;
	if(sideBarWidthMin)
	{
		if(sideBarWidth < sideBarWidthMin)
		{
			sideBarWidth = 	sideBarWidthMin;
		}
	}
	
	if(sideBarWidthMax)
	{
		if(sideBarWidth > sideBarWidthMax)
		{
			sideBarWidth = 	sideBarWidthMax;
		}
	}
	return false;
}

function calculateFlash()
{
	flashWidth = winW - sideBarWidth;
	if(flashWidthMin)
	{
		if(flashWidth < flashWidthMin)
		{
			flashWidth = flashWidthMin;
		}
	}
	
	if(flashWidthMax)
	{
		if(flashWidth > flashWidthMax)
		{
			flashWidth = flashWidthMax;
		}
	}
	return false;
}

function getElementHeight(Elem) 
{
	if (ns4) {
		var elem = getObjNN4(document, Elem);
		return elem.clip.height;
	} else {
		if(document.getElementById) {
			var elem = document.getElementById(Elem);
		} else if (document.all){
			var elem = document.all[Elem];
		}
		if (op5) { 
			xPos = elem.style.pixelHeight;
		} else {
			xPos = elem.offsetHeight;
		}
		return xPos;
	} 
}

function addLoadListener(fn)
{
	if (typeof window.addEventListener != 'undefined'){
		window.addEventListener('load', fn, false);
	}else if (typeof document.addEventListener != 'undefined'){
		document.addEventListener('load', fn, false);
	}else if (typeof window.attachEvent != 'undefined'){
		window.attachEvent('onload', fn);
	}else{
		var oldfn = window.onload;
		if (typeof window.onload != 'function'){
		window.onload = fn;
		}else{
			window.onload = function(){
				oldfn();
				fn();
			};
		}
	}
}
