<!--
// =======================================================================================
//    Photo database
//    Copyright of database format, engine and photos by redfish hypermedia
//
//    last updated: 000129 by Gerhard Wasner, gwasner@redfish.to
// =======================================================================================



photosel = new Array();
qm = String.fromCharCode(34);
laylargephototop=35;
laylargephotoleft=0;

// ---------------------------------------------------------------------------------------
// --- album render functions
// ---------------------------------------------------------------------------------------


function createphotosel() {
// returns an array with all photos meeting filter criterias:
// [imgtypes, topics --- up to come]

	//re1=new RegExp(plevel) //Regular expression set up a filter criteria
	
	numphotos = photos.length
	numtopics = topics.length
	actualtopic=-1;
	
	j=0;
	for (var i=0; i<numphotos ; i++) 
		//if (true==re1.test(photos[i].privacy)) {
		if (1==1) {
			photosel[j]=photo[i];
			if (actualtopic!=photosel[j].topic.id) { //topic change
				actualtopic=photosel[j].topic.id
				topics[actualtopic].photoidbegin = j;
				if (actualtopic>0)
					topics[actualtopic-1].photoidend = j-1;
			}
			j++;			
		}

	if (actualtopic!=-1)		
		topics[actualtopic].photoidend = j-1;				
}


function returnimagetypes (pnum, imgtypes) {
//returns a HTML string with icons of the 'imgtypes' for image number 'pnum'
	imgt = new Array();
	imgt = splitstring(imgtypes, ",");
	imgthtml = ""
	for (j=0; j<imgt.length; j++) {
		re = new RegExp(imgt[j]);
		if (true==re.test(photosel[pnum].imagetype)) 
			imgthtml += "<IMG SRC='" + albumbase + "g/it" + imgt[j] + ".gif' WIDTH='9' height='10'>";
		else
			imgthtml += "<IMG SRC='" + albumbase + "g/itnull.gif' WIDTH='9' height='1'>";
	}
	return imgthtml;
}


function renderphotothumbs() {
// returns a list of photothumbs positioned in the 's' subdirectory of the albumtopic
// in the filmstripe style ordered by topic.
	
	var numtopics = topics.length;
	var actualtopic="";
	var imagetypes=imgtypes; // imgtypes: global
	var imgperline=6;
	var imgcount=1;
	
	for (var k=0; k<numtopics ; k++) {     // ASCENDING: old to new
		
		if (numtopics>1) { // Write topic title, if more than one topic was defined
			if (""!=topics[k].title) {  // topic is not empty
				dw("<P><IMG SRC='" + albumbase + "g/space.gif' WIDTH='285' HEIGHT='1'><FONT CLASS='albumtopic'>");
				
				dw(topics[k].title + ": " + topics[k].date + "</FONT></P>");				
			} else {
				dw("<P>&nbsp;</P>");
			}
		}
	
		newline=true;
		numphotos = topics[k].photoidend - topics[k].photoidbegin + 1;
		
		photoidbegin = topics[k].photoidbegin;
		photoidend = topics[k].photoidend;
		for (i=photoidbegin; i<=photoidend ; i++) {     // ASCENDING: old to new
				
			photourl = albumbase + photosel[i].topic.dir + photosel[i].topic.thumbsdir + photosel[i].filename;
			photourllarge = albumbase + photosel[i].topic.dir + photosel[i].filename;	
		
			// {{{ ======= simple list =======
			//   dw("<A HREF='javascript:setlargeimage(" +  i + ");'><IMG SRC='" + photourl + "' BORDER='0' ALT='" + photosel[i].title + "'></A> ");
			// =========================== }}}
		
		
			// {{{ ======= table list =======
			if (newline==true) {
				
				dw("<TABLE ALIGN='CENTER' BORDER='0' CELLPADDING='0' CELLSPACING='0'><TR>");
				for (var j=1; j<=imgperline; j++)
					dw("<TD><IMG SRC='" + albumbase + "g/filmtop.gif' WIDTH='122' HEIGHT='16'></TD>");
				dw("</TR><TR>");
				imgcount=1;
				newline=false;
			}
			
			// === the image THUMB ===
			// --- with link to open in new window: 
			//  dw("<TD ALIGN='CENTER' VALIGN='MIDDLE' BGCOLOR='black'><A HREF='javascript:setlargeimage(" +  i + ");'><IMG SRC='" + photourl + "' BORDER='0' ALT='" + photosel[i].title + "' WIDTH='" + photosel[i].sizexs + "' HEIGHT='" + photosel[i].sizeys + "'></A></TD>");
			// --- with link to open simply in same window: 
			dw("<TD ALIGN='CENTER' VALIGN='MIDDLE' BGCOLOR='black'><A HREF='" +  photourllarge + "'><IMG SRC='" + photourl + "' BORDER='0' ALT='" + photosel[i].title + "' WIDTH='" + photosel[i].sizexs + "' HEIGHT='" + photosel[i].sizeys + "'></A></TD>");
			// --- without link:
			//dw("<TD ALIGN='CENTER' VALIGN='MIDDLE' BGCOLOR='black'><IMG SRC='" + photourl + "' BORDER='0' ALT='" + photosel[i].title + "' WIDTH='" + photosel[i].sizexs + "' HEIGHT='" + photosel[i].sizeys + "'></TD>");
		
			if (imgcount<imgperline && i==photoidend)
				dw("<TD COLSPAN='" + (imgperline-imgcount) + "' BGCOLOR='black'>&nbsp;</TD>");
			
			if (imgcount==imgperline || i==photoidend) {
				dw("</TR><TR>");
				for (var j=1; j<=imgperline; j++)
					dw("<TD><IMG SRC='" + albumbase + "g/filmbottom.gif' WIDTH='122' HEIGHT='16'></TD>");
				newline=true;
				dw("</TR></TABLE><P>&nbsp;</P>");
			}
			imgcount++;
		
			// =========================== }}}
			
		} //end for images
	} //end for topics
	
} //end function



function renderphotolist() {
// returns a list of photo titles with icons indicating the type of the photo. 
// grouped by topic
	
	var numtopics = topics.length;
	var numphotos = photosel.length;
	var imagetypes=imgtypes;
	var actualtopic="";
	dw("<P>");
	for (var i=0; i<numphotos ; i++) {     // ASCENDING: old to new
	//for (var i=numphotos-1; i>=0 ; i--) {  // DESCENDIG: new to old		
		if (actualtopic!=photosel[i].topic.title && numtopics>1) { // topic change
			actualtopic=photosel[i].topic.title;
			if (""!=actualtopic) {  // topic is not empty
				dw("</P><P><IMG SRC='" + albumbase + "g/space.gif' WIDTH='100' HEIGHT='1'><FONT CLASS='albumtopic'>");
				dw(photosel[i].topic.title + ": " + photosel[i].topic.date + "</FONT></P><P CLASS='albumentry'>");				
			} else {
				dw("</P><P>&nbsp;</P><P CLASS='albumentry'>");
			}
		}
		
		//if (isnewphoto(i, lastvisited)==true)
		//	dw("<IMG SRC='" + albumbase + "g/itnull.gif' WIDTH='20' HEIGHT='1'><IMG SRC='" + albumbase + "g/itnew.gif' ALT='neu !' WIDTH='20' HEIGHT='10'>"); 
		//else
			dw("<IMG SRC='" + albumbase + "g/itnull.gif' WIDTH='40' HEIGHT='1'>"); 
			
		document.writeln(returnimagetypes(i, imagetypes) + "<IMG SRC='" + albumbase + "g/itnull.gif' WIDTH='9' height='1'>");
		dw("<A HREF='javascript:setlargeimage(" +  i + ");'>" + photosel[i].title + "</A><BR> ");
		
	}
	dw("</P>");
}



// ---------------------------------------------------------------------------------------
// --- setlargeimage, showlargeimages, -redfishimage, -title, -navigation, -copyright
// ---------------------------------------------------------------------------------------

function setlargeimage(imgnum) {
// sets the GLOBAL VARIABLES, USED in LARGE.HTML to the cookie, for each clic on an thumb.
// these variables are read in large.html with GETPARAMETERS()

	setcookies('ra', 'albumbase', albumbase, 'imgnum', imgnum, 'imgtypes', imgtypes, 'lang', lang, 'largeurl', largeurl);
	
		if (photosel[imagenum].sizeyl-1 < 300)
			newwinsizey = photosel[imagenum].sizeyl-1+100
		else
			newwinsizey = photosel[imagenum].sizeyl-1+70						

	//wo("large", largeurl,  photosel[imagenum].sizexl-1+30, newwinsizey,"yes", "no", "no");
	//alert(largeurl);
	wo("largewin", largeurl,  640, 480,"yes", "no", "no");
	largewin.location.reload();
}

function closelargewin() {
//closes the large-image album window
	winname="largewin";
	if (window[winname] != null) 
		window[winname].close()

}	


function getparameters() {
// gets variables from cookie - set with SETLARGEIMAGE() - and sets the document variables
// used in LARGE.HTML

	//alert(getcookieval('ra'));

		var thecookies=new Array();
		thecookies=getcookies('ra', 'albumbase', 'largeurl', 'imgnum', 'imgtypes', 'lang');
		albumbase = thecookies[0];
		largeurl = thecookies[1];
		simagenum = thecookies[2];
		imagenum = simagenum.valueOf();
		imgtypes = thecookies[3];
		lang = thecookies[4];
}


function resizelargewindow() {
// USES GLOBAL DOCUMENT VARIABLES and resizes the large window

	
		if (photosel[imagenum].sizeyl-1 < 300)
			newwinsizey = photosel[imagenum].sizeyl-1+100
		else
			newwinsizey = photosel[imagenum].sizeyl-1+100						
		this.resizeTo(photosel[imagenum].sizexl-1+40+ laylargephotoleft, newwinsizey)

}



function showdoctitle(viewtype) {
// USES GLOBAL DOCUMENT VARIABLES and displays the title for the HTML DOCUMENT
	if (true == isNaN(imagenum)) 
		imagenum=0 
		
	dw("<TITLE>redfish album " + photosel[imagenum].topic.title + " - " + viewtype + " view</TITLE>" );
	
}


function showoverviewtitle() {
// USES GLOBAL DOCUMENT VARIABLES and displays the title for the HTML DOCUMENT
	
	if (true == isNaN(imagenum)) 
		imagenum=0 
		
	//alert(photosel[imagenum].topic.title);
	dw("<FONT CLASS='toptableheader'>redfish album <B>" + photosel[imagenum].topic.title + "</B> &nbsp; </FONT>");
	
}

function showlargetitle() {
// USES GLOBAL DOCUMENT VARIABLES and displays the title in the LARGE window as first line
	
	if (false == isNaN(imagenum)) {
		if (photosel[imagenum.valueOf()].topic.title != "")
			topicseparator=" : ";
		else
			topicseparator="";
			
		dw("<TABLE WIDTH='100%' BORDER='0' CELLPADDING='2' CELLSPACING='0'><TR>");
        	dw("<TD CLASS='toptable' ALIGN='LEFT' VALIGN='MIDDLE'>");
		dw("<FONT CLASS='albumtitlesub'>" + photosel[imagenum.valueOf()].topic.title + "</FONT> <BR> <FONT CLASS='toptableheader'><B>" + photosel[imagenum.valueOf()].title + " </B> </FONT> " );
		dw("</TD></TR></TABLE>");
	}
}


function shownavigation() {
// USES GLOBAL DOCUMENT VARIABLES and displays the navigation

	maximage = photosel.length
	if (lang=="de") {
		strback="Zum Photoalbum ";
		strof="von ";
	} else if (lang=="es") {
		strback="Al álbum de fotos ";
		strof="de ";
	} else {
		strback="To the photo album ";
		strof="of ";
	}
	
		
	if (false == isNaN(imagenum)) {

		if (browsernetscape4)
			dw("<layer id='laynavigation' position='absolute' top='" + laylargephototop + "' left='" + laylargephotoleft + "' width='200'  height='30' z-index='21'>");
		else if (browsermicrosoft4)
			dw("<div id='laynavigation' style='position:absolute; left:" + laylargephotoleft + "px; top:" + laylargephototop + "px; width:200px; height:30px; z-index:21'>");		
			
		dw("<TABLE BORDER='0' CELLPADDING='0' CELLSPACING='0'><TR>");
		
		//=== Navigation << < > >> ====
		dw("<TD CLASS='smallfont' ALIGN='LEFT' VALIGN='MIDDLE'>");		
		if (imagenum > 0) {
			dw("<A HREF='javascript:setlargeimage(" + (0)          + ")'><IMG SRC='" + albumbase + "g/navfirst.gif' border='0' ALT='" + photosel[0].title + "'></A>");
			dw("<A HREF='javascript:setlargeimage(" + (imagenum-1) + ")'><IMG SRC='" + albumbase + "g/navprev.gif' border='0' ALT='" + photosel[(imagenum-1)].title + "'></A>");
		} else {
			dw("<IMG SRC='" + albumbase + "g/space.gif' HEIGHT='1' WIDTH='40'>");
		}
		
		dw("</TD><TD CLASS='smallfontgrey' WIDTH='80' ALIGN='CENTER' VALIGN='MIDDLE'>");
		dw("<B>" + ((imagenum-1)+2) + "</B> " + strof + maximage);
		
		dw("</TD><TD CLASS='smallfont' ALIGN='LEFT' VALIGN='MIDDLE'>");
		if (imagenum < maximage-1) {
			dw("<A HREF='javascript:setlargeimage(" + ((imagenum-1)+2) + ")'><IMG SRC='" + albumbase + "g/navnext.gif' border='0' ALT='" + photosel[((imagenum-1)+2)].title + "'></A>");
			dw("<A HREF='javascript:setlargeimage(" + (maximage-1) + ")'><IMG SRC='" + albumbase + "g/navlast.gif' border='0' ALT='" + photosel[(maximage-1)].title + "'></A>");
		} else {
			dw("<IMG SRC='" + albumbase + "g/space.gif' HEIGHT='1' WIDTH='40'>");
		}
		
		dw("</TD></TR></TABLE>");

		if (browsernetscape4)
			dw("</layer>");
		else if (browsermicrosoft4)
			dw("</div>");
	}
}


function showlargeimage() {
// USES GLOBAL DOCUMENT VARIABLES and renders the IMG tag for the actual large image on a layer

	if (isNaN(imagenum)) 
		dw("<IMG SRC='../g/logo.jpg'>");
	else {
		if (browsernetscape4)
			dw("<layer id='layphoto' position='absolute' top='" + laylargephototop + "' left='" + laylargephotoleft + "' width='" + photosel[imagenum].sizexl + "'  height='" + photosel[imagenum].sizeyl + "' z-index='3'>");
		else if (browsermicrosoft4)
			dw("<div id='layphoto' style='position:absolute; left:" + laylargephotoleft + "px; top:" + laylargephototop + "px; width:" + photosel[imagenum].sizexl + "px; height:" + photosel[imagenum].sizeyl + "px; z-index:3'>");		
				
		dw("<IMG SRC='"  + albumbase + photosel[imagenum].topic.dir + photosel[imagenum].filename + "' WIDTH='" + photosel[imagenum].sizexl + "' HEIGHT='" + photosel[imagenum].sizeyl + "'>");

		if (browsernetscape4)
			dw("</layer>");
		else if (browsermicrosoft4)
			dw("</div>");

	}
}


function showredfishimage() {
// USES GLOBAL DOCUMENT VARIABLES and renders the IMG tag for the protection image on a layer

		if (browsernetscape4)
			dw("<layer id='layredfishimage' position='absolute' top='" + laylargephototop + "' left='" + laylargephotoleft + "' width='" + photosel[imagenum].sizexl + "'  height='" + photosel[imagenum].sizeyl + "' z-index='10'>");
		else if (browsermicrosoft4)
			dw("<div id='layredfishimage' style='position:absolute; left:" + laylargephotoleft + "px; top:" + laylargephototop + "px; width:" + photosel[imagenum].sizexl + "px; height:" + photosel[imagenum].sizeyl + "px; z-index:10'>");		

		dw("<IMG SRC='"  + albumbase + "g/redfishimage.gif' WIDTH='" + photosel[imagenum].sizexl + "' HEIGHT='" + photosel[imagenum].sizeyl + "'>");

		if (browsernetscape4)
			dw("</layer>");
		else if (browsermicrosoft4)
			dw("</div>");

}


function returncopyrightstring() {
// USES GLOBAL DOCUMENT VARIABLES and renders the copyright and license note as table

	crs=""
        if (lang=="de") {
		crs+="&copy; 1999-2000 redfish.to  Alle Rechte vorbehalten.";
        	crs+="<A HREF='javascript:wo(" + qm + "license" + qm + ", " + qm + albumbase + "license.html" + qm + " ,500,300);'>Bedingungen.</A></FONT></TD>";
	} else if (lang=="es") {
		crs+="&copy; 1999-2000 redfish.to  Reservados todos los derechos.";
        	crs+="<A HREF='javascript:wo(" + qm + "license" + qm + ", " + qm + albumbase + "license.html" + qm + " ,500,300);'>Condiciones.</A></FONT></TD>";
	} else {
		crs+="&copy; 1999-2000 redfish.to All rights reserved.";
        	crs+="<A HREF='javascript:wo(" + qm + "license" + qm + ", " + qm + albumbase + "license.html" + qm + " ,500,300);'>Terms and conditions.</A></FONT></TD>";
	}

	return crs
}


function rendercopyright() {
// USES GLOBAL DOCUMENT VARIABLES and renders the copyright and license note as TABLE

	dw("<TABLE BORDER='0' CELLPADDING='6' WIDTH='100%' CELLSPACING='0'><TR>");
        dw("<TD VALIGN='TOP' COLSPAN='2' ALIGN='RIGHT'><FONT COLOR='#DEA907' CLASS='footer'>");
        dw(returncopyrightstring());
	dw("</TR></TABLE>");        
}


function showlargecopyright() {
// USES GLOBAL DOCUMENT VARIABLES and renders the copyright and license note as LAYER

	if (browsernetscape4)
		dw("<layer id='laycopyright' position='absolute' top='" + (photosel[imagenum].sizeyl-20+laylargephototop) + "' left='" + (laylargephotoleft+5) + "' width='" + photosel[imagenum].sizexl + "'  height='30' z-index='20'>");
	else if (browsermicrosoft4)
		dw("<div id='laycopyright' style='position:absolute; left:" + (laylargephotoleft+5) + "px; top:" + (photosel[imagenum].sizeyl-20+laylargephototop) + "px; width:" + photosel[imagenum].sizexl + "px; height:30px; z-index:20'>");		

	dw("<P><FONT COLOR='#ff3300' CLASS='footer'>");
	dw(returncopyrightstring());
	dw("</FONT></P>");
	
	if (browsernetscape4)
		dw("</layer>");
	else if (browsermicrosoft4)
		dw("</div>");
	
}


function renderformlarge() {
// USES GLOBAL DOCUMENT VARIABLES and renders the FORM tag for the largeXXX.html

	if (largeurl=="")
		largeurl="large.html"
	dw("<FORM NAME='formphoto' ACTION='" + largeurl + "'><INPUT TYPE='HIDDEN' NAME='imagename'></FORM>");
	
}



// ---------------------------------------------------------------------------------------
// --- database trimming - necessary for IE4
// ---------------------------------------------------------------------------------------

function trimphotos() {
//	members.pop()	// Navigator 4.0 core only !
temp = new Array();
temp = photos
photo = new Array();
	for (i=0;i<temp.length;i++) {
		if (typeof temp[i].filename !="undefined") 
			photo[photo.length] = temp[i]
	}
}
trimphotos();


// ---------------------------------------------------------------------------------------
// --- debugging
// ---------------------------------------------------------------------------------------

function debugdatabase() {

dw("<DL>");
for (i=photos.length-1;i>-1;i--) {

  dw("<DD><A HREF=" + photo[i].filename + ">" + photo[i].title + "</A></DD>");

}
dw("</DL>" );

}


// -->

