var wipeBlock	  = null;
var wipeImg		  = null;
var wipeIdx		  = 0;
var wipeContainer = null;
var wipeTimeout	  = 10000;

function wipe( links, path, alt_tags, size )
{
	// for browsers that don't like image wipes
	var cycle	= Math.floor( Math.random() * links.length );

	// exit wipe if broadband is not available
	var m_wipe	= ( typeof(animate) != "undefined" ? animate : hasBroadband() );
	
	if( m_wipe == false || path.length <= 1 || !( isIE4 || isW3C ) )
	{
		wipePicker( links, path, alt_tags, cycle );
		return;
	}
	
	wipeIdx		= cycle;

	document.write( "<div id=\"container\" style=\"size:" + size +"px;height:360px\">" );

	for( i = 0; i < path.length; i++ )
	{
		document.write( "<div id=\"wipe" + i + "\" style=\"display:none\">" );
		
		wipePicker( links, path, alt_tags, i );

		document.write( "</div>" );
	}

	document.write( "</div>" );

	wipeBlock	= new Array( path.length );
	wipeImg		= new Array( path.length );

	for( i = 0; i < path.length; i++ )
	{
		wipeBlock[i]	= document.getElementById( "wipe" + i ).style;
		wipeImg[i]	= document.getElementById( "wipeImg" + i );
		
		if( wipeImg[i] == null )
		{
			wipePicker( links, path, alt_tags, i );
			return;
		}

	}

	wipeContainer = document.getElementById("container");
	
	wipeEffects();
}

function wipeEffects()
{
	var nextImage	= (wipeIdx + 1) % wipeImg.length;

	if( getIEVer() >= 4.0 )
	{
		wipeContainer.style.filter = "blendTrans(duration=1.5) revealTrans(duration=1.0,transition=7)";
	
		wipeContainer.filters(0).apply();
		wipeContainer.filters(1).apply();
		
 		wipeSelect( nextImage );
		
		wipeContainer.filters(0).play();
		wipeContainer.filters(1).play();
	}
	else
	{
		wipeSelect( nextImage );
	}
	setTimeout( "wipeSwap()", wipeTimeout );
}

function wipeSelect( nextImage )
{
	wipeBlock[wipeIdx].display = "none";
	wipeIdx = nextImage;
	wipeBlock[wipeIdx].display = "block";
}		

function wipeSwap()
{
	if( wipeImg[wipeIdx].complete )
	{
		wipeEffects();
	}
	else
	{
		setTimeout( "wipeSwap()", 3000 );
	}
}

function wipePicker( links, path, alt_tags, cycle )
{
	if( links[cycle] != null ) 
	{
		document.write( "<A HREF=\"" + links[cycle] + "\"><IMG SRC=\"" + path[cycle] + "\" alt=\"" + alt_tags[cycle] + "\" BORDER=\"0\" ID=\"wipeImg" + cycle + "\"></a>" );
	}
	else
	{
		document.write( "<IMG SRC=\"" + path[cycle] + "\" ID=\"wipeImg" + cycle + "\">" );
	}
}

function hasBroadband()
{
	if( getIEVer() < 5.0 )
	{
		return false;
	}
	
	try
	{
		document.body.addBehavior ("#default#clientCaps");
	
		return ( typeof(document.body.connectionType) != "undefined" && document.body.connectionType == "lan" );
	}
	catch( e )
	{
		return false;
	}
}

var isCSS 			= false;
var isW3C 			= false;
var isIE4 			= false;
var isNN4 			= false;
var isIE6 			= false;
var isGecko 		= false;
var isOpera 		= false;
var isDHTML 		= false;
var suppressMenus	= false;
var legacyMode		= false;
var timerID			= null;
var subtimerID		= null;

function browserconfig()
{
    if(document && document.images)
    {
        isCSS		= (document.body && document.body.style) ? true : false;
        isW3C		= (isCSS && document.getElementById) ? true : false;
        isIE4		= (isCSS && document.all && getIEVer() >= 4.0) ? true : false;
        isNN4		= (document.layers) ? true : false;
        isGecko		= (isCSS && navigator && navigator.product && navigator.product == "Gecko");
        isOpera		= (isCSS && navigator.userAgent.indexOf( "Opera") != -1 );
		isIE6CSS	= (document.compatMode && document.compatMode.indexOf("CSS1") >= 0) ? true : false;
		isIE6		= ( isIE6CSS && getIEVer() >= 6.0 );
        isDHTML		= isCSS && ( isIE4 || isGecko || isOpera );
        
        if( suppressMenus || ( isOpera && getOperaVer() < 7 ) || ( isGecko && navigator.productSub <= 20011022 ) || ( isGecko && navigator.productSub == 20030107 ) )
        {
			isDHTML	= false;
        }
        
    }
    
    
}

function getIEVer()
{
	var agent	= navigator.userAgent;
	var offset	= agent.indexOf( "MSIE" );
	if( offset < 0 )
	{
		return 0;
	}
	return parseFloat( agent.substring( offset + 5, agent.indexOf( ";", offset ) ) );
}

function getOperaVer()
{
	var agent	= navigator.userAgent;
	var offset	= agent.indexOf( "Opera" );
	if( offset < 0 )
	{
		return 0;
	}
	return parseFloat( agent.substring( offset + 6 ) );
}
