var preloadFlag = false;
var preloadStack = new Array("preloadImages();","textOnly(false);");
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;
}

//
// Text only mode
//
function TextOnly( flip )
{
	if ( flip )
	{
		textOnlyState = ( GetCookie( "textOnly" ) == 1 ) ? false : true;
	}
	else
	{
		textOnlyState = ( GetCookie( "textOnly" ) == 1 ) ? true : false;
	}

	try
	{
		stylesheets = this.document.styleSheets;

		for( i = 0; i < stylesheets.length; i++ )
		{
			stylesheets[i].disabled = textOnlyState;
		}

		SetCookie( 'textOnly', ( textOnlyState ) ? 1 : 0, 365, '/', '', '' );
		document.getElementById( 'textOnlyLink' ).innerHTML = ( textOnlyState ) ? "Full graphics site" : "Text only";
	}
	catch( e )
	{
	}
}

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 = '#777';
	}
}

// ------------------------------------------------------------
// --- 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" : "" );
}

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 ( GetCookie( name ) )
	{
		document.cookie = name + "=" + ( ( path ) ? ";path=" + path : "") + ( ( domain ) ? ";domain=" + domain : "" ) + ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
	}
}

function InitialiseTabs( tabId, initialTab )
{
	tabs = document.getElementById( tabId ).getElementsByTagName( "LI" );

	for( x=0; x < tabs.length; x++ )
	{
    	if( ( initialTab != "" ) && ( initialTab != x + 1 ) )
    	{
        	document.getElementById( tabId + ( x + 1 ) ).style.display = 'none';
    	}

		tabs[x].getElementsByTagName( "A" )[0].onclick = function()
		{
			tabs = document.getElementById( tabId ).getElementsByTagName( "LI" );

			for( x = 0; x < tabs.length; x++ )
			{
				if( tabs[ x ] == this.parentNode )
				{
					tabs[ x ].className = 'current';
					document.getElementById( tabId + ( x + 1 ) ).style.display = 'block';
				}
				else
				{
					tabs[ x ].className = '';
					document.getElementById( tabId + ( x + 1 ) ).style.display = 'none';
				}
			}

			return false;
		};
	}
}


function ScrollThumbs(containerID)
{
	myScrollThumbsRef = this;
	this.ThumbsScroll = ThumbsScroll;
	this.ThumbsScrollLeft = ThumbsScrollLeft;
	this.ThumbsScrollRight = ThumbsScrollRight;
	this.slider  = document.getElementById( containerID );
	lists = this.slider.getElementsByTagName( "UL" );
	this.thumbnailList = lists[0];
	this.thumbsImageCount = this.thumbnailList.getElementsByTagName("LI").length;
	this.thumbsLeftPos
	this.thumbsImageWidth = 142;
	this.thumbsScrollSpeed = 15;
	this.thumbsScrollWidth = 748;
	this.thumbsScrollIncrement = 17; // this must be a factor of thumbsScrollWidth
	this.thumbsLeftPos = 0;
	this.thumbsTargetLeftPos = 0;
	this.thumbsTimer = 0;

	function ThumbsScrollRight()
	{
		if ( ( this.thumbsLeftPos > -( ( this.thumbsImageWidth * this.thumbsImageCount ) - this.thumbsScrollWidth ) )
			 && ( this.thumbsTimer == 0 ) )
 		{
 			this.thumbsTargetLeftPos = this.thumbsLeftPos - this.thumbsScrollWidth;
			this.thumbsTimer = setTimeout("myScrollThumbsRef.ThumbsScroll()", this.thumbsScrollSpeed);
		}
	}

	function ThumbsScrollLeft()
	{
		if ( ( this.thumbsLeftPos < 0 ) && ( this.thumbsTimer == 0 ) )
		{
	 		this.thumbsTargetLeftPos = this.thumbsLeftPos + this.thumbsScrollWidth;
			this.thumbsTimer = setTimeout("myScrollThumbsRef.ThumbsScroll()",this.thumbsScrollSpeed);
		}
	}

	function ThumbsScroll()
	{
	 	this.thumbsLeftPos = ( this.thumbsLeftPos > this.thumbsTargetLeftPos ) ? this.thumbsLeftPos - this.thumbsScrollIncrement : this.thumbsLeftPos + this.thumbsScrollIncrement;
	 	this.thumbnailList.style.left = this.thumbsLeftPos + "px";

	 	if(this.thumbsLeftPos != this.thumbsTargetLeftPos)
	 	{
			this.thumbsTimer = setTimeout( "myScrollThumbsRef.ThumbsScroll()", this.thumbsScrollSpeed );
		}
		else
		{
			//clear the timer used to test if already moving
			clearTimeout( this.thumbsTimer );
			this.thumbsTimer = 0;
		}
	}
}

function switchTabs( activeTabID )
{
	tabs = $( '#tab-anchors li' );
	tabContents = $( '#panel-content div' );
	for ( x = 0; x < tabs.length; x++ ) 
	{
		if ( tabs[ x ].id == activeTabID )
		{
			tabs[ x ].className = 'tab-on';	
			tabContents[ x ].className = 'active';
		}
		else
		{
			tabs[ x ].className = '';
			tabContents[ x ].className = 'inactive';
		}
	}
	return false;
}




jQuery.fn.gcdTabs = function() 
{
	this.find("li").click( function()
  	{
  		li = jQuery(this);
  		li.parents("ul:first").find("li").removeClass("selected").find("a").each( function()
  		{
  			jQuery(this.hash).removeClass("show").addClass("hide");
		});
  		li.addClass("selected");
  		tabId = li.find("a")[0].hash;
  		jQuery(tabId).addClass("show").removeClass("hide");
  		location.hash = tabId + "-tab";
        return false;
	});
	this.find("li a[href="+ location.hash.substring( 0 , location.hash.length - 4) +"]").click();
	return this;
};