// JavaScript Document

// Copyright Mike Laye, image-access.net

function doHide(theObject,theAction) {
	var thisHiding = new getObj(theObject);
	if (theAction == "hidden") {
	thisHiding.obj.className = "make_hidden";	
	}
	else {
	thisHiding.obj.className = "make_none";	
	}
}

function doShow(theObject, theAction) {
	var thisShowing = new getObj(theObject);
	if (theAction == "block") {		
	//YAHOO.util.Dom.addClass(thisShowing.obj,"make_block");
thisShowing.obj.className = "make_block";	
	}
	else {		
	//YAHOO.util.Dom.addClass(thisShowing.obj,"make_visible");
thisShowing.obj.className = "make_visible";	
	}
}

function doAddClass(theObject, theAction) {
	var thisDiv = new getObj(theObject);
	thisDiv.obj.className = theAction;
}

function getRandomNum(thenum) {
	var rndm = Math.floor(Math.random()*thenum);
	return rndm;
}

function goHome(theObject) {
	var thisArray = eval(thisFolioRoot);
	for (var i in thisArray) {
		var thisTitle = thisArray[i]['mainnav_title'];
		if(thisTitle == "HOME") {
		var thisCat = i;
		}
		}
	var thisHTML = "<div id='fullimage_area'><table><tr><td>";
	var thisFolio = thisData[thisCat]['subnav'][0]['subnav_folio'];
	var i = getRandomNum(thisFolio.length);
	var thisFullImage = thisFolio[i][0];
	thisHTML = thisHTML + "<img src=\"" + fullImageDir + "\/" + thisFullImage + "\" alt=\"" + copyline + "\" \/>";
	thisHTML = thisHTML + "<\/td><\/tr><\/table><\/div>";
	doShow(theObject,'block');	
	doHide(theObject,'none');
	doShow('navigation','block');
	doShow('content','block');
	getMainNav();
	var thisDiv = new getObj('content');
	thisDiv.obj.innerHTML = thisHTML;
	}
	
function goShow(theObject) {
	doHide(theObject,'none');
	doShow('navigation','block');
	doShow('content','block');
	getMainNav();
	goImages(1,0,0,"full");
	}
	
function goText(thisText) {
	doHide('home_area','none');
	doShow('navigation','block');
	doShow('content','block');
	getMainNav();
	var reqCatID;
	var thisArray = eval(thisFolioRoot);
	for (var i in thisArray) { var thisCat = thisArray[i]['mainnav_title']; if (thisCat == thisText.toUpperCase()) {reqCatID = i;}}
	setSelected("navigation","Nav" + reqCatID + "0","selected");
	thisHTML = '<div id="textArea">' + eval("this" + thisText + "Text") + '<\/div>';
	var thisDiv = new getObj("content");
	thisDiv.obj.innerHTML = thisHTML;
	}


function goImages(reqCat,reqFolio,reqStart,reqFormat) {	
	//YAHOO.util.Dom.removeClass("content_area", "bg_circles");
	setSelected("navigation","Nav" + reqCat + "0","selected");
if (reqFormat == "full") {getFullImage(reqCat,reqFolio,reqStart,"","");}	
else {getThumbs(reqCat,reqFolio,reqStart);}	
	}
	
function setSelected(reqElement, reqID, reqClass) {
var el = document.getElementById(reqElement);
var thisList = el.getElementsByTagName('a');
for (var i=0;i<thisList.length;i++) {YAHOO.util.Dom.removeClass(thisList[i], reqClass);}
YAHOO.util.Dom.addClass(reqID, reqClass);
}	

/*function getFullImage(reqCat,reqFolio,reqNum) {
	var thisDiv = new getObj("content"); 
	var thisFullImage = thisData[reqCat]['subnav'][reqFolio]['subnav_folio'][reqNum][0];
	//var thisFullImage = thisData[0]['subnav'][0]['subnav_folio'][0][0];
	thisFullImage = "<div id='fullimage_area'><table><tr><td><a href='Javascript:getThumbs(" + reqCat + "," + reqFolio + " );'><img src=\"" + fullImageDir + "\/" + thisFullImage + "\" alt=\"" + copyline + "\" \/><\/a><\/td><\/tr><\/table></div>";
	thisFullImage = thisFullImage + "<div id='fullimage_nav'>xxxxxx<\/div>";
	//var thisFullImageTitle = eval("folio" + reqFolio)[reqNum][1] ;
	//thisFullImageTitle = "<p>" +  thisFullImageTitle + "</p>"; 
	//thisFullImage = thisFullImage + thisFullImageTitle;
if (document.getElementById || document.all) {
thisDiv.obj.innerHTML = thisFullImage;
	}
else {
thisDiv.obj.document.open();
thisDiv.obj.document.write(thisFullImage);
thisDiv.obj.document.close();
	}
//	if (reqCat != 0) {
getFullImageNav(reqCat,reqFolio,reqNum);
//	}
	}*/
	
function getFullImage(reqCat,reqFolio,reqNum,reqImageFormat,reqDirection) {
	var thisAdj = false;
	var thisDiv = new getObj("content"); 
var thisFolio = thisData[reqCat]['subnav'][reqFolio]['subnav_folio'];
var thisFullImage = thisFolio[reqNum][0];
var thisHTML = "<a href='Javascript:getThumbs(" + reqCat + "," + reqFolio + " );'><img src=\"" + fullImageDir + "\/" + thisFullImage + "\" alt=\"" + copyline + "\" \/><\/a>" ;
if(hasDoubles) {
if (reqImageFormat == "") {
		 	var reqImageFormat = thisFolio[reqNum][4];
		if (reqImageFormat == "") {			
			reqImageFormat = "single_left";
			if (reqDirection == "prev") {reqImageFormat = "single_right";}
			}
	}
var nextNum = reqNum+1;
		nextImageNum = nextNum;
var prevNum = reqNum-1;
		prevImageNum = prevNum;
switch(reqImageFormat) {
			case "single_left":
			if (reqNum < (thisFolio.length-1)) {
				//var thisNextImageFormat = ARTIST_FOLIO_IMAGES[nextNum][1];
				var thisNextImageFormat = thisFolio[nextNum][4];
				if (thisNextImageFormat == "") {
			//alert("two singles - this one left, next one right");
				var thisRightImage = thisFolio[nextNum][0]
				var thisRightHTML = "<a href='Javascript:getThumbs(" + reqCat + "," + reqFolio + " );'><img src=\"" + fullImageDir + "\/" + thisRightImage + "\" alt=\"" + copyline + "\" \/><\/a>";
				thisRightHTML = "<div id=\"right_single\">" + thisRightHTML + "<\/div>";
				/*var thisLeftImage = thisFolio[reqNum][0];
				var thisLeftHTML = "<a href='Javascript:getThumbs(" + reqCat + "," + reqFolio + " );'><img src=\"" + fullImageDir + "\/" + thisLeftImage + "\" alt=\"" + copyline + "\" \/><\/a>" ;*/
				thisLeftHTML = "<div id=\"left_single\">" + thisHTML + "<\/div>";
				thisHTML = thisLeftHTML + thisRightHTML;
				reqNum =reqNum + 1;
				thisAdj = true;
					}
				}
				break;			
			case "single_right":
			if (reqNum > 0) {
				//var prevNum = eval(thisnum)-1;
				//var thisPrevImageFormat = ARTIST_FOLIO_IMAGES[prevNum][1];
				var thisPrevImageFormat = thisFolio[prevNum][4];
				if (thisPrevImageFormat == "") {
					//alert("two singles - this one right, prev one left");	
				var thisLeftImage = thisFolio[prevNum][0];
				var thisLeftHTML = "<a href='Javascript:getThumbs(" + reqCat + "," + reqFolio + " );'><img src=\"" + fullImageDir + "\/" + thisLeftImage + "\" alt=\"" + copyline + "\" \/><\/a>";
				thisLeftHTML = "<div id=\"left_single\">" + thisLeftHTML + "<\/div>";
/*				var thisRightImage = thisFolio[(reqNum)][0];
				var thisRightHTML = "<a href='Javascript:getThumbs(" + reqCat + "," + reqFolio + " );'><img src=\"" + fullImageDir + "\/" + thisRightImage + "\" alt=\"" + copyline + "\" \/><\/a>" ;*/
				thisRightHTML = "<div id=\"right_single\">" + thisHTML + "<\/div>";
				thisHTML = thisLeftHTML + thisRightHTML;
				thisAdj = true;
					}
				}
				break;				
			/*case "single":
			alert("double, centre and finish");
			var thisFullImage = thisFolio[reqNum][0];
			var thisHTML = "<a href='Javascript:getThumbs(" + reqCat + "," + reqFolio + " );'><img src=\"" + fullImageDir + "\/" + thisFullImage + "\" alt=\"" + copyline + "\" \/><\/a>" ;
			break;*/
			}
	}

	
thisHTML = "<div id='fullimage_area'><table><tr><td>" + thisHTML + "<\/td><\/tr><\/table></div>";
thisHTML = thisHTML + "<div id='fullimage_nav'><\/div>";
if (document.getElementById || document.all) {
thisDiv.obj.innerHTML = thisHTML;
	}
else {
thisDiv.obj.document.open();
thisDiv.obj.document.write(thisHTML);
thisDiv.obj.document.close();
	}
if (reqCat != 0) {
getFullImageNav(reqCat,reqFolio,reqNum,thisAdj);
}
}
	
function getFullImageNav(reqCat,reqFolio,reqNum,thisAdj) {
	//var thisNum = reqNum;
	var thisDiv = new getObj("fullimage_nav");
	//var thisFolio = eval("folio" + reqFolio);
	var thisFolio = eval(thisFolioRoot + "[" + reqCat + "]['subnav'][" + reqFolio + "]['subnav_folio']");
	var thisFolioLength = thisFolio.length;
	var prevNum = reqNum;
	if (thisAdj) {prevNum=prevNum-1;}
if (prevNum > 0)
	{ var thisprevHTML = "<a href='Javascript:getFullImage(" + reqCat + "," + reqFolio + "," + (prevNum-1) + ",\"\",\"prev\");'>&lt;<\/a>"; }
else { var thisprevHTML = "&lt;";}
if (reqNum < (thisFolioLength-1)) 
	{ var thisnextHTML = "<a href='Javascript:getFullImage(" + reqCat + "," + reqFolio + "," + (reqNum+1) + ",\"\",\"next\");'>&gt;<\/a>"; }
else {var thisnextHTML = "&gt;"; }
var thiscountHTML = (reqNum+1) + " \/ " + thisFolioLength;
//var thisThumbsLinkHTML = "<a href='Javascript:getThumbs(" + reqCat + "," + reqFolio + ");' id='butt_thumbs'><img src='graphics\/butt_thumbs.gif' alt='click here for gallery overview' \/><\/a>";
var thisThumbsLinkHTML = "<a href='Javascript:getThumbs(" + reqCat + "," + reqFolio + ");' id='butt_thumbs'>THUMBNAILS<\/a>";
//var thisThumbsLinkHTML = "";
var thisHTML = thisThumbsLinkHTML + "<ul id='nav_butts'><li id='butt_prev'>" + thisprevHTML + "<\/li><li id='butt_count'>" + thiscountHTML + "<\/li><li id='butt_next'>" + thisnextHTML + "<\/li><\/ul>";
if (document.getElementById || document.all) {
thisDiv.obj.innerHTML = thisHTML;
	}
else {
thisDiv.obj.document.open();
thisDiv.obj.document.write(thisHTML);
thisDiv.obj.document.close();
	}		
	}
	
var getThumbs = function(reqCat,reqFolio) {
var thisImageFolio = eval(thisFolioRoot + "[" + reqCat + "]['subnav'][" + reqFolio + "]['subnav_folio']");
var thisHTML =  "<div id='thumbs_area'><ol id='thumbs'>";	
var thisPosition = "left";
for (var i=0;i<thisImageFolio.length;i++) {
var reqImageFormat = "";
if(hasDoubles) {
var thisThumbFormat = thisImageFolio[i][4];
		switch(thisThumbFormat) {
			case "":
				switch(thisPosition) {
					case "left":
					//thisHTML = thisHTML + "<td class=\"single_left\"><a class=\"width75\" href=\"Javascript:updateFullImage('" + y + "','single_left'," + thisFrame + ");\"><img src=\"/ti/" + thisThumbFilename + "\" alt=\"\" /><\/a></td>";
					reqImageFormat = "single_left";
					thisPosition = "right";
					break;					
					case "right":
					//thisFrame = eval(thisFrame - 1);
					//thisHTML = thisHTML + "<td class=\"single_right\"><a class=\"width75\" href=\"Javascript:updateFullImage('" + y + "','single_right'," + thisFrame + ");\"><img src=\"/ti/" + thisThumbFilename + "\" alt=\"\" /><\/a></td><td class=\"single_spacer\"><div class=\"width5\">&nbsp;<\/div></td>";
					reqImageFormat = "single_right";
					thisPosition = "left";
					break;
					}
			break;	
			
/*			case "single":
					if (thisPosition == "right") {
					thisPosition = "left";
					//thisHTML = thisHTML + "</tr></table></li>";
					thisHTML = thisHTML + "<td class=\"single_right\"><div class=\"width75\"><\/div></td><td class=\"single_spacer\"><div class=\"width5\">&nbsp;<\/div></td>";
					}
					thisHTML = thisHTML + "<td><a class=\"width151\" href=\"Javascript:updateFullImage('" + y + "','double'," + thisFrame + ");\"><img src=\"/ti/" + thisThumbFilename + "\" alt=\"\" /><\/a></td><td class=\"single_spacer\"><div class=\"width5\">&nbsp;<\/div></td>";
			break;		*/				
			}



}
thisHTML =  thisHTML + "<li><table><tr><td class='thumbs'><a href='Javascript:getFullImage(" + reqCat + "," + reqFolio + ", " + i + ",\"" + reqImageFormat +  "\",\"\");'><img src='" + thumbsImageDir + "\/" + thisImageFolio[i][0] + "' alt='" + copyline + "' \/><\/a><\/td><\/tr><\/table><\/li>";	
}
var thisgrid = thumbrows * thumbcols;
if (thisgrid > thisImageFolio.length) { var thisExtraCells = thisgrid-thisImageFolio.length;}
else {var thisExtraCells = (thumbcols - (thisImageFolio.length % thumbcols));
if (thisExtraCells == thumbcols) {thisExtraCells = 0;}
}
	for (var i=0;i<(thisExtraCells);i++) {	
thisHTML =  thisHTML + "<li><table><tr><td class='thumbs'><\/td><\/tr><\/table><\/li>";	
}
thisHTML =  thisHTML + "<\ol><p class='clear_all'><\/p><\/div>";
var thisDiv = YAHOO.util.Dom.get("content");
thisDiv.innerHTML = thisHTML;
		};
		
var getSubMenu = function(reqCat) {
	var reqCatID;
	thisArray = eval(thisFolioRoot);
for (var i in thisArray) {var thisCat = thisArray[i]['mainnav_title'];	if (thisCat == reqCat) {reqCatID = i;}}
setSelected("navigation","Nav" + reqCatID + "0","selected");
var thisSubSection = eval(thisFolioRoot + "[" + reqCatID + "]['subnav']");
var thisHTML = "<div id='submenu_area'><ol>";
for (var i=0;i<thisSubSection.length;i++) {
var thisSubMenuTitle = eval(thisFolioRoot + "[" + reqCatID + "]['subnav'][" + i + "]['subnav_title']");
thisHTML = thisHTML + "<li><a href='Javascript:goImages(" + reqCatID + "," + i + ",0,\"full\");'><img src='graphics/Projects" + reqCatID + i + ".jpg' height='160' width='160' alt='" + thisSubMenuTitle + "'></a><p><a href='Javascript:goImages(" + reqCatID + "," + i + ",0,\"full\");'>" + thisSubMenuTitle + "</a></p><\/li>";
}
thisHTML = thisHTML + "<\/ol><\/div>";
var thisDiv = YAHOO.util.Dom.get("content");
thisDiv.innerHTML = thisHTML;	
};

var getMainNav = function() {
	var thisArray = eval(thisFolioRoot);
	var thisHTML = "<ul>";
	for (var i in thisArray) {
		var thisCat = thisArray[i]['mainnav_title'];
switch(thisCat) {
	case "HOME":
	thisHTML = thisHTML;
	break;	
	case "CONTACT":
	thisHTML = thisHTML + "<li><a href=\"Javascript:goText('Contact');\" id=\"Nav" + i + "0\">" + thisCat + "<\/a><\/li>";;
	break;
	case "CLIENTS":
	thisHTML = thisHTML + "<li><a href=\"Javascript:goText('Clients');\" id=\"Nav" + i + "0\">" + thisCat + "<\/a><\/li>";;
	break;
	default:
	thisHTML = thisHTML + "<li><a href=\"Javascript:goImages(" + i + ",0,0,'full');\" id=\"Nav" + i + "0\">" + thisCat + "<\/a><\/li>";
			}	
	}
	thisHTML = thisHTML + "<li><a href='http:\/\/www.theoutdoorminer.com\/' target='_blank'>LINK<\/a><\/li>";
	thisHTML = thisHTML + "<\/ul>";
var thisDiv = YAHOO.util.Dom.get("navigation");
thisDiv.innerHTML = thisHTML;
	};
	
