currIndex=0;

function FP_swapImg() {//v1.0
 var doc=document,args=arguments,elm,n; doc.$imgSwaps=new Array(); for(n=2; n<args.length;
 n+=2) { elm=FP_getObjectByID(args[n]); if(elm) { doc.$imgSwaps[doc.$imgSwaps.length]=elm;
 elm.$src=elm.src; elm.src=args[n+1]; } }
}
function FP_getObjectByID(id,o) {//v1.0
 var c,el,els,f,m,n; if(!o)o=document; if(o.getElementById) el=o.getElementById(id);
 else if(o.layers) c=o.layers; else if(o.all) el=o.all[id]; if(el) return el;
 if(o.id==id || o.name==id) return o; if(o.childNodes) c=o.childNodes; if(c)
 for(n=0; n<c.length; n++) { el=FP_getObjectByID(id,c[n]); if(el) return el; }
 f=o.forms; if(f) for(n=0; n<f.length; n++) { els=f[n].elements;
 for(m=0; m<els.length; m++){ el=FP_getObjectByID(id,els[n]); if(el) return el; } }
 return null;
}

function GetWidthforPic()
{
	if (parseInt(navigator.appVersion)>3) 
	{
		if (navigator.appName=="Netscape") 
		{
			winW = window.innerWidth-16;
		}
		if (navigator.appName.indexOf("Microsoft")!=-1) 
		{
			winW = document.body.offsetWidth-20;
		}
	}
	
	if (document.getElementById('userTable'))
	{
		tableWidth = document.getElementById('userTable').width;
	}
	else
	{
		tableWidth = winW;
	}
	return winW;	
}

function createZoomHref(id, pName)
{
	zoomWidth = GetWidthforPic();
	document.getElementById(id).href = "?p=zoomPict&pic=" + pName+ "&fWidth=" + zoomWidth;
}

// Call this function to update a href for zoom url passing the image name and the screen dimensions
function mouseOverThumb(id, pName)
{
	if (pName=="")
	{
		pName = document.getElementById(id).src;
	}
	createZoomHref(id, pName);
}

// If the screen size if atleast 1024*768 then return true
function isScreenSizeGoodEnough()
{
	if (screen.width >= 1024 && screen.length >= 768)
	{
		return 1
	}
	return 0
}

function changePhotoF(fileName)
{
	document.getElementById("Photo").src = imageSourceL + fileName
}

// Used for the floorPlan map
function changePhoto(fileIndex)
{
/*	if (document.all) 
	{
		document.getElementById("Photo").style.filter="blendTrans(duration=1)"
		document.getElementById("Photo").filters.blendTrans.Apply()
	}

//	document.getElementById("Photo").src = preLoad[fileIndex].src
*/	document.getElementById("Photo").src = imageSourceL + Pic[fileIndex]

/*	if (document.all) 
	{
		document.getElementById("Photo").filters.blendTrans.Play()
	}*/
}

// This function is used by index.php and pict.htm
function displaySlideShow()
{
	var picNum = new Array();
	for(var currIndex=0; currIndex<numPhotos; currIndex++)
	{
		picNum[currIndex] = Math.floor(Math.random()*totalNumPicsInArray);
		for(var i=0; i<numPhotos; i++)
		{
			if (i!=currIndex)
			{
				// hopefully one check should do, should really be interative
				if (picNum[currIndex]==picNum[i])
				{
					picNum[currIndex]=Math.floor(Math.random()*totalNumPicsInArray);
				}				
			}
		}		
	}	
	
	for(var currIndex=0; currIndex<numPhotos; currIndex++)
//	if (currIndex<numPhotos)
	{
		var loadPic = picNum[currIndex]
		var cornerElementhrefName = "Photohref" + currIndex
		var cornerElementTextName = "PT" + currIndex
		var imageName = "Photo" + currIndex
		var imageFileName
		
		if (document.all) 
		{
			document.getElementById(imageName).style.filter="blendTrans(duration=1)"
			document.getElementById(imageName).filters.blendTrans.Apply()
		}
	
//		document.getElementById(imageName).src = preLoad[loadPic].src
		imageFileName = imageSourceL + Pic[loadPic]
		document.getElementById(imageName).src = imageFileName 
			
		// if there's a href associated with the img, then update that reference also
		if (document.getElementById(cornerElementhrefName).href)
		{
			zoomName = new String(imageFileName);
/*			zoomName = zoomName.replace(/\s\(thumb\)/g,"");
			// remove the extension as the table is not interersted in it
			zoomName = zoomName.replace(/.jpg/g,"");
			// remove the path ast the table is not interested in it
			zoomName = zoomName.substring(zoomName.lastIndexOf("/")+1, zoomName.length);*/

			// if the PicName array is available then use it
			zoomName = PicName[loadPic];
						
			createZoomHref(cornerElementhrefName, zoomName);
						
			document.getElementById(cornerElementhrefName).title = PicQuote[loadPic];
			document.getElementById(cornerElementhrefName).alt = PicQuote[loadPic];
			if (document.getElementById(cornerElementTextName))
			{
				document.getElementById(cornerElementTextName).innerHTML = PicQuote[loadPic];
			}
		}
		
		if (document.all) 
		{
			document.getElementById(imageName).filters.blendTrans.Play()
		}
		
//		currIndex++
//		displaySlideShow()
	}
//	else
	{
		// ok we've updated alll the images, now chill for a while
		currIndex=0
		setTimeout('displaySlideShow()', slideShowSpeed)
	}
}

function displaySlideShowArgs()
{
	var a=arguments
	
	if (currIndex<numPhotos)
	{
		var loadPic = Math.round(Math.random()*totalNumPicsInArray)
		
		if (document.all) 
		{
			document.getElementById("Photo"+currIndex).style.filter="blendTrans(duration=1)"
			document.getElementById("Photo"+currIndex).filters.blendTrans.Apply()
		}
	
		document.getElementById("Photo"+currIndex).src = preLoad[loadPic].src
	
		if (document.all) 
		{
			document.getElementById("Photo"+currIndex).filters.blendTrans.Play()
		}
		
		currIndex++
		displaySlideShow()
	}
	else
	{
		// ok we've updated alll the images, now chill for a while
		currIndex=0
		setTimeout('displaySlideShow()', slideShowSpeed)
	}
}

function cycleMenuColour()
{
	var col = Math.round(Math.random() * 0xffffff);
	var i;
	
	if (document.getElementById("mItem"+i)) 
	{
		for(i=0; i<mItem.length; i++)
		{
			document.getElementById("mItem"+i).color = "#123456"
		}
	}	
	setTimeout('cycleMenuColour()', 10)
}

// iterate over all the pics adding the witdh to the url of the zoom script call
function updateZoomWithWidth()
{
	var picIndex=0;
	
    if (navigator.appName == 'Netscape' && document.layers != null) 
    {
        wid = window.innerWidth;
        hit = window.innerHeight;
    }
    if (document.all != null)
    {
        wid = document.body.clientWidth;
        hit = document.body.clientHeight;
    }
    
/*	while(document.getElementById("pZUrl"+picIndex))
	{
		document.getElementById("pZUrl"+picIndex).href += "&width="wid;
		picIndex++;
	}
	document.write(picIndex);
*/	
}

/*************************
 code to help rotation with visible/hide & timers
 
 
 <html>
<head>
<script>

function waitAndHide(id) {
  timer = window.setTimeout("hideDiv('"+id+"')", 250);
}

function hideDiv(element) {
	var el = document.getElementById(element);
	el.style.visibility = "hidden";
}
</script>
<style>
#myDiv {visibility: visible;}
</style>
</head>

<body>
<div id="myDiv" onmouseout="waitAndHide(this.id)">Some stuff</div>
</body>
</html>
 
 
 */
 
function updateFloorPlanMouseOvers(idName)
{
	if (document.getElementById)
		var x = document.getElementById(idName).getElementsByTagName('a');
	else if (document.all)
		var x = document.all[idName].all.tags('a');
	else return;
	
//	document.getElementById('Photo').src=Pic[x[1].id];
//	document.write(x.length+':');
	
	for (var i=0;i<x.length;i++)
	{
//		document.write(x[i].id+',');
/*		preloads['o'+x[i].id] = new Image;
		preloads['o'+x[i].id].src = 'pix/'+ x[i].id + '_omo.jpg';
		preloads['o'+x[i].id].onerror = function () {this.src='pix/default.gif'}*/
		x[i].onmouseover = function(){document.getElementById('Photo0').src=Pic[this.id];};
//		x[i].onmouseout = function () {this.src=preloads['n'+this.id].src;}
//		createZoomHref(x[i].id,PicName[x[i].id]);
	}
}

function getCookie(c_name)
{
	if (document.cookie.length>0)
	  {
	  c_start=document.cookie.indexOf(c_name + "=")
	  if (c_start!=-1)
	    { 
	    c_start=c_start + c_name.length+1 
	    c_end=document.cookie.indexOf(";",c_start)
	    if (c_end==-1) c_end=document.cookie.length
	    return unescape(document.cookie.substring(c_start,c_end))
	    } 
	  }
	return null
}

function setCookie(c_name,value,expiredays)
{
	var exdate=new Date()
	exdate.setTime(exdate.getTime()+(expiredays*24*3600*1000))
	document.cookie=c_name+ "=" +escape(value)
					+((expiredays==null) ? "" : "; expires="+exdate)
					+"; path=/"
}

function setStyleCookie(styleValue)
{
	// set the cookie for 6 weeks
	setCookie("theme", styleValue, 6*7);
}