var product = 0;
var cat = 0;
var obj;
var height = 0;
var productQty;
var element;

var waitlength = 250;		// Length of wait between sky switches
var looptimer = 0;			// Setup main loop timer
var position = -600;
var count = 10;

function getObj(id)
{
	return document.getElementById(id);
}

function getHeight()
{
	obj = getObj('contentBox');
	height = obj.offsetHeight;
	return height;
}

function setHeight()
{
	cat = getObj('categories');
	cat.style.height = getHeight() + 'px';
	return false;
}

function changeQuantity(id,val)
{
	productQty = getObj(id);

	if (val == 1)
	{
		productQty.value++;
	}
	else if (!(productQty.value <= 0))
	{
		productQty.value--;
	}
}

function popProduct(imageName)
{
	var left = (screen.width-220)/2;
	var top = (screen.height-220)/2;

	if (!product.closed && product.location)
	{
		product.location.href = '/popProduct.php?name=' + imageName;
	}
	else
	{
		product=window.open('/popProduct.php?name=' + imageName,'productPopup','resizable=no,width=220,height=220,scrollbars=0,top=' + top + ',left=' + left + '');
		if (!product.opener) product.opener = self;
	}
	if (window.focus)
	{
		product.focus();
	}
}

function getInnerHeight(win) {
  var winHeight;
  if (win.innerHeight) {
    winHeight = win.innerHeight;
  }
  else if (win.document.documentElement && win.document.documentElement.clientHeight) {
    winHeight = win.document.documentElement.clientHeight;
  }
  else if (win.document.body) {
    winHeight = win.document.body.clientHeight;
  }
  return winHeight;
}

function setOuterHeight(browserWin)
{
	var newHeight;
	var header;
	var nav;
	var windowHeight;
	var headerHeight;
	var navHeight;
	var basketHeight;

	windowHeight = getInnerHeight(browserWin) - 17;
	header = getObj('header');
	nav = getObj('navigationOuter');
	//basket = getObj('basket');
	//headerHeight = header.offsetHeight;
	//navHeight = nav.offsetHeight;
	//basketHeight = basket.offsetheight;

	newHeight = windowHeight/* - (headerHeight + navHeight + basketHeight)*/;

	obj = getObj('bottomOuter');
	obj.style.height = newHeight + 'px';
}

function init(page)
{ 
	if (document.getElementById('categories'))
	{
		setHeight();
	}
	setOuterHeight(window);
	if (page == 'furniture')
	{
		window.location.hash="furniture";
		window.scroll(0,0);
	}
}


function mail(first, last)
{
	document.write('<a href="mail' + 'to:' + first + '@' + last + '">' + first + '@' + last + '</a>');
}



function goToTop()
{
	obj = getObj('categories');
	obj.scrollTop = 0;
}


function getInnerWidth(win) {
  var winWidth;
  if (win.innerWidth) {
    winWidth = win.innerWidth;
  }
  else if (win.document.documentElement && win.document.documentElement.clientWidth) {
    winWidth = win.document.documentElement.clientWidth;
  }
  else if (document.body) {
    winWidth = win.document.body.clientWidth;
  }
  return winWidth;
}


function rollover( imgName, imgLocation )
{
	document[imgName].src = imgLocation ;
}

function color(divName,divColor)
{
	document.getElementById(divName).style.backgroundColor = divColor;
}