// JavaScript for gallery (*Photos.html) pages
// specific data supplied in each gallery (*Photo.html) page for:
//   galleryFolder
//   individual image data

// define js var which indicates a gallery page is opened (1)
var galleryPage = 1;

// define constructor for Work class
// title, who/what, place, date, source, detailWidth, detailHeight, thumbnailWidth, thumbnailHeight
function Work(t,w,p,d,s,dW,dH,tW,tH){
  this.title=t;
  this.whoWhat=w;
  this.place=p;
  this.date=d;
  this.dtSrc="/images/"+galleryFolder+"/"+s+".jpg";
  this.tnSrc="/images/"+galleryFolder+"/"+s+"tn.jpg";
  this.dtW=dW;
  this.dtH=dH;
  this.tnW=tW;
  this.tnH=tH;
}

// methods of Work class
//   method to write detail (larger) data: image only
function dtImgWrt(){  // image only for detail (larger)
  return "<img src='"+this.dtSrc+"' width='"+this.dtW+"' height='"+this.dtH+"' alt='"+this.title+"'><br />";
}

//   method to write detail (larger) data: text only
function dtDataWrt(){
  return "<p>"+this.title+"</p><p>"+this.whoWhat+"</p><p>"+this.place+"</p><p>"+this.date+"</p>";
}

//   method to write image and data for thumbnail (smaller)
function tnWrt(){
  return "<img src='"+this.tnSrc+"' width='"+this.tnW+"' height='"+this.tnH+"' alt='"+this.title+"'><br />"+this.title;

/* was: return "<img src='"+this.tnSrc+"' width='"+this.tnW+"' height='"+this.tnH+"' border='0' alt='"+this.title+"'><br />"+this.title+"<br />"+this.whoWhat+"<br />"+this.place+"<br />"+this.date;
*/
}

//  create and discard initial object for Netscape Navigator 3
new Work(0,0,0,0,0,0,0,0,0);

// assign methods to prototype, so methods can be called from object: work[k].dtWrite()
Work.prototype.dtImgWrite=dtImgWrt;
Work.prototype.dtDataWrite=dtDataWrt;
Work.prototype.tnWrite=tnWrt;

var detail = null; // detail page
var curWork=0; // current item in scope of driver page

// open/write/focus for document on detail page
function openDetail(j){
  curWork=j;
  if (!detail || detail.closed){ // detail window is closed or not defined
	detail = window.open("","detail","width=723,height=395,location,toolbar,resizable,status,scrollbars");
	writeDetail(j);
  }else{
	if (j != detail.j){ // detail window is open for different artwork
	  writeDetail(j);
      detail.focus();
	}else{ // detail window for same artwork is open
	  detail.focus();
	}
  }
}

// write new document to detail page, if initiated from detail page
// change value of curWork when moving to next or previous work
function nextPrev(change){ // change = +1 (next) or -1 (previous)
  curWork += change;
  if (curWork < 0)
	curWork = work.length - 1;
  else if (curWork >= work.length)
	curWork = 0;
  writeDetail(curWork);
  detail.focus();
}

// write detail page
function writeDetail(j){
  var code = detailCode(j);
  detail.document.write(code);
  detail.document.close();
}

// aggregate code for detail page
function detailCode(j){

  d = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">';
  d += '<html lang="en"><head>';
  d += '\n<title>'+ work[j].title+' - Photo Album - Asturian-American Migration Forum<\/title>';
  d += '\n<link rel=stylesheet href="'+cssFile+'" type="text/css">';
  d += '\n<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">\n<\/head>';

  d += '\n<body>\n<div class="center"><table width="705" summary="layout"><tr><td rowspan="2">';
  d += '<img src="/images/spacer.gif" width="8" height="385" alt=""/><\/td>';
  
  d += '\n<td width="160" valign="top"><img src="/images/spacer.gif" width="160" height="1" alt=""/><br /><br />';
  d += '\n<h4>Asturian-American<br />Migration Forum<\/h4><br /><br />';
  d += work[j].dtDataWrite()+'</td>\n<td rowspan="2">&nbsp;&nbsp;<\/td>';

  d += '\n<td width="500" rowspan="2" class="center"><img src="/images/spacer.gif" width="500" height="1" alt=""/><br />'+work[j].dtImgWrite()+'<\/td><\/tr>';
  
  d += '\n<tr><td valign="bottom"><a href="javascript:opener.nextPrev(-1);"><< Previous<\/a>&nbsp;&nbsp;&nbsp;';
  d += '\n<a href="javascript:opener.nextPrev(1);">Next >><\/a><br /><br /><br />';
  d += '\n<a href="javascript:window.opener.focus();"><< '+galleryName+'<\/a><br /><br /><br />';
  d += '\n<\/td><\/tr><\/table>';
  
//  d += '\n<input type="hidden" name="title" value="'+escape(work[j].title)+'">';
  d += '\n</div><\/body><\/html>';
  return d;
}

// when user wants to contact Art from  detail page
// move to gallery window, get title of work, invoke contact page
function contact(){
  var title=escape(work[curWork].title);
  var src=work[curWork].tnSrc;
  var loc="/contactRealistPainting.php?detailTitle="+title+"&imgSrc="+src+"&referer="+document.URL;
  location.href=loc;
}