window.onload = init

function init()
{ setRollovers()
}





/*

after the html page loads, setRollovers() scans the HTML page for any img tag 
that has the class "rollOver". When it finds one, it attaches the mouseover events.

*/

function setRollovers()
{ imgs = document.getElementsByTagName("img")
  for (i=0;i<imgs.length;i++)
  { if (/rollOver/.test(imgs[i].className))
    { imgs[i].parentNode.onmouseover=function(){roll(this,true);}
      imgs[i].parentNode.onmouseout=function(){roll(this,false);}
      imgs[i].parentNode.onfocus=function(){roll(this,true);}
      imgs[i].parentNode.onblur=function(){roll(this,false);}
    }
  }
}





/*

roll() handles the image rollovers.

*/

function roll(node,status)
{	nodeImg = node.firstChild
	srcImage = nodeImg.getAttribute("src")
	
	if (status)
	{	navState = srcImage.substring(srcImage.length - 7,srcImage.length - 4)
		if (navState == "off")
		{	srcImage = srcImage.substring(0,srcImage.length - 7)
			srcImage = srcImage + "on.gif"
			nodeImg.setAttribute("src",srcImage)
		}
	}
	else
	{	navState = srcImage.substring(srcImage.length - 7,srcImage.length - 4)
		if ((navState != "sel") && (navState != "off"))
		{	srcImage = srcImage.substring(0,srcImage.length - 6)
			srcImage = srcImage + "off.gif"
			nodeImg.setAttribute("src",srcImage)
		}
	}
}





/*

swatchClick() handles the actions when a swatch is clicked in the 
Purchase Fabrics and Create a Sample Kit pages.

Note 'swatchRoot' variabe below -- this identifies the folder where
the larger swatches can be found.

*/

function swatchClick(node,name,image,sale,description)
{ document.getElementById("swatchName").innerHTML = name
  document.getElementById("swatchSale").innerHTML = sale
  
  if (document.getElementById("getSampleKit"))
  { document.getElementById("getSampleKit").style.display = "block"
  }
  
  if (document.getElementById("swatchDescriptionDefault"))
  { document.getElementById("swatchDescriptionDefault").style.display = "none"
  }
  
  document.getElementById("swatchDescription0").style.display = "none"
  document.getElementById("swatchDescription1").style.display = "none"
  document.getElementById("swatchDescription2").style.display = "none"
  document.getElementById("swatchDescription3").style.display = "none"
  document.getElementById("swatchDescription4").style.display = "none"
  document.getElementById("swatchDescription5").style.display = "none"
  document.getElementById("swatchDescription" + description).style.display = "block"
  
  document.getElementById("swatchName").style.display = "block"
  document.getElementById("swatchInfo").style.display = "block"
  
  if (document.getElementById("addedToCart"))
  { document.getElementById("addedToCart").style.display = "none"
  }
  
  imgs = document.getElementById("swatchTable").getElementsByTagName("img")
  for (i=0;i<imgs.length;i++)
  { src = imgs[i].getAttribute("src")
    if (!/icon/.test(src))
    { imgs[i].parentNode.className = ""
    }
  }
  
  node.className = "selected"
  
  swatchRoot = "images/swatches/medium/"
  swatchImg = swatchRoot + image
  document.getElementById("swatchClicked").setAttribute("src",swatchImg)
}




/*

roll() handles the image rollovers.

*/

function replaceName(which)
{ if (which == '')
  { document.getElementById("thumbName").innerHTML = selectedThumb
  }
  else
  { document.getElementById("thumbName").innerHTML = which
  }
}





/*

launches pop-up window for Enlarge Image, More Images, and Swatches

*/

function popUp(file)
{ width = 585
  height = 515
  
  x = (screen.availWidth - width) / 2 
  y = ((screen.availHeight - height) / 2 ) - 40
  attribs = "width=" + width + ",height=" + height + ",left=" + x + ",top=" + y + ",scrollbars"
  win = window.open(file,"popWindow",attribs)
}





/*

image swap routine for consumer landing page

*/

function homeSwap(node,which)
{ if (which > 0)
  { roll(node,true)
  }
  else
  { roll(node,false)
  }
  
  srcImg = document.getElementById("homeImg").getAttribute("src")
  jpg = srcImg.lastIndexOf(".jpg")
  srcImg = srcImg.substring(0,jpg - 7)
  srcImg = srcImg + "option" + which + ".jpg"
  document.getElementById("homeImg").setAttribute("src",srcImg)
}





/*

show distributor detail information on click

*/

function showDistributor(file)
{ node = document.getElementById("detailInfoFrame")
  node.setAttribute("src",file)
}





/*

move ads on rollover

*/

function movePic()
{ if (direction == 0)
  { return
  }

  oldPos = parseInt(document.getElementById("thumbs").style.left)
  
  if ((oldPos == 0) && (direction > 0))
  { return
  }
  
  if ((oldPos == -4380) && (direction < 0))
  { return
  }
  
  oldPos = oldPos + direction
  document.getElementById("thumbs").style.left = oldPos + "px"
}

function moveAdsLeft(status)
{ if (status)
  { direction = increment
  }
  else
  { direction = 0
  }
}

function moveAdsRight(status)
{ if (status)
  { direction = -increment
  }
  else
  { direction = 0
  }
}





/*

launches pop-up window for About Crypton Ads

*/

var currentAd = ""
var bigWidth = 0

function popAd(which,node)
{ imgNode = node.firstChild
  imgWidth = imgNode.getAttribute("width")
  
  currentAd = which
  width = Math.floor((381/171) * imgWidth) + 60
  
  height = 560
  file = "08_05a_about_ads_detail.htm"
  
  x = (screen.availWidth - width) / 2 
  y = ((screen.availHeight - height) / 2 ) - 40
  attribs = "width=" + width + ",height=" + height + ",left=" + x + ",top=" + y + ",scrollbars=no"
  win = window.open(file,"popWindow",attribs)
}





/*

launches pop-up window for Glosary

*/

function glossary()
{ width = 620
  height = 560
  file = "07_00_trade_glossary.htm"
  
  x = (screen.availWidth - width) / 2 
  y = ((screen.availHeight - height) / 2 ) - 40
  attribs = "width=" + width + ",height=" + height + ",left=" + x + ",top=" + y + ",scrollbars"
  win = window.open(file,"popWindow",attribs)
}





/*

launches pop-up window for Glosary

*/

function petBeds()
{ width = 780
  height = 650
  file = "05_00b_forpets_flash.htm"
  
  x = (screen.availWidth - width) / 2 
  y = ((screen.availHeight - height) / 2 ) - 20
  attribs = "width=" + width + ",height=" + height + ",left=" + x + ",top=" + y + ",scrollbars=no"
  win = window.open(file,"popWindow",attribs)
}





