/*
  2010-09-12
*/
function ResizeBackgroundImageProportional()
{
	ResizeBackgroundImageProportional.prototype.resizeImage = function()
	{
		var screen_width;
		var screen_height;	
		var backgroundImage = document.getElementById("backgroundImg"); //Get the image object from dom width jquery
		var ratioX=0;
		var ratioY=0;
		var activeElement_new_width=0;
		var activeElement_new_height=0;
		var withScrollWidth=0;
		var withScrollHeight = 0;
		//var backgroundImageWidth = 1020;
		//var backgroundImageHeight = 768;		
		if(backgroundImage != null) //Isn't null than
		{
			//ToDo: It is a better way to get the width and height from the backgroundImg but not from the attributes width and height
			var backgroundImageWidth = backgroundImage.getAttribute("xwidth"); 
			var backgroundImageHeight = backgroundImage.getAttribute("xheight");		
		
			if (/MSIE (\d+\.\d+);/.test(navigator.userAgent))
			{ //test for MSIE x.x;
			
				var ieversion=new Number(RegExp.$1) // capture x.x portion and store as a number
				if (ieversion==6)
				{		
					screen_width = document.body.clientWidth;
					screen_height = document.body.clientHeight;
			    }
				if (ieversion>=7)
				{			    	
					screen_width = document.body.clientWidth;
					screen_height = document.body.clientHeight;
			    }
			}		
			else //No
			{
			    screen_width = window.innerWidth;
			    screen_height = window.innerHeight;
			    withScrollHeight = (document.getElementById("content-overlay").scrollHeight-screen_height)
			}
			if(withScrollHeight < 0)
				withScrollHeight = 0;
				screen_height += withScrollHeight;
				if(screen_width > screen_height) 
				{
					ratioX = screen_width/backgroundImageWidth; //Calculate the ratio and set new width and height for the background image
					activeElement_new_width = backgroundImageWidth * ratioX;
					activeElement_new_height = (backgroundImageHeight*ratioX);
				}
				else
				{
					ratioY = screen_height/backgroundImageHeight;				
					activeElement_new_height = backgroundImageHeight * ratioY; 
					activeElement_new_width = backgroundImageWidth * ratioY;
				}
			
				if(activeElement_new_width < screen_width) //Check is the resized image smaller than the screen size
				{
					ratioX = screen_width/backgroundImageWidth; //Calculate the ratio and set new width and height for the background image
					activeElement_new_width = backgroundImageWidth * ratioX;
					activeElement_new_height = (backgroundImageHeight*ratioX);		    	
				}
				if(activeElement_new_height < screen_height)
				{
					ratioY = screen_height/backgroundImageHeight;				
					activeElement_new_height = backgroundImageHeight * ratioY; 
					activeElement_new_width = backgroundImageWidth * ratioY;
				}
				//set the new size
				if(backgroundImage != null)
				{
					backgroundImage.style.width = activeElement_new_width + "px"; 
					backgroundImage.style.height = activeElement_new_height + "px";
					shiftPos = activeElement_new_height - screen_height;
					if(shiftPos > 0)
					{
						backgroundImage.style.top = (shiftPos * 0.5) * -1 + "px";
					}
					document.getElementById("background").style.display = "block";
					document.getElementById("background").style.height = screen_height;
					document.getElementById("background").style.clip = "rect(" + 0 + "px " + activeElement_new_width + "px " + screen_height + "px " + 0 + "px)"
				}
			}
		
			//Footer
			var screen_height; //Set Footer by resize
	 		objFooter = document.getElementById("footer");
			ifMouseUp = false;		 	
	 		
		 	if(objFooter != null)
		 	{
		 		if (/MSIE (\d+\.\d+);/.test(navigator.userAgent))
		 		{ //test for MSIE x.x;
			
		 			var ieversion=new Number(RegExp.$1) // capture x.x portion and store as a number
		 			if (ieversion==6)
		 			{		
		 				screen_width = document.body.clientWidth;
		 				screen_height = document.body.clientHeight;
			    	}
		 			if (ieversion>=7)
		 			{			    	
		 				screen_width = document.body.clientWidth;
		 				screen_height = document.body.clientHeight;
			    	}
		 		}	
		 		else //No
		 		{
		 			screen_width = window.innerWidth;
		 			screen_height = window.innerHeight;
		 		}		
		 		divContainer = document.getElementById("content-overlay");
		 		if(divContainer != null)
		 		{
		 			if(divContainer.clientWidth < divContainer.scrollWidth)
		 			{
		 				if(screen_height < 760)
		 				{
		 					objFooter.style.top= (screen_height + document.getElementById("content-overlay").scrollTop)-36 + "px";
		 					document.getElementById("bottom").style.top = (screen_height + document.getElementById("content-overlay").scrollTop)-161 + "px";		 	
		 				}
		 				else
		 				{
		 					objFooter.style.top= (screen_height + document.getElementById("content-overlay").scrollTop)-20 + "px";
		 					document.getElementById("bottom").style.top = (screen_height + document.getElementById("content-overlay").scrollTop)-145 + "px";		 	
		 				}
		 			}
		 			else
		 			{
		 				objFooter.style.top= (screen_height + document.getElementById("content-overlay").scrollTop)-20 + "px";
		 				document.getElementById("bottom").style.top = (screen_height + document.getElementById("content-overlay").scrollTop)-145 + "px";		 	        
		 			}
		 				
		 			// footer, transmask, flashMask
		 			if (screen_width < document.getElementById("content-overlay").scrollWidth){
		 				document.getElementById("content-overlay").scrollWidth - screen_width;
						document.getElementById("transMask").style.width=document.getElementById("content-overlay").scrollWidth + "px";
						document.getElementById("footer").style.width=document.getElementById("content-overlay").scrollWidth + "px";
		 				document.getElementById("footercontent").style.margin="0px auto 0px 0px";
		 			}else{
						document.getElementById("transMask").style.width=screen_width + "px";
						document.getElementById("footer").style.width=screen_width + "px";
		 				document.getElementById("footercontent").style.margin="0px auto";
		 			}	
		 		}
		 	}
		}
			
		if(document.getElementById("content-overlay") != null)
		{
			ifMouseUp = true;

			document.getElementById("content-overlay").onmouseup = function()
			{
				ifMouseUp = true;
				//objFooter.style.display = "block";
			}

			document.getElementById("content-overlay").onscroll = function()
			{
				var screen_height;
				objFooter = document.getElementById("footer");
				ifMouseUp = false;		 	
	 		
				if(objFooter != null)
				{
					if (/MSIE (\d+\.\d+);/.test(navigator.userAgent))
					{ //test for MSIE x.x;
			
						var ieversion=new Number(RegExp.$1) // capture x.x portion and store as a number
						if (ieversion==6)
						{		
							screen_width = document.body.clientWidth;
							screen_height = document.body.clientHeight;
						}
						if (ieversion>=7)
						{			    	
							screen_width = document.body.clientWidth;
							screen_height = document.body.clientHeight;
						}
					}	
					else //No
					{
						screen_width = window.innerWidth;
						screen_height = window.innerHeight;
			    
					}		
					divContainer = document.getElementById("content-overlay");
					if(divContainer != null)
					{
						if(divContainer.clientWidth < divContainer.scrollWidth)
						{
							if(screen_height < 760)
							{
								objFooter.style.top= (screen_height + document.getElementById("content-overlay").scrollTop)-36 + "px";
								document.getElementById("bottom").style.top = (screen_height + document.getElementById("content-overlay").scrollTop)-161 + "px";
							}
							else
							{
								objFooter.style.top= (screen_height + document.getElementById("content-overlay").scrollTop)-20 + "px";
								document.getElementById("bottom").style.top = (screen_height + document.getElementById("content-overlay").scrollTop)-145 + "px";		 	        
							}
						}
						else
						{
							objFooter.style.top= (screen_height + document.getElementById("content-overlay").scrollTop)-20 + "px";
							document.getElementById("bottom").style.top = (screen_height + document.getElementById("content-overlay").scrollTop)-145 + "px";		 	        
						}
					}
				}
			}
		}
}



	if(objResizeBackgroundImage == null)
	var objResizeBackgroundImage = new ResizeBackgroundImageProportional();

	if (/MSIE (\d+\.\d+);/.test(navigator.userAgent))
	{ //test for MSIE x.x;
		window.onresize = function()
		{
			objResizeBackgroundImage.resizeImage();
		}
	}
	else
	{
		window.onresize = function(event)
		{
			objResizeBackgroundImage.resizeImage();
		}
	}
	
	
	

