// JavaScript Document

function MM_findObj(n, d) { //v3.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); return x;
}

/* Functions that swaps images. */
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

/* Functions that handle preload. */
function MM_preloadImages() { //v3.0
 var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
   var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
   if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

// FUNCTION THAT CHECKS THE DOM 
function getObj(name){
if (document.getElementById)
{this.obj = document.getElementById(name);}
else if (document.all)
{this.obj = document.all[name];}
else if (document.layers)
{this.obj = document.layers[name];}
}

// CENTER WINDOW //
function getWindowHeight() {
var windowHeight=0;
if (typeof(window.innerHeight) == 'number') {
windowHeight = window.innerHeight;
}
else {
if (document.documentElement && document.documentElement.clientHeight) {
windowHeight = document.documentElement.clientHeight;
}
else {
if (document.body&&document.body.clientHeight) {
windowHeight = document.body.clientHeight;
}
}
}
return windowHeight;
}

function setSpacing() {
if (document.getElementById) {
var windowHeight = getWindowHeight();
if (windowHeight > 0) {
var contentElement = new getObj('content');
var contentHeight = contentElement.obj.offsetHeight;
if (windowHeight - contentHeight > 0) {	
contentElement.obj.style.position = 'relative';
contentElement.obj.style.top = ((windowHeight / 2) - (contentHeight / 2)) + 'px';
}
else {
contentElement.obj.style.position = 'relative';
contentElement.obj.style.top = "0px";
}
}
}
}

// START SITE //

window.onload = function() {
  setSpacing();
   //goImages(1);
 goHome(); /**/
}

window.onresize = function() {
  setSpacing();
}

// GENERIC //

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") {
	thisShowing.obj.className = "make_block";	
	}
	else {
	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;
}


// SECTION FUNCTIONS 

function goHome() {
	//doHide('sorry','none');
	doHide('full_image','none');	
	doHide('image_title','none');	
	doHide('foliotitle','none');
	doHide('thumb_content','none');
	doHide('Contact','none');
	doHide('Copyright','none');
	doHide('btm_full','none');
	doHide('btm_thumbs','none');
	doHide('btm_contact','none');
	doShow('top_row','block');
	showHomestrip();
	doShow('home_content','block');
	doShow('btm_home','block');
	//doHighlight(1);
}

function doGetFull(fullNum) {
	doHide('home_content','none');
	doHide('thumb_content','none');
	doHide('Contact','none');
	doHide('Copyright','none');	
	doHide('btm_home','none');
	doHide('btm_thumbs','none');
	doShow('full_image','block');	
	doShow('image_title','block');		
	doShow('foliotitle','block');
	doShow('btm_full','block');
	doHide('btm_contact','none');
myMode='full';
thisnum=fullNum;
switchContent(thisItemNum);
}

function doGetThumbs(thumbsNum) {
	doHide('home_content','none');
	doHide('full_image','none');		
	doShow('foliotitle','block');	
	doHide('image_title','none');
	doHide('Contact','none');
	doHide('Copyright','none');	
	doHide('btm_home','none');
	doHide('btm_full','none');
	doShow('thumb_content','block');	
	doShow('btm_thumbs','block');
	doHide('btm_contact','none');
myMode='thumbs';
thisnum=thumbsNum;
switchContent(thisItemNum);
}


function goContact(returnlink) {	
	doHide('home_content','none');
	doHide('full_image','none');	
	doHide('foliotitle','none');	
	doHide('image_title','none');
	doHide('thumb_content','none');
	doHide('Copyright','none');
	doHide('btm_full','none');
	doHide('btm_thumbs','none');		
	doHide('btm_home','none');
	doShow('Contact','block');
	doShow('btm_contact','block');
	doReturnLink(returnlink);
}

function goCopyright(returnlink) {	
	doHide('home_content','none');
	doHide('full_image','none');	
	doHide('foliotitle','none');	
	doHide('image_title','none');
	doHide('thumb_content','none');
	doHide('Contact','none');
	doHide('btm_full','none');
	doHide('btm_thumbs','none');		
	doHide('btm_home','none');
	doShow('Copyright','block');
	doShow('btm_contact','block');
	doReturnLink(returnlink);
}

function doReturnLink(returnlink) {
	var returnHTML = "<a href='Javascript:";
	switch(returnlink) {
	case 'home':	
	returnHTML = returnHTML + "goHome()";
	break
	case 'full':
	returnHTML = returnHTML + "doGetFull(" + thisnum + ")";
	break
	case 'thumbs':
	returnHTML = returnHTML + "doGetThumbs(0)";
	break
	default:
	returnHTML = returnHTML + "	";	
	}
	returnHTML = returnHTML + ";'>BACK</a>";
	var x = new getObj("returnlink");
	if (document.getElementById || document.all) {	x.obj.innerHTML = returnHTML;	}
	else {
	x.obj.document.open();
	x.obj.document.write(numberContent);
	x.obj.document.close();	
	}
}

// FUNCTION TO SWITCH TO IMAGE MODE
function goImages(thisitemnum) {
	myMode = startMode;
	thisItemNum = thisitemnum
	if (myMode == "full") {
		doGetFull(0);
}
else {doGetThumbs(thisitemnum); }
}

// FUNCTION TO SWITCH TO REQUIRED FOLIO
function switchContent(thisitemnum) {
thisItemNum = thisitemnum;
thisfolio = eval("thisfolio" + thisItemNum);
allnum = thisfolio.length;
if (myMode == "full") {
thisImageDir = fullImageDir;
showthisimage('current');
}
else {
thisImageDir = thumbsImageDir;
showThumbs(0);
}
}

// FUNCTION TO HIGHLIGHT CURRENT FOLIO LINK
/*function  doHighlight(thisNavItem) {
var z = new getObj("footer_links");
if (!z) return;
var y = (z.obj.getElementsByTagName('a').length);
for (var i=1;i<=y;i++) {
navLink = new getObj("nav" + i + "hi");
navLink.obj.className="";
}
if (thisNavItem != 0) {
navLink = new getObj("nav" + thisNavItem + "hi");
navLink.obj.className = "hilite";
return true;
}
}*/

// GET CORRECT FULL IMAGE NUMBER	
function showthisimage(showwhat) {
if (showwhat == "prev") {
if (thisnum >= 1) {
	thisnum = thisnum-1;}
	else {
	if (imageLoop){thisnum = lastnum-1;} 
	else {thisnum = 0;}
	}
}
else if (showwhat == "next" || showwhat == "nextslide") {
if (showwhat == "next") {
}
	if (thisnum < allnum-1) {thisnum = thisnum + 1;}
	else {
	if (imageLoop) {thisnum = 0;} 
	else {thisnum = lastnum-1;}
	}
}
var shownum = thisnum;
getimagefile(shownum);
}

// GET FULL IMAGE
function getimagefile(thisreqnum) {
if (document.images) {
var lastnum = thisfolio.length;
	if ((thisreqnum<lastnum) && thisreqnum>=0) {	
var thisHTML = '<img src="' + thisImageDir + thisfolio[thisreqnum] + '" alt="&copy ' + artistName + '">'
if (hasThumbsLink) {
thisHTML = '<a href="Javascript:doGetThumbs(0);" onMouseOver="status=\'Click here to view thumbnails\'; return true;" onMouseOut="status=\'\'; return true;">' + thisHTML + '</a>'; 
}
//thisHTML = '<table class="imagetable"><tr><td>' + thisHTML + '<\/td><\/tr><\/table>';
var x = new getObj("full_image");
var q = new getObj("foliotitle");

var thisTitle = eval("thisfoliotitle" + thisItemNum);

if (hasThumbsLink) { 
var thumbsLink = new getObj("thumbsLink");
var thumbsHTML = '<a href="Javascript:doGetThumbs(0);" onMouseOver="MM_swapImage(\'thumbs_MM\',\'\',\'gifs\/thumbs_f2.gif\',1);status=\'Click here to view thumbnails\'; return true;" onMouseOut="MM_swapImgRestore();status=\'\'; return true;"><img src="gifs/thumbs.gif" alt="Click here to view thumbnails" id="thumbs_MM" width="43" height="15" \/></a>'; 
}
if (document.getElementById || document.all) {
x.obj.innerHTML = thisHTML;
q.obj.innerHTML = thisTitle;
if (hasThumbsLink) {	
thumbsLink.obj.innerHTML = thumbsHTML; 
}
}

else {
x.obj.document.open();
x.obj.document.write(thisHTML);
x.obj.document.close();
q.obj.document.open();
q.obj.document.write(thisTitle);
q.obj.document.close();
if (hasThumbsLink) {
//thumbsLink.obj.document.open();
//thumbsLink.obj.document.write(thumbsHTML);
//thumbsLink.obj.document.close();
}
}
}
// IMAGE TITLES
if (imageTitles) {
thistitle = eval("thistitle" + thisItemNum);
var titleContent = "<br \/>" + thistitle[thisreqnum];
//var titleContent = "<p>" + thistitle[thisreqnum] + "</p>";
y = new getObj("image_title");
if (document.getElementById || document.all) {
y.obj.innerHTML = titleContent;
}
else {
y.obj.document.open();
y.obj.document.write(titleContent);
y.obj.document.close();
}
}
// IMAGE NUMBERS
if (imageNumbers) {
var z = new getObj("numberseq");
var numberContent =  "<p>" + (thisnum+1) + "/" + allnum + "</p>" ;
//var numberContent = " / " + allnum ;
if (document.getElementById || document.all) {
z.obj.innerHTML = numberContent;
}
else {
z.obj.document.open();
z.obj.document.write(numberContent);
z.obj.document.close();
}
}
// Go Back & Go On links
var thisnext = new getObj("butt_next");
var thisprev = new getObj("butt_prev");

if (thisreqnum < (lastnum-1)) 
	{
		var thisnextHTML = "<a href='Javascript:showthisimage(\"next\");'>&gt;<span class='full_nav'><\/span><\/a>";
	//var thisnextHTML = "<a href='Javascript:showthisimage(\"next\");' onMouseOver=\"MM_swapImage('butt_next_MM','','gifs\/butt_next_f2.gif',1);status='Click here for the next image'; return true;\" onMouseOut=\"MM_swapImgRestore();status=''; return true;\"><img src='gifs\/butt_next.gif' id='butt_next_MM' alt='Click here for the next image' width='12' height='20' \/></span><\/a>";	
	}
else {
thisnextHTML = "<span class='nav_null'>&nbsp;</span>"; 
}

if (thisreqnum > 0)
	{
		var thisprevHTML = "<a href='Javascript:showthisimage(\"prev\");'>&lt;<span class='full_nav'><\/span><\/a>"; 
	//var thisprevHTML = "<a href='Javascript:showthisimage(\"prev\");' onMouseOver=\"MM_swapImage('butt_prev_MM','','graphics\/butt_prev_f2.gif',1);status='Click here for the previous image'; return true;\" onMouseOut=\"MM_swapImgRestore();status=''; return true;\"><img src='graphics\/butt_prev.gif' alt='Click here for the previous image' id='butt_prev_MM' width='40' height='30' \/><\/a>";
	}
else {
thisprevHTML = "<span class='nav_null'>&nbsp;<\/span>";
}/*
}*/
if (document.getElementById || document.all) {
thisnext.obj.innerHTML = thisnextHTML;
thisprev.obj.innerHTML = thisprevHTML;
}
else {
thisnext.obj.document.open();
thisnext.obj.document.write(thisnextHTML);
thisnext.obj.document.close();
thisprev.obj.document.open();
thisprev.obj.document.write(thisprevHTML);
thisprev.obj.document.close();
}/**/
}
}

function showThumbs(thisNumCalled) {
if (document.images) {
var thisHTML = "<ol id='thumbslist'>";
for (var y=thisnum; y<(thisnum+thumbsGrid); y++) {
if (y < allnum) {	
thisHTML = thisHTML + '<li><a href="Javascript:doGetFull(' + y + ');" onMouseOver="status=\'Click here to view the full image\';return true;" onMouseOut="status=\'\';return true;"><img src="' + thumbsImageDir + thisfolio[y] + '" width="' + thumbwidth + '" height="' + thumbheight + '" alt="&copy; ' + artistName + '" border="0"></a>';
//if (thumbTitles) {
//var thumbTitleContent = thistitle[y];
//thisHTML = thisHTML + '<br /><span class="thumbslabel">' + thumbTitleContent.toUpperCase() + '</span>';
//}
thisHTML = thisHTML + '</li>';	}
else { thisHTML = thisHTML + '<li><img src="gifs/spacer.gif" width="' + thumbwidth + '"  height="' + thumbheight + '" alt="#" border="0"></li>'; }	
}
thisHTML = thisHTML + "</ol>";
// ADD TITLE
var thisthumbstitle = eval("thisfoliotitle" + thisItemNum);
var thisTitle = thisthumbstitle;
//
var x = new getObj("thumb_content");
var y = new getObj("foliotitle");
if (document.getElementById || document.all) {x.obj.innerHTML = thisHTML; y.obj.innerHTML = thisTitle;}
else { x.obj.document.open();
x.obj.document.write(thisHTML);
x.obj.document.close();
y.obj.document.open();
y.obj.document.write(thisTitle);
y.obj.document.close();
}
}
}

function showHomestrip() {
if (document.images) {	
var thisStripNum = getRandomNum(choicenum)+1;
//alert("This is Homestrip " + thisStripNum);
//var thisStripNum = 11;
var thisStrip = eval("thisStrip" + thisStripNum);
var thisHTML = '<ol id="home_text"><li><a href="Javascript:goImages(1);">People</a></li><li><a href="Javascript:goImages(2);">Commissions</a></li><li><a href="Javascript:goImages(3);">Portraits</a></li><li><a href="Javascript:goImages(4);">Project</a></li></ol>';
thisHTML = thisHTML + '<ol id="home_images">';
for (var y=0; y<numStrips; y++) {
thisHTML = thisHTML + '<li><a href="Javascript:goImages(' + (y+1) + ');" onMouseOver="status=\'Click here to view the folio\';return true;" onMouseOut="status=\'\';return true;"><img src="' + homestripsImageDir + thisStrip[y] + '" width="' + homestripwidth + '" height="' + homestripheight + '" alt="&copy; ' + artistName + '" border="0"></a>';
thisHTML = thisHTML + '</li>';	
}
thisHTML = thisHTML + "</ol>";
var x = new getObj("home_content");
if (document.getElementById || document.all) {
x.obj.innerHTML = thisHTML;
}
else {
x.obj.document.open();
x.obj.document.write(thisHTML);
x.obj.document.close();
}
}
}
