var WINDOW_HEIGHT_LOW_CUTOFF = 863;
var WINDOW_HEIGHT_HIGH_CUTOFF = 1500;

var heightRatio = 1.7;
var WIDTH_RATIO = 1.6032;

var FLASH_WIDTH_RATIO = 0.5102;
var FLASH_HEIGHT_RATIO = 0.75;

var FLASH_CONT_TOP_RATIO = 0.001;

// banner is 486 x 60 native
var AD_WIDTH_RATIO = 0.39;
var AD_HEIGHT_RATIO = 0.1282;
var AD_TOP_RATIO = 0.047;
var AD_LEFT_RATIO = 0.296;

// banner is 768 x 150
var ADALT_WIDTH_RATIO = 0.4;
var ADALT_HEIGHT_RATIO = 0.1953;
var ADALT_TOP_RATIO = 0.032;
var ADALT_LEFT_RATIO = 0.213;

var CONTENT_MARGIN_LEFT_RATIO = 0;
var CONTENT_PADDING_TOP_RATIO = 0.0255;

var PRODUCTS_BOARD_WIDTH_RATIO = 0.3643;
var PRODUCTS_BOARD_HEIGHT_RATIO = 0.6617;

var PRODUCTS_WIDTH_RATIO = 0.11095;
var PRODUCTS_HEIGHT_RATIO = 0.262;
var PRODUCTS_LEFT_RATIO = 0.095;
var PRODUCTS_MARGIN_TOP_RATIO = 0.2250;
var PRODUCTS_MARGIN_RIGHT_RATIO = 0.22;
var PRODUCTS_PADDING_RIGHT_RATIO = 0.0172;

var OTHER_WIDTH_RATIO = 0.2;
var OTHER_HEIGHT_RATIO = 0.36;
var OTHER_PADDING_RIGHT = 5;
var OTHER_LEFT_RATIO = 0.23;
var OTHER_TOP_RATIO = 0.004;

// ******* //

var FLASH_WIDTH_RATIO_SHOW = 0.5739;
var FLASH_HEIGHT_RATIO_SHOW = 0.6667;

var FLASH_CONT_TOP_RATIO_SHOW = 0;

// banner is 486 x 60 native
var AD_WIDTH_RATIO_SHOW = 0.36;
var AD_LEFT_RATIO_SHOW = 0.287;


/**
 * METHODS
 */
function getWindowDimensions()
{
  var viewportwidth;
  var viewportheight;
 
  // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
 
  if (typeof window.innerWidth != 'undefined')
  {
    viewportwidth = window.innerWidth;
    viewportheight = window.innerHeight;
  }
  else if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth !== 0)
  {
  // IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
    viewportwidth = document.documentElement.clientWidth;
    viewportheight = document.documentElement.clientHeight;
  } 
  else
  {
    viewportwidth = document.getElementsByTagName('body')[0].clientWidth;
    viewportheight = document.getElementsByTagName('body')[0].clientHeight;
  }
  
  if (viewportheight < WINDOW_HEIGHT_LOW_CUTOFF)
  {
  	heightRatio = 1.7;
  }
  else if ((viewportheight >= WINDOW_HEIGHT_LOW_CUTOFF) && (viewportheight < WINDOW_HEIGHT_HIGH_CUTOFF))
  {
  	heightRatio = (viewportheight - 2410) / -910;
  }
  else
  {
  	heightRatio = 1;
  }
  //alert("height: " + viewportheight + "\nratio: " + heightRatio);
  
  return {width: viewportwidth, height: viewportheight};
} 


function getFlashDimensions()
{
    var dim = getWindowDimensions();
	
	// get the scaled background dimensions
	var bgHeight = dim.height * heightRatio;
	var bgWidth = WIDTH_RATIO * bgHeight;

	// scale the flash container
	var flashWidth = FLASH_WIDTH_RATIO * bgWidth;
	var flashHeight = FLASH_HEIGHT_RATIO * flashWidth;
	
	return {width: flashWidth, height: flashHeight};
}


function getMarqueeDimensions()
{
    var dim = getWindowDimensions();
	
	// get the scaled background dimensions
	var bgHeight = dim.height * heightRatio;
	var bgWidth = WIDTH_RATIO * bgHeight;

	// scale the flash container
	var flashWidth = 0.2695 * bgWidth;
	var flashHeight = 0.5252 * flashWidth;
	
	return {width: flashWidth, height: flashHeight};
}


function resizeContent()
{
	var dim = getWindowDimensions();
	var bg = document.getElementById("background");
	var cont = document.getElementById("container");
	var fla = document.getElementById("flash");
	var flaCont = document.getElementById("flash_container");
	var ad = document.getElementById("adBanner");
	var content = document.getElementById("content");
	var products_board = document.getElementById("products_board");
	var products = document.getElementById("products");
	var other = document.getElementById("other_content");
	var subNav = document.getElementById("sub_navigation");
	
	// scale the background image
	if(bg != null)
	{
		bg.height = dim.height * heightRatio;
		bg.width = WIDTH_RATIO * (dim.height * heightRatio);
	}
	
	//alert("w: " + bg.width + "\nh: " + bg.height);
	
	// scale the main container
	if(cont != null)
	{
		cont.style.marginLeft = (dim.width - bg.width) / 2 + "px";
	}
	
	// scale the flash
	if(fla != null)
	{
		fla.width = FLASH_WIDTH_RATIO * bg.width;
		fla.height = FLASH_HEIGHT_RATIO * fla.width;
	}
	
	// move the flash container
	if(flaCont != null)
	{
		flaCont.width = bg.width;
		flaCont.style.left = ((bg.width - fla.width) / 2) + "px";
		flaCont.style.top = FLASH_CONT_TOP_RATIO * bg.height + "px";
	}
	
	// scale and move the ad banner
	if (ad !== null)
	{
		ad.width = fla.width * AD_WIDTH_RATIO;
		ad.height = ad.width * AD_HEIGHT_RATIO;
		ad.style.top = AD_TOP_RATIO * bg.height + "px";
		ad.style.left = AD_LEFT_RATIO * bg.width + "px";
	}
	
	// scale and position the content container
	if (content !== null)
	{
	content.style.left = CONTENT_MARGIN_LEFT_RATIO * bg.width +"px";
	content.style.top = fla.height + "px";
	content.style.paddingTop = CONTENT_PADDING_TOP_RATIO * bg.height + "px";
	}
	
	//alert("content.left: " + content.style.left);
	
	// scale and position the products board
	if (products_board !== null)
	{
	products_board.style.width = PRODUCTS_BOARD_WIDTH_RATIO * bg.width + "px";
	products_board.style.height = PRODUCTS_BOARD_HEIGHT_RATIO * products_board.style.width + "px";
	}
	
	// scale and position the products
	if (products !== null)
	{
	products.style.width = PRODUCTS_WIDTH_RATIO * bg.width + "px";
	products.style.height = PRODUCTS_HEIGHT_RATIO * bg.height + "px";
	products.style.marginTop = PRODUCTS_MARGIN_TOP_RATIO * (PRODUCTS_HEIGHT_RATIO * bg.height) + "px";
	products.style.left = PRODUCTS_LEFT_RATIO * bg.width + "px";
	products.style.marginRight = PRODUCTS_MARGIN_RIGHT_RATIO * bg.width + "px";
	products.style.paddingRight = PRODUCTS_PADDING_RIGHT_RATIO * bg.width + "px";
	}
	
	// scale and position the other board
	if (other !== null)
	{
	other.style.width = OTHER_WIDTH_RATIO * bg.width + "px";
	other.style.height = OTHER_HEIGHT_RATIO * bg.height + "px";
	other.style.paddingRight = OTHER_PADDING_RIGHT + "px";
	other.style.left = OTHER_LEFT_RATIO * bg.width + "px";
	other.style.top = OTHER_TOP_RATIO * bg.height + "px";
	}
	
	// position the sub nav
	if (subNav !== null)
	{
	subNav.style.top = bg.height - 20 + "px";
	}
}


function getFlashDimensionsShow()
{
	var dim = getWindowDimensions();
	
	// get the scaled background dimensions
	var bgHeight = dim.height * heightRatio;
	var bgWidth = WIDTH_RATIO * (dim.height * heightRatio);

	// scale the flash container
	var flashWidth = FLASH_WIDTH_RATIO_SHOW * bgWidth;
	var flashHeight = FLASH_HEIGHT_RATIO_SHOW * flashWidth;
	
	return {width: flashWidth, height: flashHeight};
}


function resizeContentShow()
{
	var dim = getWindowDimensions();
	var bg = document.getElementById("background");
	var cont = document.getElementById("container");
	var fla = document.getElementById("flash");
	var flaCont = document.getElementById("flash_container");
	var content = document.getElementById("content");
	var products_board = document.getElementById("products_board");
	var products = document.getElementById("products");
	var other = document.getElementById("other_content");
	var ad = document.getElementById("adBanner");
	var adAlt = document.getElementById("adBannerAlt");
	var subNav = document.getElementById("sub_navigation");
		
	// scale the background image
	if(bg != null)
	{
		bg.height = dim.height * heightRatio;
		bg.width = WIDTH_RATIO * (dim.height * heightRatio);
	}
	
	//alert("w: " + bg.width + "\nh: " + bg.height);
	
	// scale the main container
	if(cont != null)
	{
		cont.style.marginLeft = (dim.width - bg.width) / 2 + "px";
	}
	
	//alert("cont.left: " + cont.style.marginLeft);

	// scale the flash
	if(fla != null)
	{
		fla.width = FLASH_WIDTH_RATIO_SHOW * bg.width;
		fla.height = FLASH_HEIGHT_RATIO_SHOW * fla.width;
	}
	
	// scale and position the flash container
	if(flaCont != null)
	{
		flaCont.width = bg.width;
		flaCont.style.left = ((bg.width - fla.width) / 2) +"px";
		flaCont.style.top = (FLASH_CONT_TOP_RATIO_SHOW * bg.height) + "px";
	}
	
	//alert("flaCont.left: " + flaCont.style.left);
	
	// scale and position the content container
	if(content != null)
	{
		content.style.left = CONTENT_MARGIN_LEFT_RATIO * bg.width +"px";
		content.style.top = fla.height + "px";
		content.style.paddingTop = CONTENT_PADDING_TOP_RATIO * bg.height + "px";
	}
	
	//alert("content.left: " + content.style.left);
	
	// scale and position the products board
	if(products_board != null)
	{
		products_board.style.width = PRODUCTS_BOARD_WIDTH_RATIO * bg.width + "px";
		products_board.style.height = PRODUCTS_BOARD_HEIGHT_RATIO * products_board.style.width + "px";
	}
	
	// scale and position the products
	if(products)
	{
		products.style.width = PRODUCTS_WIDTH_RATIO * bg.width + "px";
		products.style.height = PRODUCTS_HEIGHT_RATIO * bg.height + "px";
		products.style.marginTop = PRODUCTS_MARGIN_TOP_RATIO * (PRODUCTS_HEIGHT_RATIO * bg.height) + "px";
		products.style.left = PRODUCTS_LEFT_RATIO * bg.width + "px";
		products.style.marginRight = PRODUCTS_MARGIN_RIGHT_RATIO * bg.width + "px";
		products.style.paddingRight = PRODUCTS_PADDING_RIGHT_RATIO * bg.width + "px";
	}
	
	// scale and position the other board
	if(other)
	{
		other.style.width = OTHER_WIDTH_RATIO * bg.width + "px";
		other.style.height = OTHER_HEIGHT_RATIO * bg.height + "px";
		other.style.paddingRight = OTHER_PADDING_RIGHT + "px";
		other.style.left = OTHER_LEFT_RATIO * bg.width + "px";
		other.style.top = OTHER_TOP_RATIO * bg.height + "px";
	}
	
	//alert("comments.left: " + comments.style.left);
	
	// scale and move the ad banner
	if (ad !== null)
	{
		ad.width = fla.width * AD_WIDTH_RATIO_SHOW;
		ad.height = ad.width * AD_HEIGHT_RATIO;
		ad.style.top = AD_TOP_RATIO * bg.height + "px";
		ad.style.left = AD_LEFT_RATIO_SHOW * bg.width + "px";
	}
	
	if (adAlt !== null)
	{
		adAlt.width = fla.width * ADALT_WIDTH_RATIO;
		adAlt.height = adAlt.width * ADALT_HEIGHT_RATIO;
		adAlt.style.top = ADALT_TOP_RATIO * bg.height + "px";
		adAlt.style.left = ADALT_LEFT_RATIO * bg.width + "px";
	}
	
	// position the sub nav
	if(subNav != null)
	{
		subNav.style.top = bg.height - 20 + "px";
	}
}