// 
// WaveFade v1.01 (Aug 04)
// by Astralys Solutions Pte. Ltd., Copyright 2004
//
// Copyright (c) 2004, all rights reserved
// No part of this script may be copied, modified, used or distributed without
// prior knowledge or approval of the author.
//
// ---------------------------------------------------------------------------

// declare wavefade array
var aryUrls = new Array();
var aryImgs = new Array();
var aryAlts = new Array();
var aryFade;

// common variables
var wf_index	= 0;
var wf_imgs		= null;
var wf_parent	= null;
var wf_child	= null;

function wavefade(urls, imgs, alts, iWidth, iHeight, iWait)
{
	if(imgs.length <= 1 || !IsIENS6)
	{
		wavefade_generate(urls, imgs, alts, Math.floor(Math.random()*imgs.length), iHeight, iWidth);
		return;
	}
	
	// create parent and child DHTML layers
	document.writeln("<div id=\"wf_parent\" style=\"width:"+iWidth+"px;height:"+iHeight+"px\">");
	for (iCount=0; iCount<imgs.length; iCount++)
	{
		document.writeln("\t<div id=\"wf_child"+iCount+"\" style=\"display:none\">");
		wavefade_generate(urls, imgs, alts, iCount, iHeight, iWidth);
		document.writeln("\t</div>");
	}
	document.writeln("</div>");

	// init layers properties
	wf_child = new Array(imgs.length);
	wf_imgs = new Array(imgs.length);
	wf_parent = document.getElementById("wf_parent");
	for (iCount=0; iCount<imgs.length; iCount++)
	{
		wf_child[iCount] = document.getElementById("wf_child"+iCount).style;
		wf_imgs[iCount] = document.getElementById("wf_imgs"+iCount);
	}
	
	// ready to roll
	wavefade_action(iWait);
}

function wavefade_generate(urls, imgs, alts, iCount, iHeight, iWidth)
{
	// generate HTML to display image
	if(urls[iCount] != null) 
		document.writeln("<a href=\""+urls[iCount]+"\"><img src=\""+imgs[iCount]+"\" alt=\""+alts[iCount]+"\" border=\"0\" width=\""+iWidth+"\" height=\""+iHeight+"\" id=\"wf_imgs"+iCount+"\"></a>");
	else
		document.writeln("<img src=\""+imgs[iCount]+"\" border=\"0\" width=\""+iWidth+"\" height=\""+iHeight+"\" id=\"wf_imgs"+iCount+"\">");
}

function wavefade_swap(wf_nextpic)
{
	// swap cur pic with next pic
	wf_child[wf_index].display = "none";
	wf_index = wf_nextpic;
	wf_child[wf_index].display = "block";
}		

function wavefade_showpic(iWait)
{
	// if pic fully load, show it, else, wait awhile
	if (wf_imgs[wf_index].complete)
		wavefade_action(iWait);
	else
		setTimeout("wavefade_showpic()", 1000);
}

function wavefade_action(iWait)
{
	var iNext = (wf_index+1)%wf_imgs.length;
//	var iFade = Math.floor(Math.random()*aryFade.length);
	var iFade = aryFade[wf_index];
	
	// apply IE filters
	if (IsIE4)
	{
		wf_parent.style.filter = "blendTrans(duration=1.5) revealTrans(duration=1.5,transition="+iFade+")";
		wf_parent.filters(0).apply(); wf_parent.filters(1).apply();
 		wavefade_swap(iNext);
		wf_parent.filters(0).play(); wf_parent.filters(1).play();
	}
	else
		wavefade_swap(iNext);

	setTimeout("wavefade_showpic("+iWait+")", iWait);
}
