/*Function to slide a div in to and out of view
(c) S.Howie.  Howie Associates Ltd.
*/
var slider_slideSpeed = 5;	// Higher value = faster
var slider_timer = 10;	// Lower value = faster

var objectIdToSlideDown = false;
var slider_slideInProgress = false;  //Keeps track of a slide to allow it to complete



function showHideContent(inputId)
{
	if(slider_slideInProgress)return;
	slider_slideInProgress = true;
	if(!inputId)inputId = this.id;
	inputId = inputId + '';
	var sliderDiv = document.getElementById(inputId);

	if(sliderDiv.style.display=='none'){		
		sliderDiv.style.display='block';
		sliderDiv.style.visibility = 'visible';
		slideContent(inputId,slider_slideSpeed);
	}else{
		slideContent(inputId,(slider_slideSpeed*-1));
	}	
}
function slideContent(inputId,direction)
{
	
	var obj =document.getElementById(inputId);
	var contentObj = document.getElementById('content_' + inputId);
	height = obj.clientHeight;
	if(height==0)height = obj.offsetHeight;
	height = height + direction;
	rerunFunction = true;
	if(height>contentObj.offsetHeight){
		height = contentObj.offsetHeight;
		rerunFunction = false;
	}
	if(height<=1){
		height = 1;
		rerunFunction = false;
	}

	obj.style.height = height + 'px';
	var topPos = height - contentObj.offsetHeight;
	if(topPos>0)topPos=0;
	contentObj.style.top = topPos + 'px';
	if(rerunFunction){
		setTimeout('slideContent("' + inputId + '",' + direction + ')',slider_timer);
	}else{
		if(height<=1){
			obj.style.display='none'; 
			if(objectIdToSlideDown && objectIdToSlideDown!=inputId){
				document.getElementById(objectIdToSlideDown).style.display='block';
				document.getElementById(objectIdToSlideDown).style.visibility='visible';
				slideContent(objectIdToSlideDown,slider_slideSpeed);				
			}else{
				slider_slideInProgress = false;
			}
		}else{
			slider_slideInProgress = false;
		}
	}
}

function findFromImage()
{ 
    var referrer=document.referrer;
    var contentObj = document.getElementById('content_banner1');
    var imgPath = getPath(location.href);
    var thisPosition, imgName;
    if(referrer!="")
    { 
        imgName=referrer.substr(imgPath.length,referrer.length);
        imgName=imgName.replace(/.html/, ".jpg")
        contentObj.innerHTML='<img src="' + imgPath + 'images/headers/' + imgName + '" />';
    } else {
           contentObj.innerHTML='';
    }

}

/* Function to display a simple text clock in a div called 'clock' */
function displayClock()
{
    var clockTime = new Date();
    var clockHours = clockTime.getHours();
    var clockMinutes = clockTime.getMinutes();
    var clockSeconds = clockTime.getSeconds();
    var clockSuffix = "am";
    var clockDiv;
    
    if (clockHours > 11)
    {
        clockSuffix = "pm";
        clockHours = clockHours - 12;
    }
    if (clockHours == 0){clockHours = 12;}
    if (clockHours < 10){clockHours = "0" + clockHours;}
    if (clockMinutes < 10){clockMinutes = "0" + clockMinutes;}
    if (clockSeconds < 10){clockSeconds = "0" + clockSeconds;}

    clockDiv = document.getElementById('clock');
    clockDiv.innerHTML = clockHours + ":" + clockMinutes + ":" + clockSeconds + " " + clockSuffix;
    setTimeout("displayClock()", 1000);
}

/* Function to output the date as image chars with 2 digit years */
function setDate() {
	var text = "";
	var openImage = "<IMG SRC=\"" + getPath(location.href) + "images/c";
	var closeImage = ".gif\" HEIGHT=13 WIDTH=9>";
	var now = new Date();
	var date = now.getDate(); 
	var month = now.getMonth(); 
	var year = now.getFullYear(); 
	now = null;
	month++ ;  // 0 - 11 => 1 - 12
	date += "";
	month += "";
	year += "";
	for (var i = 0; i < date.length; ++i) {
		text += openImage + date.charAt(i) + closeImage;
	}
	text += openImage + "p.gif\" HEIGHT=13 WIDTH=8>" ;

	for (var i = 0; i < month.length; ++i) {
		text += openImage + month.charAt(i) + closeImage;
	}
	text += openImage + "p.gif\" HEIGHT=13 WIDTH=8>";

	year = year.substring(2);

	for (var i = 0; i < year.length; ++i) {
		text += openImage + year.charAt(i) + closeImage;
	}

	return text;
}
    
function getPath(url) {
	lastSlash = url.lastIndexOf("/");
	return url.substring(0, lastSlash + 1);
}