// JavaScript Document

var arrImages = Array( 
	"http://img.geminigroup.net/images/template/Corporate.jpg",
	"http://img.geminigroup.net/images/homepage/valley.jpg", // Valley
	"http://img.geminigroup.net/images/homepage/Blow_Mold.jpg", // Regency
	"http://img.geminigroup.net/images/homepage/Extrusion.jpg", // Gemini
	"http://img.geminigroup.net/images/homepage/Injection_Mold.jpg", // TPM
	"http://img.geminigroup.net/images/homepage/Production_Machining.jpg", // Axly 
	"http://img.geminigroup.net/images/homepage/Briney.jpg", // Briney
	"http://img.geminigroup.net/images/homepage/Precision_Machining.jpg", // CKS
	"http://img.geminigroup.net/images/homepage/Thumbtool.jpg", // TTE
	"http://img.geminigroup.net/images/homepage/TextCaption.jpg",
	"http://img.geminigroup.net/images/homepage/AboutUs.jpg"
);
var arrImageObjs = Array();
var imgCenter;
var intLastTimer;

function FadeIn(intImgIndex)
{
	(intLastTimer > 0 ) ? ClearTimer() : intLastTimer = 0;
	SetOpacity(imgCenter,0);
	imgCenter.src = arrImages[intImgIndex];
	intLastTimer = window.setTimeout("ChangeOpacity('" + imgCenter.id + "',300," + (new Date()).getTime() + ",0,100)", 5);
}

function FadeOut()
{
	(intLastTimer > 0) ? ClearTimer() : intLastTimer = 0;
	intLastTimer = window.setTimeout("ChangeOpacity('" + imgCenter.id + "',300," + (new Date()).getTime() + ",100,0)", 5);
}

function ClearTimer()
{
	window.clearTimeout(intLastTimer);
	intLastTimer = 0;
}

// Opacity and Fade in script.
function SetOpacity(obj, opacity)
{  
  opacity = (opacity == 100)?99.999:opacity;
  
  // IE/Win
  obj.style.filter = "alpha(opacity:"+opacity+")";
  
  // Safari<1.2, Konqueror
  obj.style.KHTMLOpacity = opacity/100;
  
  // Older Mozilla and Firefox
  obj.style.MozOpacity = opacity/100;
  
  // Safari 1.2, newer Firefox and Mozilla, CSS3
  obj.style.opacity = opacity/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);
	intLastTimer = window.setTimeout("ChangeOpacity('" + id + "'," + msDuration + "," + msStart + "," + fromO + "," + toO + ")", 1);
  }
}

function PreloadImages()
{
	var i = 0;  
	for (i in arrImages)
	{
		arrImageObjs[i] = new Image();
		arrImageObjs[i].src = arrImages[i];
	}
/*	arrImageObjs = null;*/
}