whichIsOn = 0;
readyToHide = 0;
bigHolder = new Array();

function showSub(which)
{
	if (whichIsOn != 0) document.getElementById("sub"+whichIsOn).className = "subNavOff";
	document.getElementById("sub"+which).className = "subNavOn";
	whichIsOn = which;
	readyToHide++;
}


function hideSub(which)
{
	readyToHide++;
	setTimeout("killSub("+readyToHide+")",2000);
}


function onSub(which)
{
	readyToHide++;
}


function offSub(which)
{
	readyToHide++;
	setTimeout("killSub("+readyToHide+")",2000);
}

function killSub(check)
{
	if (check == readyToHide)
	{
		document.getElementById("sub"+whichIsOn).className = "subNavOff";
		whichIsOn = 0;
	}
}


hpIMG = 0;
hpImageRoutine = false;
firstTime = true;
fadeCat = new Array();

hpPos = 0;
hpSlot = 0;
animPos = 0;

fadeLevel = new Array();
fadeLevel[1] = new Array(9,8,7,6,5,4,3,2,1,0,1,2,3,4,5,6,7,8,9,10,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1);
fadeLevel[2] = new Array(-1,-1,-1,-1,-1,-1,-1,9,8,7,6,5,4,3,2,1,0,1,2,3,4,5,6,7,8,9,10,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1);
fadeLevel[3] = new Array(-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,9,8,7,6,5,4,3,2,1,0,1,2,3,4,5,6,7,8,9,10,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1);
fadeLevel[4] = new Array(-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,9,8,7,6,5,4,3,2,1,0,1,2,3,4,5,6,7,8,9,10,-1,-1,-1,-1,-1,-1,-1);
fadeLevel[5] = new Array(-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,9,8,7,6,5,4,3,2,1,0,1,2,3,4,5,6,7,8,9,10);

firstTimeReady = new Array(false,false,false,false,false,false);


function hpClick(which)
{
	document.location = fadeCat[which];
}

function pageLoaded()
{
	if (hpImageRoutine) startSwapping();
}

function hpIMGfile(filename,newurl)
{
	this.newurl = newurl;
	this.location = filename;
	this.imgFile  = new Image();
	this.imgFile.src  = filename;
}

function startSwapping()
{	
	if (hpIMG != 0) homeTransition();
}

function homeTransition()
{
	for (which=1; which<=5; which++)
	{
		level = fadeLevel[which][animPos];
		if ((firstTime) && (!firstTimeReady[which]))
		{
			if (level == 0) 
			{
				firstTimeReady[which] = true;	
			} else {
				level = -1;
			}
		}
		if (level > -1) setOpacity(which,level);
		if (level == 0) 
		{
			hpPos++;
			if (hpPos > hpIMG) hpPos = 1;
			setPhoto(which,hpPos);
		}
	}
	animPos++;
	if (animPos <= 47)
	{
		setTimeout("homeTransition()",75);
	} else {
		animPos = 0;
		firstTime = false;
		setTimeout("homeTransition()",8000);
	}
}

function setPhoto(slot,pos)
{
	fadeCat[slot] = hpIMGsrc[pos].newurl;
	document.getElementById("hp"+slot).src = hpIMGsrc[pos].location;
}

function setOpacity(slot,level)
{
	document.getElementById("hpb"+slot).className = "transSwap"+level;
}


thumbStore = new Array();
thumbLink = new Array();
thumbText = new Array();
thumbX = new Array();
thumbDesc = new Array();
thumbTitle = new Array();
thumbStart = 1;
extlink = "";
sizerOk = false;
swapContent = false;

function setBig(which)
{

//alert(which);
	if (thumbStore[which] != "0")
	{
	//alert(thumbStore[which]);
		document.getElementById("galleryBig").style.backgroundImage = "url("+thumbStore[which]+")";
		if (thumbX[which] == "439")
		{
			document.getElementById("thumber1").className = "clipNone";
			document.getElementById("galleryBig").className = "bigNarrow";
			sizerOk = false;
		} else {
			document.getElementById("thumber1").className = "clipOff";
			document.getElementById("galleryBig").className = "bigWide";
			sizerOk = true;
		}
		extlink = thumbLink[which];
		if (swapContent)
		{
			document.getElementById("theText").innerHTML = thumbDesc[which];
			document.getElementById("theTitle").innerHTML = thumbTitle[which];
		} else {
			if (thumbText[which] != "")
			{
				document.getElementById("externalLink").innerHTML = thumbText[which];
			} else {
				document.getElementById("externalLink").innerHTML = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
			}
		}
	}
}

function thumberOn()
{
	if (sizerOk)
	{
		document.getElementById("thumber1").className = "clipOn";
	}
}

function thumberOff()
{
	if (sizerOk)
	{
		document.getElementById("thumber1").className = "clipOff";
	}
}

function tNail(thumburl,bigurl,extText,extUrl,dimX,dimY,desc,title)
{
	this.thumburl = thumburl;
	this.bigurl = bigurl;
	this.extText = extText;
	this.extUrl = extUrl;
	this.dimX = dimX;
	this.dimY = dimY;
	this.desc = desc;
	this.title = title;
}

function setThumbs(startPos)
{
	firstPos = startPos;
	lastPos = startPos + 7;
	if (thumbNum < lastPos) lastPos = thumbNum;
	realNum = lastPos + 1;
	for (num = 0; num <= 7; num++)
	{	
		realNum--;
		if ((num+startPos) <= lastPos)
		{
			document.getElementById("thumb"+(num+1)).src = galleryThumbnail[realNum].thumburl;
			document.getElementById("thumb"+(num+1)).className = "gallerySmall";
			thumbStore[num+1] = galleryThumbnail[realNum].bigurl;
			thumbLink[num+1] = galleryThumbnail[realNum].extUrl;
			thumbText[num+1] = galleryThumbnail[realNum].extText;
			thumbX[num+1] = galleryThumbnail[realNum].dimX;
			thumbDesc[num+1] = galleryThumbnail[realNum].desc;
			thumbTitle[num+1] = galleryThumbnail[realNum].title;
		} else {
			document.getElementById("thumb"+(num+1)).src = "wp-content/uploads/nothing.gif";
			document.getElementById("thumb"+(num+1)).className = "gallerySmallEmpty";
			thumbStore[num+1] = "0";
			thumbLink[num+1] = "";
			thumbText[num+1] = "";
			thumbX[num+1] = "";
			thumbDesc[num+1] = "";
			thumbTitle[num+1] = "";
		}
	}
	if (thumbNum > lastPos)
	{
		document.getElementById("arrowR").className = "arrowR1";
		rightClickPos = startPos + 8;
		//alert('camehere');
	} else {
		document.getElementById("arrowR").className = "arrowR0";
		rightClickPos = 0;
		//alert('came else');
	}
	if (startPos > 1)
	{
		document.getElementById("arrowL").className = "arrowL1";
		leftClickPos = startPos - 8;
		//alert('came here2');
	} else {
		document.getElementById("arrowL").className = "arrowL0";
		leftClickPos = 0;
		//alert('came here3');
	}
}

function setStarter()
{
	which = 1;
//	alert(thumbNum);
	//if (thumbNum > 8) which = 8;
	
	setBig(which);
}

leftClickPos = 0;
rightClickPos = 0;

function leftClick()
{
	if (leftClickPos != 0) setThumbs(leftClickPos);
}

function rightClick()
{
	if (rightClickPos != 0) setThumbs(rightClickPos);
}

function extClick()
{
	if (extlink != "") document.location = extlink;
}



function makeBig(which)
{
//alert('camehere');
	document.getElementById("galleryBig").src = bigHolder[which].src;
}
