// JavaScript for *gallery.html pages
// specific data supplied in gallery page for:
//   galleryFolder
//   galleryName (artist name)
//   individual image data


// set variable which identifies page as gallery page
// used to close detail when gallery page is closed
var galleyPage = 1;

// declare js var for css file in wholeSiteHead.ssi

// define constructor for Work class
//function Work(t,d,m,p,s,dW,dH,tW,tH){
function Work(t,d,m,s,dW,dH,tW,tH){
  this.title=t;
  this.dimen=d;
  this.media=m;
  if (this.media=="" || this.media==null)
    this.media="oil on canvas";
//  this.price=p;
  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(){
  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>"+this.media+"<br />"+this.dimen+"<br />"+this.price;
  return "<p>"+this.title+"</p>"+this.media+"<br />"+this.dimen;
}

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

//  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 XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">';
  d += '\n<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"><head>';
  d += '\n<meta name="lang" content="EN" />';
  d += '\n<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />';
  
  d += '\n<meta name="copyright" content="Copyright on content and design: Art Zoller Wagner, 2003, all rights reserved. No part of this Web site may be reproduced or transmitted by any means or in any form without the prior permission. Web site: www.digitalDesign.us" />';

  d += '\n<title>'+ work[j].title+' -- '+ galleryName+' -- Arte Asturias<\/title>';
  d += '\n<link rel="stylesheet" href="'+cssFile+'" type="text/css" />\n<\/head>';

  d += '\n<body>\n<div class="center"><table summary="layout" width="705"><tr><td rowspan="2">';
  d += '<img src="/images/otherPhotos/spacer.gif" width="8" height="385" alt="" /><\/td>';
  
  d += '\n<td width="160" valign="top"><img src="/images/otherPhotos/spacer.gif" width="160" height="1" alt="" /><br /><br /><h2 class="gallery">Arte Asturias<\/h2><h3 class="gallery">'+ galleryName +'</h3><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/otherPhotos/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);">&laquo; Previous<\/a>&nbsp;&nbsp;&nbsp;';
  d += '\n<a href="javascript:opener.nextPrev(1);">Next &raquo;<\/a><br /><br /><br />';
  d += '\n<a href="javascript:window.opener.focus();">&laquo; Thumbnail Gallery<\/a><br /><br /><br />';
  d += '\n<a href="javascript:opener.contact();">Contact<\/a><br /><br /><br /><\/td><\/tr><\/table>';
  
  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="contactArteAsturias.php?detailTitle="+title+"&imgSrc="+src+"&referer="+document.URL;
  location.href=loc;
}

function closeDetail(){
  if(detail != null){
    detail.close();
    detail=null;
  }
}