/* JS Document for Chromcraft - Product Swap
   Prepared by:
     Blake Watson
     www.threesquarewebdesign.com
*/

/* The purpose of this script is to feature a random product from a given selection
   and allow the user to cycle through the products in the selection. */
   
NumOfProducts = 9;

function product(title,desc,src)
{
  this.title=title;
  this.desc=desc;
  this.src=src;

  this.changeSrc = changeSrc;
}

function changeSrc(changeSrc)
{
  this.src = changeSrc;
}

products = new Array();
products[0] = new product("Ultima II", "Ultima II offers a full family of seating products from wuest to task seating to management versions. Ultima II encompasses a full range of features, providing fully adjustable, ergonomically correct seating for every office application.", "images/prod-Ultima.jpg");
products[1] = new product("Breton", "Molded Ultrafoam&reg;: Our exclusive, molded, high-resilient, Ultrafoam&reg; is produced in our own facility in Senatobia, MS. It is density controlled for years of superior service and treated with fire retardant chemicals. Ultrafoam&reg; has a limited lifetime warranty when used in a single shift application.", "images/prod-Brenton.jpg");
products[2] = new product("Icon", "ICON is defined as a significant piece of art, artifact, person, place or thing that is held in high regard. The ICON Series will certainly achieve that status. Uniquely shaped urethane over steel arms with angled connection points and aluminum arm receivers located underneath the seat that complement the sculptured cast aluminum back bar.", "images/prod-Icon.jpg");
products[3] = new product("Trak", "Combining high tech design and comfort, Trak achieves the best of all seating. Trak chairs are available in four styles: high-back with a headrest, high-back without a headrest, mid-back task, plus a matching guest chair.", "images/prod-Trak.jpg");
products[4] = new product("Zest", "Chromcraft Zest seating is the next generation of public seating. Zest comes in a scale that allows specifiers to maximize space requirements with multiple frame and table configurations.Zest provides singles, doubles, and triples, center arm versions, along with center support leg and multiple table configurations.", "images/prod-Zest.jpg");
products[5] = new product("Inspire", "Inspire has become an instant inspiration with its striking appearance, updated features and terrific price points..", "images/prod-Inspire.jpg");
products[6] = new product("Zyn", "Zyn awakens the benefits of mindfulness and concentration to the workplace in this new seat ing creation by Gary Bacon and Synergy Product Development.", "images/prod-Zyn.jpg");
products[7] = new product("Facet", "FACET is a multipurpose seating series in every aspect. Facet offers comfortable design features, end user convenience and unlimited possibilities. Facet is everything you could hope for in a multipurpose chair and then some.", "images/prod-Facet.jpg");
products[8] = new product("Genesis", "Genesis is ergonomic in form, style and function. The Genesis Series features high, mid, and low back versions. This popular chair series is available armless or in four types of standard arm packages. Genesis is available in versions ranging from a basic task chair (099) posture mech (085) synchro mech (051) side tension mech (091) along with an asynchronous mech with a seat slider (054) all described on the next page. There is also a Big & Tall version high back chair; this chair comes standard with a heavy duty asynchronous mech (501) or heavy duty asynchronous mech with a seat slider (504) for the Big & Tall chair only..", "images/prod-Genesis.jpg");


opacity = 0;
currentProd = 0;

function pickNumber()
{
  currentProd = Math.floor(Math.random() * (NumOfProducts));
  document.getElementById("front-product").src = products[currentProd].src;
  document.getElementById("swapper-title").innerHTML = products[currentProd].title;
  document.getElementById("swapper-desc").innerHTML = products[currentProd].desc;
}

function transition(direction)
{
  opacity = 100;
  if(direction==0)
  {
    currentProd--;
    if(currentProd<0)
    {
      currentProd = NumOfProducts - 1;
    }
    callFadeOut();
    window.setTimeout('document.getElementById("front-product").src = products[currentProd].src;', 1000);
    window.setTimeout('document.getElementById("swapper-title").innerHTML = products[currentProd].title; document.getElementById("swapper-desc").innerHTML = products[currentProd].desc; callFadeIn();', 1000);
  }
  else if(direction==1)
  {
    currentProd++;
    if(currentProd==NumOfProducts)
    {
      currentProd = 0;
    }
    callFadeOut();
    window.setTimeout('document.getElementById("front-product").src = products[currentProd].src;', 1000);
    window.setTimeout('document.getElementById("swapper-title").innerHTML = products[currentProd].title; document.getElementById("swapper-desc").innerHTML = products[currentProd].desc; callFadeIn();', 1000);
  }
}

function callFadeOut()
{
  timer = window.setInterval("fade(0)", 20);
}

function callFadeIn()
{
  window.setTimeout("timer = window.setInterval('fade(1)', 20)", 800);
}

function fade(direction)
{
  if(direction==0)
  {
    opacity = opacity - 2;
    if(navigator.appName=="Microsoft Internet Explorer")
    {
      document.getElementById("front-product").style["filter"] = "alpha(opacity=" + opacity + ")";
    }
    else
    {
      document.getElementById("front-product").style.MozOpacity = opacity / 100;
    }
    
		if(opacity<1)
		{
			window.clearInterval(timer);
		}
  }
  
  if(direction==1)
  {
    opacity = opacity + 2;
    if(navigator.appName=="Microsoft Internet Explorer")
    {
      document.getElementById("front-product").style["filter"] = "alpha(opacity=" + opacity + ")";
    }
    else
    {
      document.getElementById("front-product").style.MozOpacity = opacity / 100;
    }
    
		if(opacity>99)
		{
			window.clearInterval(timer);
		}
  }
}