document.write('<div class=dloadingBar id=loadingBar name=loadingBar>\n<center><p class=ploadingBar>Loading Photo Albums...</p><img src="content/loading.gif"></center>\n</div>');
document.write("<div class=darkenScreenObject id='darkenScreenObject' name='darkenScreenObject' style='position:absolute; top:0px; left:0px; overflow: hidden; display: none; width:100%; height:100%; z-index:98'></div>");


var myLocation;

function grayOut(vis, options) {
  // Pass true to gray out screen, false to ungray
  // options are optional.  This is a JSON object with the following (optional) properties
  // opacity:0-100         // Lower number = less grayout higher = more of a blackout
  // zindex: #             // HTML elements with a higher zindex appear on top of the gray out
  // bgcolor: (#xxxxxx)    // Standard RGB Hex color code
  // grayOut(true, {'zindex':'50', 'bgcolor':'#0000FF', 'opacity':'70'});
  // Because options is JSON opacity/zindex/bgcolor are all optional and can appear
  // in any order.  Pass only the properties you need to set.
  var options = options || {};
  var zindex = options.zindex || 50;
  var opacity = options.opacity || 75;
  var opaque = (opacity / 100);
  var bgcolor = options.bgcolor || '#000000';
  var dark=document.getElementById('darkenScreenObject');
  if (!dark) {
    // The dark layer doesn't exist, it's never been created.  So we'll
    // create it here and apply some basic styles.
    // If you are getting errors in IE see: http://support.microsoft.com/default.aspx/kb/927917
    var tbody = document.getElementsByTagName("body")[0];
    var dark = document.createElement('div');           // Create the layer.
        dark.style.position='absolute';                 // Position absolutely

        dark.style.overflow='hidden';                   // Try to avoid making scroll bars
        dark.style.display='none';                      // Start out Hidden
        dark.id='darkenScreenObject';                   // Name it so we can find it later
        dark.name='darkenScreenObject';
    tbody.appendChild(dark);                            // Add it to the web page
    dark=document.getElementById('darkenScreenObject');  // Get the object.
  }
  var loadingBar=document.getElementById('loadingBar');
  if (vis) {
    // Calculate the page width and height
    if( document.body && ( document.body.scrollWidth || document.body.scrollHeight ) ) {
        var pageWidth = document.body.scrollWidth+'px';
        var pageHeight = document.body.scrollHeight+'px';
    } else if( document.body.offsetWidth ) {
      var pageWidth = document.body.offsetWidth+'px';
      var pageHeight = document.body.offsetHeight+'px';
    } else {
       var pageWidth='100%';
       var pageHeight='100%';
    }
    //set the shader to cover the entire page and make it visible.
	dark.style.top='0px';                           // In the top
	dark.style.left='0px';                          // Left corner of the page
    dark.style.opacity=opaque;
    dark.style.MozOpacity=opaque;
    dark.style.filter='alpha(opacity='+opacity+')';
    dark.style.zIndex=zindex;
    dark.style.backgroundColor=bgcolor;
    dark.width= '100%';
    dark.height= '100%';
    dark.style.display='block';
    loadingBar.style.display='block';
  } else {
     dark.style.display='none';
     loadingBar.style.display='none';
  }
}
grayOut('true');



function unGray(){
	//var sparky=setTimeout("myLightbox.initLightbox()",3000);
	var sparky=setTimeout("grayOut(false)",2500);
	document.getElementById("infoBox").style.visibility="hidden";
	var sparky=setTimeout("checkSlideShow()",7000);
	var sparky=setTimeout("checkChange()",2000);
	var objDiv = document.getElementById("albumList");
	objDiv.scrollTop=0;
}
function loadAlbum(location){
	document.getElementById("controlBox").style.display="none";
	location.replace(/%20/g," ");
	var a=grayOut(true);
	newlocation=location;
	splitLocation=newlocation.split("\/");
	newlocation="";
	currentLocation="";
	for(x=0;x<splitLocation.length-2;x++){
		spacedSplit=splitLocation[x];
		spacedSplit=spacedSplit.replace(/\%20/g, " ");
		newlocation+=("<a href='#"+currentLocation+splitLocation[x]+"/' onClick='javascript:loadAlbum(\""+currentLocation+splitLocation[x]+"/\")'>"+spacedSplit+"</a> / ");
		currentLocation+=splitLocation[x]+"/";
	}
	spacedSplit=splitLocation[splitLocation.length-2];
	spacedSplit=spacedSplit.replace(/\%20/g, " ");
	newlocation=newlocation+spacedSplit + " /";
	docTitle=document.title;
	splitTitle=docTitle.split(/ : /);
	document.title=splitTitle[0]+" : "+spacedSplit;
	loadTest=new Ajax.Updater('albumList', 'loadimages.cgi', {parameters: {afunction: 'loadFolder', directory: location}, method: 'post', onComplete: unGray()});
	//document.getElementById("albumListFrame").innerHTML=document.getElementById("albumList").innerHTML;
	document.getElementById("locationBox").innerHTML=newlocation;
	myLocation=location;
	document.getElementById("infoBox").style.visibility="hidden";
}
function checkLocation(){
	nowHref=window.location.href
	nowHref=nowHref.replace(/\%20/g, " ");
	myLocation=nowHref
	if(myLocation.indexOf("#") > -1)
	{
		check=1;
		album=(myLocation.split("#"))[1];
	}else{
		check=0;
	}
	//check for "bookmark"
	if(check != 1){
		window.location.href=nowHref+"#Albums/";
		loadAlbum("Albums/")
	}else{
		loadAlbum(album)
	}
}
function checkChange(){
	nowHref=window.location.href
	nowHref=nowHref.replace(/\%20/g, " ");
	album=(nowHref.split("#"))[1];
	if(myLocation != album){
		checkLocation();
	}
	var checkSparky=setTimeout("checkChange()",500);
}


var infoBox = getStyleObject("infoBox")

var IE = document.all?true:false;
if (!IE) document.captureEvents(Event.MOUSEMOVE)
document.onmousemove = getMouseXY;
var tempX = 0;
var tempY = 0;

function getMouseXY(e) {
	if (IE) { // grab the x-y pos.s if browser is IE
		tempX = event.clientX + document.body.scrollLeft;
		tempY = event.clientY + document.body.scrollTop;
	}
	else {  // grab the x-y pos.s if browser is NS
		tempX = e.pageX;
		tempY = e.pageY;
	}
	if (tempX < 0){tempX = 0;}
	if (tempY < 0){tempY = 0;}
	document.Show.MouseX.value = tempX;
	document.Show.MouseY.value = tempY;
	//var Sparky=setTimeout('getMouseXY(e)',50);
}

function displayAlbumInfo(vis, info){
	if(vis){

		document.getElementById("infoBox").innerHTML="<font size=+1>"+info+"</font>";
		//alert(info)
		infoBox.visibility='visible';
		//alert(document.Show.MouseY.value);
		infoBox.left=eval(document.Show.MouseX.value+"+10")+"px";
		infoBox.top=eval(document.Show.MouseY.value+"-20")+"px";
		//var Sparky=setTimeout("displayAlbumInfo('"+vis+"','"+info+"')",1000);
		if(info == ""){
			//infoBox.visibility='hidden';
		}
	}else{
		infoBox.visibility='hidden';
	}
}
function getStyleObject(objectId) {
	// cross-browser function to get an object's style object given its
	if(document.getElementById && document.getElementById(objectId)) {
	// W3C DOM
	return document.getElementById(objectId).style;
	} else if (document.all && document.all(objectId)) {
	// MSIE 4 DOM
	return document.all(objectId).style;
	} else if (document.layers && document.layers[objectId]) {
	// NN 4 DOM.. note: this won't find nested layers
	return document.layers[objectId];
	} else {
	return false;
	}
} // getStyleObject
var slideOn=0;
function slideShow(isOn){
	if(isOn){
		slideOn=1;
	}
	var anchors = document.getElementsByTagName('a');
	var x=0;
	if(!anchors[x]){
		alert("No slideshow to display");
	}
	while(anchors[x].getAttribute('rel') != "lightbox[album]" && x<anchors.length){
		x++;
	}
	if(x>=anchors.length){
		alert("No slideshow to display");
	}else{
		myLightbox.start(anchors[x]);
		var Sparky=setTimeout("changeSlide()",10000);
	}
}
function changeSlide(){
	if(slideOn==1){
		number=eval(activeImage+"+1");
		myLightbox.changeImage(number);
		if(number<imageArray.length-2){
			setTimeout("changeSlide()",10000);
		}
	}
}
function changeBar(location){
	myLoc=window.location.href;
	mySplit=myLoc.split("#");
	window.location.href=mySplit[0]+"#"+location;
	loadAlbum(location);
}
function checkSlideShow(){
	if(window.document.getElementById("albumShown")){
		document.getElementById("controlBox").style.display="block";
	}
}