/* main */
var timer;
var activeMenu = null;
function StartTimer(){
	timer=setTimeout("ResetMenu()",1000);
}
function MaintainMenu(){
	clearTimeout(timer);
}
function StartDrop(objectID){
	activeMenu = objectID;
	if(parseInt(document.getElementById(objectID).style.top)<0){
		MoveMenu(objectID);
	}
}
function MoveMenu(objectID){
	x = document.getElementById(objectID).style;
	x.top=parseInt(x.top)+3+"px"
	if(parseInt(x.top)<0){
		setTimeout("MoveMenu('"+objectID+"')",10);
	} else {
		MaintainMenu();
	}
}
function ResetMenu(){
	x = document.getElementById(activeMenu).style;
	x.top=parseInt(x.top)-3+"px"
	if(parseInt(x.top)>-30){
		setTimeout("ResetMenu()",10);
	}
}
function NavRollOver(objectID,leftCoord,topCoord){
	var startPos = topCoord;
	var endPos = -210;
	x=document.getElementById(objectID).style;
	x.backgroundPosition=leftCoord + "px," + endPos + "px";
}
function NavMouseDown(objectID,bgPos){
	x=document.getElementById('submenu').getElementsByTagName('ul');
	document.getElementById(objectID).style.backgroundPosition = bgPos;
}
function align()
{
	var lmt = document.getElementById('centering');
	var container = document.documentElement;

	if(lmt && container)
	{
	    var containerHeight;
	    if (container.innerWidth)
	    {
            containerHeight = container.innerHeight;
		}
		else
		{
            containerHeight = container.clientHeight;
		}
	    var lmtHeight;
	    if (lmt.innerWidth)
	    {
            lmtHeight = lmt.innerHeight;
		}
		else
		{
            lmtHeight = lmt.offsetHeight;
		}
		var y = Math.ceil((containerHeight - lmtHeight) / 2);
		if(y < 0)
		{
			y = 0;
		}
		lmt.style.position = "relative";
		lmt.style.top = y + "px";
	}
	if (document.getElementById)
	{
		document.body.style.visibility = 'visible';
	}
}
function addevent(obj,evt,fn,capt){
	if(obj.addEventListener)
	{
		obj.addEventListener(evt, fn, capt);
		return true;
	}
	else if(obj.attachEvent)
	{
		obj.attachEvent('on'+evt, fn);
		return true;
	}
	else return false;
}
if (document.getElementById && document.getElementsByTagName)
{
	addevent(window, 'load', align, false);
	addevent(window, 'resize', align, false);
}
function matchColumns(){
	var divs,contDivs,maxHeight,divHeight,d;
	divs = document.getElementsByTagName('div');
	contDivs = [];
	maxHeight = 0;
	for(var i = 0; i<divs.length; i++)	{
		if(/\bcolumn\b/.test(divs[i].className)){
			d = divs[i];
			contDivs[contDivs.length] = d;
			if(d.offsetHeight){
				divHeight = d.offsetHeight;
			}
			else if(d.style.pixelHeight){
				divHeight = d.style.pixelHeight;
			}
		maxHeight = Math.max(maxHeight,divHeight);
		}
	}
	for(var i = 0; i<contDivs.length; i++){
		contDivs[i].style.height=maxHeight + "px";
	}
}
function popIt(URL){
	mywindow = window.open (URL,"mywindow","resizable=1,menubar=0,location=0,status=0,scrollbars=1,width=640,height=480");
}
/* pics */
var arraycounter=0, activeImgId, inactiveImgId, rotateIntId, rotateIntLen = 5000, intervalState, nextUrl, fadePauseInt, bgCoords, galleryName, imgUrl, imgName, imgExt, imgNum, startNum;
/* imagearray and titlearray defined on page */
function rotateHandler(){
	var curOpacity = document.getElementById("curImg").style.opacity;
	if(curOpacity < 1){
		setOpacity("curImg");
	}
	nextUrl = "url(" + imagearray[startNum + arraycounter + 1] + ")";
	document.getElementById("nextImg").style.backgroundImage = nextUrl;
	if ( document.getElementById("rotateBtn").firstChild.data == "start"){
	document.getElementById("rotateBtn").firstChild.data="stop";
	document.getElementById("rotateBtn").style.backgroundPosition="-50px 0px";
	rotateIntId = setInterval("rotateimages()", rotateIntLen);
	} else {
	document.getElementById("rotateBtn").firstChild.data="start";
	document.getElementById("rotateBtn").style.backgroundPosition="-50px -75px";
	clearInterval(rotateIntId);
	clearTimeout(fadePauseInt);
	}
}
function rotateimages(){
	arraycounter=((arraycounter+startNum)<imagearray.length-1) ? arraycounter+1 : 0;
	document.getElementById("curImg").setAttribute("src", imagearray[startNum + arraycounter]);
	var nowNum = startNum + arraycounter + 1;
	activeImgId = "img" + nowNum;
	document.getElementById("curImg").src=imagearray[startNum + arraycounter];
	document.getElementById("curNum").firstChild.data=nowNum;
	document.getElementById("curTitle").firstChild.data=titlearray[startNum + arraycounter];
	document.getElementById(activeImgId).style.borderColor="#046380";
	if(startNum + arraycounter == imagearray.length-1){
		nextUrl = "url(" + imagearray[startNum] + ")";
		document.getElementById("nextImg").style.backgroundImage = nextUrl;
	} else {
		nextUrl = "url(" + imagearray[startNum + arraycounter + 1] + ")";
		document.getElementById("nextImg").style.backgroundImage = nextUrl;
	}
	if(activeImgId == "img" + String(startNum+1)){
		inactiveImgId = "img" + (imagearray.length);
		document.getElementById(inactiveImgId).style.borderColor="#f5f3e1";
	} else {
		inactiveImgId = "img" + (nowNum-1);
		document.getElementById(inactiveImgId).style.borderColor="#f5f3e1";
	}
	fadeObject();
}
function initFade(){
	if(document.getElementById("rotateBtn").firstChild.data == "start"){
		clearTimeout(fadePauseInt);
		setOpacity("curImg");
	} else {
		fadePauseInt = setTimeout("opacity('curImg', 90, 0, 500)", 4500);
	}
}
function fadeObject(){
	var curOpacity = document.getElementById("curImg").style.opacity;
	if(curOpacity < 1){
		fadeIn();
	}
	clearTimeout(fadePauseInt);
	fadePauseInt = setTimeout("opacity('curImg', 90, 0, 500)", 4500);
}
function fadeIn(){
	opacity('curImg', 0, 100, 500);
}
function fadeMsg(){
	setOpacity("msg2user");
	clearTimeout(fadePauseInt);
	fadePauseInt = setTimeout("opacity('msg2user', 90, 0, 900)", 1800);
}
function opacity(id, opacStart, opacEnd, millisec) {
    var speed = Math.round(millisec / 100);
    var timer = 0;
    if(opacStart > opacEnd) {
        for(i = opacStart; i >= opacEnd; i--) {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    } else if(opacStart < opacEnd) {
        for(i = opacStart; i <= opacEnd; i++)
            {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    }
}
function changeOpac(opacity, id) {
    var object = document.getElementById(id).style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
} 
function setOpacity(id){
    var object = document.getElementById(id).style;
    object.opacity = 1.0;
    object.MozOpacity = 1.0;
    object.KhtmlOpacity = 1.0;
    object.filter = "alpha(opacity=" + 100 + ")";
}
function imageSwap(arrayPos){
	setOpacity("curImg");
	document.getElementById("nextImg").style.backgroundPosition = "center 0";
	intervalState=document.getElementById("rotateBtn").firstChild.data;
	if (intervalState == "stop"){
		clearInterval(rotateIntId);
		rotateIntId = setInterval("rotateimages()", rotateIntLen);
		fadeObject();
	}
	inactiveImgId = "img" + String(Number(document.getElementById("curNum").firstChild.data));
	document.getElementById(inactiveImgId).style.borderColor="#f5f3e1";
	document.getElementById("curImg").src=imagearray[arrayPos];
	document.getElementById("curTitle").firstChild.data=titlearray[arrayPos];
	arraycounter = arrayPos;
	document.getElementById("curNum").firstChild.data=(arrayPos+1);
	activeImgId = "img" + (arrayPos+1);
	document.getElementById(activeImgId).style.borderColor="#046380";
	if(arraycounter == startNum + imagearray.length-1){
		nextUrl = "url(" + imagearray[startNum] + ")";
		document.getElementById("nextImg").style.backgroundImage = nextUrl;
	} else {
		nextUrl = "url(" + imagearray[startNum + arraycounter + 1] + ")";
		document.getElementById("nextImg").style.backgroundImage = nextUrl;
	}
}
function changeNum(increment){
	document.getElementById("nextImg").style.backgroundPosition = "center 0";
	intervalState=document.getElementById("rotateBtn").firstChild.data;
	if (intervalState == "stop"){
		setOpacity("curImg");
		clearInterval(rotateIntId);
		rotateIntId = setInterval("rotateimages()", rotateIntLen);
		fadeObject();
	}
	var beginNum = Number(document.getElementById("curNum").firstChild.data);
	var endNum = beginNum + increment;
	if(endNum>imagearray.length){
		endNum=startNum+1;
	} else if(endNum<(startNum+1)){
		endNum=imagearray.length;
	}
	document.getElementById("curImg").src=imagearray[endNum-1];
	bgCoords = document.getElementById("rotateBtn").style.backgroundPosition;
	document.getElementById("curTitle").firstChild.data=titlearray[endNum-1];
	arraycounter = endNum-1;
	document.getElementById("curNum").firstChild.data=endNum;
	activeImgId = "img" + endNum;
	document.getElementById(activeImgId).style.borderColor="#046380";
	inactiveImgId = "img" + beginNum;
	document.getElementById(inactiveImgId).style.borderColor="#f5f3e1";
	if(arraycounter == startNum + imagearray.length-1){
		nextUrl = "url(" + imagearray[startNum] + ")";
		document.getElementById("nextImg").style.backgroundImage = nextUrl;
	} else {
		nextUrl = "url(" + imagearray[startNum + arraycounter + 1] + ")";
		document.getElementById("nextImg").style.backgroundImage = nextUrl;
	}
}
function myMouseOver(objectID, myBgPos, myAltBgPos){
	if (objectID == "rotateBtn"){	
		if ( document.getElementById(objectID).firstChild.data == "start"){
		document.getElementById(objectID).style.backgroundPosition = myBgPos;
		} else {
		document.getElementById(objectID).style.backgroundPosition = myAltBgPos;
		}
	} else {
		document.getElementById(objectID).style.backgroundPosition = myBgPos;
	}
}
function myMouseDown(objectID, myBgPos, myAltBgPos){
	if (objectID == "rotateBtn"){	
		if (document.getElementById(objectID).firstChild.data == "start"){
		document.getElementById(objectID).style.backgroundPosition = myBgPos;
		} else {
		document.getElementById(objectID).style.backgroundPosition = myAltBgPos;
		}
	} else {
		document.getElementById(objectID).style.backgroundPosition = myBgPos;
	}
}
function myMouseUp(objectID, myBgPos, myAltBgPos){
	if (objectID == "rotateBtn"){	
		if ( document.getElementById(objectID).firstChild.data == "start"){
		document.getElementById(objectID).style.backgroundPosition = myBgPos;
		} else {
		document.getElementById(objectID).style.backgroundPosition = myAltBgPos;
		}
	} else {
		document.getElementById(objectID).style.backgroundPosition = myBgPos;
		}
}
function myMouseOut(objectID, myBgPos, myAltBgPos){
	if (objectID == "rotateBtn"){	
		if ( document.getElementById(objectID).firstChild.data == "start"){
		document.getElementById(objectID).style.backgroundPosition = myBgPos;
		} else {
		document.getElementById(objectID).style.backgroundPosition = myAltBgPos;
		}
	} else {
		document.getElementById(objectID).style.backgroundPosition = myBgPos;
	}
}
function thumbnailOver(imgId){
	if(imgId != activeImgId){
	document.getElementById(imgId).style.borderColor="#046380";
	}
}
function thumbnailOut(imgId){
	if(imgId != activeImgId){
	document.getElementById(imgId).style.borderColor="#f5f3e1";
	}
}
function setBgImgUrls(){
	document.getElementById("back").style.backgroundImage="url(images/playerControls.gif)";
	document.getElementById("back").style.backgroundPosition="0px 0px";
	document.getElementById("rotateBtn").style.backgroundImage="url(images/playerControls.gif)";
	document.getElementById("rotateBtn").style.backgroundPosition="-17px 0px";
	document.getElementById("next").style.backgroundImage="url(images/playerControls.gif)";
	document.getElementById("next").style.backgroundPosition="-34px 0px";
	document.getElementById("nextImg").style.backgroundPosition = "center 0";
	document.getElementById("nextImg").style.backgroundImage = "url(" + imagearray[0] + ")";
	document.getElementById("imgBg").style.backgroundImage = "url(images/playerbg.png)";
}
function popMailingList(URL){
	regwindow = window.open (URL,"regwindow","resizable=0,menubar=0,location=0,status=0,scrollbars=0,width=580,height=580");
}
function closeMailingList(){
	regwindow = window.close ("regwindow");
}
function popPayPal(URL){
	regwindow = window.open (URL,"regwindow","menubar=0,location=0,status=0,scrollbars=1,width=800,height=640");
    var a = window.setTimeout("document.payPal.submit();",500);
}
function popWindow(URL, WindowName){
	regwindow = window.open (URL,WindowName,"resizable=1,menubar=1,location=1,toolbar=1,status=1,scrollbars=1");
}
function popIt(URL){
	mywindow = window.open (URL,"mywindow","resizable=1,menubar=0,location=0,status=0,scrollbars=1,width=640,height=480");
}


var itemWidthArray = new Array();
function setHorizontal(itemCount){
	var runningWidth = 0;
	var containerWidth = 0;
	var combinedSpaces = 0;
	for(var j = 0; j < itemCount; j++)
	{
		runningWidth = containerWidth;
		itemWidthArray[j] = Number(parseFloat(document.getElementById("lp" + String(j+1)).offsetWidth));
		containerWidth = runningWidth + itemWidthArray[j];
	}
	combinedSpaces = (itemCount+1)*20;
	document.getElementById("horiz").style.width = String(containerWidth + combinedSpaces) + "px";
	var horizWidth = Number(parseFloat(document.getElementById("horizontal").offsetWidth));
	var horizHeight = Number(parseFloat(document.getElementById("horizontal").offsetHeight));
	if((containerWidth + combinedSpaces) < horizWidth){
		document.getElementById("horizontal").style.overflow = "hidden";
		document.getElementById("horizontal").style.height = String(horizHeight - 55) + "px";		
	}
}


function resetBtn(objectID, backgroundPos){
	document.getElementById(objectID).style.backgroundPosition = backgroundPos;
}
window.onload=function(){
	if(document.getElementById('curImg')){
		preloader();
		document.getElementById("rotateBtn").firstChild.data="start";
		activeImgId = "img" + String(Number(document.getElementById("curNum").firstChild.data));
		document.getElementById(activeImgId).style.borderColor="#046380";
		setBgImgUrls();
		matchColumns();
	}
}