var preloadFlag = false;
var preloadStack = new Array("preloadImages();");
var pgPreloadImage = new Array();

function newImage(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}

function changeImages() {
	if (document.images && (preloadFlag == true)) {
		for (var i=0; i<changeImages.arguments.length; i+=2) {
			document.getElementById(changeImages.arguments[i]).src = changeImages.arguments[i+1];
		}
	}
}

function preloader()
{
	for(j=0; j < preloadStack.length; j++)
	{
		eval(preloadStack[j]);
	}
}

function preloadImages() {
	if (document.images) {
		for(x=0;x<pgPreloadImage.length;x++){
			eval("pgPreloadImage"+x+"=newImage('"+pgPreloadImage[x]+"');");
		}
		preloadFlag = true;
	}
}

function preloadImage(imageUrl)
{
	pgPreloadImage[pgPreloadImage.length] = imageUrl;
}

function addToOnload(js)
{
	preloadStack[preloadStack.length] = js;
}






function textboxFocus(obj,defaultVal)
{
	if(obj.value==defaultVal)
	{
		obj.value='';
		obj.style.color='#000';
	}
}

function textboxBlur(obj,defaultVal)
{
	if(obj.value=='')
	{
		obj.value=defaultVal;
		obj.style.color='#999';
	}
}

//
// Cookie Handling functions
//

function setCookie( name, value, expires, path, domain, secure )
{
	// set time, it's in milliseconds
	var today = new Date();
	today.setTime( today.getTime() );

	/*
	if the expires variable is set, make the correct
	expires time, the current script below will set
	it for x number of days, to make it for hours,
	delete * 24, for minutes, delete * 60 * 24
	*/
	if ( expires )
	{
		expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );

	document.cookie = name + "=" +escape( value ) +
		( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
		( ( path ) ? ";path=" + path : "" ) +
		( ( domain ) ? ";domain=" + domain : "" ) +
		( ( secure ) ? ";secure" : "" );
}

// this function gets the cookie, if it exists
function getCookie( name ) {
	var start = document.cookie.indexOf( name + "=" );
	var len = start + name.length + 1;
	if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) )
	{
		return null;
	}
	if ( start == -1 ) return null;
	var end = document.cookie.indexOf( ";", len );
	if ( end == -1 ) end = document.cookie.length;
	return unescape( document.cookie.substring( len, end ) );
}

function deleteCookie( name, path, domain ) {
	if ( Get_Cookie( name ) )
		document.cookie = name + "=" + ( ( path ) ? ";path=" + path : "") + ( ( domain ) ? ";domain=" + domain : "" ) + ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}

//
// Functions for handling banner rotation.
//

// Set slideshowSpeed (milliseconds)
var slideshowSpeed = 5000;
// Duration of blendTrans (seconds)
var blendDuration = 1.5;
// Duration of revealTrans (seconds)
var revealDuration = 1;
// reveal Transition style
var revealTransition = 7;
// global variable for timer
var slideshowTimer;
var slideCursor = 0;
var container;

var overSlide = false;

function goSlideshow()
{
	if (overSlide == false && slideCount >1)
	{
		if (document.all)
		{
		  container = document.getElementById('mainBannerContainer');
		  container.style.filter="blendTrans(duration=crossFadeDuration) revealTrans(duration="+revealDuration+",transition="+revealTransition+")";
		  container.filters(0).Apply();
		  container.filters(1).Apply();
		}
		// Increment the cursor to the next appropriate slide
		nextSlide = slideCursor + 1;
		if (nextSlide > (slideCount-1)) nextSlide=0;

		// Hide the current slide
		document.getElementById('slide'+slideCursor).style.display = 'none';
		// Show the next slide
		document.getElementById('slide'+nextSlide).style.display = 'block';

		slideCursor = nextSlide;
		if (document.all)
		{
		  container.filters(0).Play();
		  container.filters(1).Play();
		}

	}
	slideshowTimer = setTimeout('goSlideshow()', slideshowSpeed);
}

// Toggle layer visibility
function ToggleLayer( whichLayer )
{

  var elem, vis;

  if( document.getElementById ) // this is the way the standards work
  {
    elem = document.getElementById( whichLayer );
  }
  else if( document.all ) // this is the way old msie versions work
  {
      elem = document.all[whichLayer];
  }
  else if( document.layers ) // this is the way nn4 works
  {
    elem = document.layers[whichLayer];
  }

  vis = elem.style;

  // if the style.display value is blank we try to figure it out here
  if(vis.display==''&&elem.offsetWidth!=undefined&&elem.offsetHeight!=undefined)
  {
    vis.display = (elem.offsetWidth!=0&&elem.offsetHeight!=0)?'block':'none';
  }

  vis.display = (vis.display==''||vis.display=='block')?'none':'block';
}