// JavaScript Document

// Sets initial effects settings
var showContent = new Spry.Effect.Slide("productsmenuwrap", {from: "0%", to: "100%", duration: "750"});
var hideContent = new Spry.Effect.Slide("productsmenuwrap", {from: "100%", to: "0%", duration: "750"});

// Says products menu is initially hidden
productshidden="yes";

// Starts function for rollover menu
function products(state) {
	
	if (state=="over") {
		// Checks if menu is already OPEN and does nothing (cancels timer)
		if (window.productCloseTimeout) {
			clearTimeout(productCloseTimeout);
		}
		// If menu is already hidden, starts effect
		if (productshidden=="yes") {
			productOpenTimeout=window.setTimeout('showContent.start();productshidden="no";',150);
		}
	}
	
	// Starts timer for reverse effect on mouseout
	if (state=="out") {
		// Checks if menu is already CLOSED and does nothing (cancels timer)
		if (window.productOpenTimeout) {
			clearTimeout(productOpenTimeout);
		}
		// If menu is OPEN, starts effect
		if (productshidden=="no") {
			productCloseTimeout=window.setTimeout('hideContent.start();productshidden="yes";',750);
		}
	}
}

// OVERLAY
function getViewportSize()
{
 var size = [0, 0];

 if (typeof window.innerWidth != 'undefined')
 {
   size = [
       window.innerWidth,
       window.innerHeight
   ];
 }
 else if (typeof document.documentElement != 'undefined'
     && typeof document.documentElement.clientWidth !=
     'undefined' && document.documentElement.clientWidth != 0)
 {
   size = [
       document.documentElement.clientWidth,
       document.documentElement.clientHeight
   ];
 }
 else
 {
   size = [
       document.getElementsByTagName('body')[0].clientWidth,
       document.getElementsByTagName('body')[0].clientHeight
   ];
 }

 return size;
}

function overlay(state) {
	var size = getViewportSize();
	var blackoverlay = document.getElementById('black_overlay').style;
	
	if (state=="in") {
		blackoverlay.width=(size[0]+"px");
		blackoverlay.height=(size[1]+"px");
		var overlayfadein = new Spry.Effect.Fade('black_overlay', {duration: 500, from: 0, to: 80, toggle:true});
		overlayfadein.start()
	}
	if (state=="out") {
		var overlayfadeout = new Spry.Effect.Fade('black_overlay', {duration: 1000, from: 80, to: 0, toggle:true});
		overlayfadeout.start()
		setTimeout("document.getElementById('black_overlay').style.display='none';",500);
	}
}

// LOGIN BOX
function openlogin() {
	overlay("in");
	setTimeout("var loginboxfadein = new Spry.Effect.Fade('loginbox', {duration: 1000, from: 0, to: 100, toggle:true});loginboxfadein.start();",500);
}
function closelogin() {
	var loginboxfadeout = new Spry.Effect.Fade('loginbox', {duration: 500, from: 100, to: 0, toggle:true});
	loginboxfadeout.start()
	setTimeout("document.getElementById('loginbox').style.display='none';",500);
	setTimeout('overlay("out");',500);
}

// SEARCH BOX
function opensearch(producttype,pname) {
	loadXMLDoc("../search/",("?producttype="+producttype+"&pname="+pname));
	var searchresultboxfadein = new Spry.Effect.Fade('searchresultbox', {duration: 1000, from: 0, to: 100, toggle:true});
	searchresultboxfadein.start();
	overlay("in");
}
function closesearch() {
	var searchresultboxfadeout = new Spry.Effect.Fade('searchresultbox', {duration: 500, from: 100, to: 0, toggle:true});
	searchresultboxfadeout.start()
	setTimeout("document.getElementById('searchresultbox').style.display='none';",500);
	overlay("out");
}

var xmlhttp;

function loadXMLDoc(url,parameters)
{
xmlhttp=null;
// code for Mozilla, etc.
if (window.XMLHttpRequest)
  {
  xmlhttp=new XMLHttpRequest();
  }
// code for IE
else if (window.ActiveXObject)
  {
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
if (xmlhttp!=null)
  {
  xmlhttp.onreadystatechange=state_Change;
  xmlhttp.open("GET",url+parameters,true);
  xmlhttp.send(null);
  }
else
  {
  alert("Your browser does not support XMLHTTP.");
  }
}

function state_Change()
{
// if xmlhttp shows "loaded"
if (xmlhttp.readyState==4)
  {
  // if "OK"
  if (xmlhttp.status==200)
    {
    document.getElementById('searchresultboxcontent').innerHTML=xmlhttp.responseText;
	setTimeout(stripe,500);
    }
  else
    {
    alert("Problem retrieving XML data");
    }
  }
}