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='#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";
}

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 ShowMap()
{

  if ( GBrowserIsCompatible() && presetLat != 0 && presetLong != 0 )
  {

    map = new GMap2( document.getElementById( "myMap" ) );
    latlng = new GLatLng( presetLat, presetLong )
    map.setCenter( latlng, presetZoom );
    map.addControl(new GSmallMapControl());
    map.addControl(new GMapTypeControl());
    houseIcon = new GIcon();
    houseIcon.iconAnchor = new GPoint(16, 16);
    houseIcon.image = '/images/favicon.png';
    map.addOverlay( new GMarker(latlng,houseIcon) );
  }
  else
  {
  	document.getElementById( "myMap" ).style.display = 'none';
  }
}