var xmlHttp

var ImgNum = 0;
var ImgLength = NewImg.length - 1;
var delay = 5000;
var run;
run = setInterval("chgImg()", delay);

function chgImg() {
	ImgNum = ImgNum + 1;
	if (ImgNum > ImgLength) { ImgNum = 0; }
        FadeInImage('slideshow',NewImg[ImgNum],'designimage');
        document.getElementById('designcaption').innerHTML='<span class="small12" style="text-align: center;"><a href="'+NewLink[ImgNum]+'" class="small12">'+NewCap[ImgNum]+'<a href="'+NewLink[ImgNum]+'"></span>';
}


// Opacity and Fade in script.
// Script copyright (C) 2008 http://www.cryer.co.uk/.
// Script is free to use provided this copyright header is included.
function SetOpacity(object,opacityPct)
{
  // IE.
  object.style.filter = 'alpha(opacity=' + opacityPct + ')';
  // Old mozilla and firefox
  object.style.MozOpacity = opacityPct/100;
  // Everything else.
  object.style.opacity = opacityPct/100;
}
function ChangeOpacity(id,msDuration,msStart,fromO,toO)
{
  var element=document.getElementById(id);
  var opacity = element.style.opacity * 100;
  var msNow = (new Date()).getTime();
  opacity = fromO + (toO - fromO) * (msNow - msStart) / msDuration;
  if (opacity<0) 
    SetOpacity(element,0)
  else if (opacity>100)
    SetOpacity(element,100)
  else
  {
    SetOpacity(element,opacity);
    element.timer = window.setTimeout("ChangeOpacity('" + id + "'," + msDuration + "," + msStart + "," + fromO + "," + toO + ")",1);
  }
}
function FadeIn(id)
{
  var element=document.getElementById(id);
  if (element.timer) window.clearTimeout(element.timer); 
  var startMS = (new Date()).getTime();
  element.timer = window.setTimeout("ChangeOpacity('" + id + "',1000," + startMS + ",0,100)",1);
}
function FadeOut(id)
{
  var element=document.getElementById(id);
  if (element.timer) window.clearTimeout(element.timer); 
  var startMS = (new Date()).getTime();
  element.timer = window.setTimeout("ChangeOpacity('" + id + "',1000," + startMS + ",100,0)",1);
}
function FadeInImage(foregroundID,newImage,backgroundID)
{
  var foreground=document.getElementById(foregroundID);
  if (backgroundID)
  {
    var background=document.getElementById(backgroundID);
    if (background)
    {
      background.style.backgroundImage = 'url(' + foreground.src + ')';
      background.style.backgroundRepeat = 'no-repeat';
    }
  }
  SetOpacity(foreground,0);
  foreground.src = newImage;
  if (foreground.timer) window.clearTimeout(foreground.timer); 
  var startMS = (new Date()).getTime();
  foreground.timer = window.setTimeout("ChangeOpacity('" + foregroundID + "',1000," + startMS + ",0,100)",10);
}

function doSearch() {
	stopChgImg();
	var temp = document.catalog.searchbox.value;
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null) {
		alert ("Browser does not support HTTP Request")
		return
	}
	var url="out.php"
	url=url+"?action=dosearch&searchbox="+temp
	td="itembox"
	xmlHttp.onreadystatechange=function() { stateChanged(td); }
	xmlHttp.open("POST",url,true)
	xmlHttp.send(null)
}

function stateChanged(td) { 
	if (xmlHttp.readyState==2 || xmlHttp.readyState==3 || xmlHttp.readyState==1) { 
		document.getElementById(td).innerHTML=""; 
	} 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") { 
		document.getElementById(td).innerHTML=xmlHttp.responseText
	} 
}

function GetXmlHttpObject() {
	var xmlHttp=null;
	try {
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	catch (e) {
		//Internet Explorer
		try {
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e) {
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return xmlHttp;
}

