var currentImage 	= '';
var currentImageSrc = '';
var firstImageText 	= '';

function customContextMenu() {
	//return false;
}
//window.document.oncontextmenu = customContextMenu;

function setPageTimer() {
	pageTimer = setTimeout(setPage,300);
}

function setPage() {
	oStage 		= getIt('stage');
	oMenu 		= getIt('menubar');
	oThumbs 	= getIt('thumbNailBar');
	oThumbNailBox = getIt('thumbNailSlider');
	oCart 		= getIt('cartTab');
	oCartTab 	= getIt('rightTab1');
	oBlog 		= getIt('blogBox');
	oInfo		= getIt('infoBox');
	oCartLink	= getIt('cartLink');
	oWorkspace	= getIt('workspace');
	oCartCount	= getIt('cartCountNum');
	oSearchBox	= getIt('searchBox');
	
	sStage 		= new xbStyle(oStage);
	sMenu 		= new xbStyle(oMenu);
	sThumbs 	= new xbStyle(oThumbs);
	sBody 		= new xbStyle(document.body);
	sCart 		= new xbStyle(oCart);
	sBlog 		= new xbStyle(oBlog);
	sSearchBox	= new xbStyle(oSearchBox);
	if (oInfo) {sInfo = new xbStyle(oInfo);}
	
	//Position floating sliders
	oCart.origLeft = sCart.getLeft();
	oCart.endPoint = 0;
	oCart.status = 0;
	oBlog.origLeft = sBlog.getLeft();
	if (oBlog.currentStyle) oBlog.endPoint = sStage.getWidth()-sBlog.getWidth()-5;
	else {
		oBlog.endPoint = sStage.getWidth()-sBlog.getWidth()-5;
	}
	oBlog.status = 1;
	if (oInfo) {
		oInfo.origLeft = sInfo.getLeft();
		oInfo.endPoint = oInfo.origLeft + sInfo.getWidth();
		oInfo.status = 0;
	}


	if (thisPage == 'cart') {}
	else if (thisPage == 'index' || thisPage == 'about' || thisPage == 'contact' || thisPage == 'stockRequest' || thisPage == 'faq') {
		heightPotential = xbGetWindowHeight() - sMenu.getHeight()-52;
		widthPotential = xbGetWindowWidth();
		sStage.setHeight(heightPotential);
	}
	else {
		heightPotential = xbGetWindowHeight() - sMenu.getHeight() - sThumbs.getHeight() - 35;
		widthPotential = xbGetWindowWidth();
		//alert(xbGetWindowHeight()+" - "+sMenu.getHeight()+" - "+sThumbs.getHeight()+" - 35 = "+heightPotential);
		if (heightPotential > 410) {sStage.setHeight(410);}
		else {sStage.setHeight(heightPotential);}
	}
	
	sStage.setWidth(widthPotential);
	
	nThumbs = oThumbNailBox.getElementsByTagName('img');
	if (nThumbs.length > 0) {
		eval(firstImageText);
	}
	
	// Set stage to turn off menus when clicked
	oStage.onclick = closeAllMenus;
	
	// Add Client gallery menu, if available...
	oClientMenu = document.getElementById('clientGalleryList');
	if (oClientMenu) {
		oTopMenu = document.getElementById('topMenu');
		oNode = oClientMenu
		oNode.id = '';
		oTopMenu.appendChild(oNode);
	}
	
	// Set menus links to only work if menu is last leaf on branch
	oLeafs = document.getElementById('topMenu').getElementsByTagName('a');
	for (i=0 ; i<oLeafs.length; i++) {
		if (oLeafs[i].className == 'menuLink') {
			oLeafs[i].onclick = openSubMenu;
			oLeafs[i].href = '';
		}
	}
	
	// Resample home page images to match screen width
	if (thisPage == 'index') {
		aImg = document.getElementsByTagName('img');
		for (i=0; i<aImg.length; i++) {
			thisImg = aImg[i];
			if (thisImg.id.indexOf('indexImg') > -1) {
				sTemp		= new xbStyle(thisImg);
				thisWidth	= sTemp.getWidth();
				thisSrc		= thisImg.src.replace(/_preview_/i, '_full_');
				thisSrc		= thisSrc.substr(thisSrc.lastIndexOf('/')+1);
				thisImg.src = 'picFramer.php?from=intro&image='+thisSrc+'&width='+thisWidth+'&';
			}
		}
	}
	
	// Initialize AJAX function library
	ajaxSelector();
	
}

//Sliding Thumbnail Bar
slideInterval = '';

function slideLeft() {
	//oThumbs.doScroll("scrollbarLeft");
	oThumbs.scrollLeft -= 10;
	}
function slideRight() {
	//oThumbs.doScroll("scrollbarRight");
	oThumbs.scrollLeft += 10;
	}

function slideThumbs(dir) {
	//window.event.cancelBubble = true;
	oThumbs = getIt('thumbNailSlider');
	stopSlide();
	switch (dir) {
	case "left": slideInterval = setInterval("slideLeft()", 50); break;
	case "right": slideInterval = setInterval("slideRight()", 50); break;
	default: break;
	}
}
	
function stopSlide() {
	if (slideInterval) {
		clearInterval(slideInterval);
	}
}

function imgInfo(thisImg) {
	sImg = new xbStyle(thisImg);
	//alert(sImg.getHeight());
}
