/*pic loader
use these functions:
-
thumbnail_start()
thumbnail(picname)
thumbnail_end()
-
picLink(linkname, picname) //textlink
picSetLink(linkname, startindex, new Array(picname1,picname2,...) )
-
variable 'aussibase' must be set in host file.
*/

numpics = 0;
numpicsets = 0;
td_height = 120;

framewidth = 0;
framewidth =  (document.all)? document.all.tags("html")[0].offsetWidth : window.outerWidth;
thumbs_numcols = (framewidth > 0)? (Math.floor(framewidth/130)) : 5;
td_width_per = Math.floor(100/thumbs_numcols);
zoomWindow = 0;
funccall = new Array();
picsets = new Array();

function thumbnail_start()
{
	thumb_col = thumbs_numcols;
	thumb_row = 0;
	apicset = new Array();

	document.write("<center><table width='90%' border=0 cellpadding=0 cellspacing=0>");
}


function thumbnail_end()
{
	html = "";

	if (thumb_row <= 1)
	{
		for (i=thumb_col; i<thumbs_numcols; ++i)
		{
			html+="<td width='"+td_width_per+"%' height="+td_height+">&nbsp;</td>";
		}
	}
	html+="</tr></table></center>";

	document.write(html);
	picsets[numpicsets] = apicset;
	++numpicsets;
}


function thumbnail(picname)
{
	filepath = getThumbFilePath(numpics);

	html = "";
	if (thumb_col == thumbs_numcols)
	{
		if (thumb_row > 0) html += "</tr>";
		html += "<tr>";
		thumb_col = 0;
		++thumb_row;
	}
	++thumb_col;

	html += "<td width='"+td_width_per+"%' height="+td_height+" align='center' valign='middle'>"+
		"<a href='javascript:displayPicSet("+apicset.length+","+numpicsets+");'><img src=\""+filepath+"\"></a></td>";

	document.write(html);
	apicset[apicset.length] = numpics;
	++numpics;
}


function getThumbFilePath(num)
{
	//path begins with "panorama" the extension is ".jpg", otherwise ".jpg"
	var ext = ".gif";
	if (picpath[num].substr(0,8).toLowerCase() == "panorama")
	{
		ext = ".jpg";
	}
	var filepath = aussibase + "pics/thumbs/" + picpath[num] + ext;
	return filepath;
}


function getNormalFilePath(num)
{
	return aussibase + "pics/normal/"+picpath[num]+".jpg";
}


function getZoomFilePath(num)
{
	return aussibase + "pics/zoom/"+picpath[num]+".jpg";
}


function displayPic(num)
{
	width =660;
	height=620;
	scrbars="no";

	width_avail  = screen.availWidth-10;
	height_avail = screen.availHeight-25;
	zoomwidth =screen.availWidth-10;
	zoomheight=screen.availHeight-25;
	if (window.opera) {zoomwidth-= 40; zoomheight-=70;}

	if (height>height_avail) {height=height_avail;scrbars="yes";width+=16;}
	if (width>width_avail) {width=width_avail;scrbars="yes";}

	filenormal = getNormalFilePath(num);
	filezoom = getZoomFilePath(num);
	w1 = window.open("","normal","width="+width+",height="+height+",left=0,top=0,resizable=yes,scrollbars="+scrbars);

	zoomcode = "function zoom() {zoomWindow= window.open('','','menubar=no,status=no,scrollbars=yes,resizable=yes"
	+",width="+zoomwidth+",height="+zoomheight+",dependent=yes,left=0,top=0');"
	+"html = \"<html><head><title>Zoom Ansicht</title></head><body bgcolor=#000000 style='margin:0 0 0 0'>"
	+"<table width='100%' border=0 cellpadding=0 cellspacing=0><tr><td align=center>"
	+"<img border=0 src='"+filezoom+"'></td></tr></table></body></html>\";"
	+"zoomWindow.document.open(); zoomWindow.document.write(html); zoomWindow.document.close(); zoomWindow.focus();}";

	html= "<html><head><title>Foto Ansicht</title><meta http-equiv='content-type' content='text/html; charset=ISO-8859-1'></head>"
	+"<body text=#FFFFFF bgcolor=#000000 style='margin-top:10px'>"
	+"<script type='text/javascript'>"+zoomcode+"</script>"
	+"<table width='100%' border=0 cellpadding=0 cellspacing=0><tr><td colspan=3 align=center>"
	+"<img border=0 src=\""+filenormal+"\"></td></tr><tr><td width=80>&nbsp;</td>"
	+"<td width="+(width-160)+" align=center valign=top><p style='font-family:Arial;font-size:10pt'>"+picdesc[num]+"</p></td>"
	+"<td width=80 valign=bottom>"
//	+"<a href='javascript:zoom()'><img border=0 src=\""+aussibase+"images/lupe.gif\" width=35 height=35></a>"
	+"</td></tr></table>"
	+"</body></html>";

	w1.document.open();
	w1.document.write(html);
	w1.document.close();
	w1.focus();
}


function displayPicSet(startindex, set_nr)
{
	displayPics(startindex, picsets[set_nr]);
}


function displayPics(startindex, intArray)
{
	n = intArray.length;

	pathHTML="picpath=new Array(";
	descHTML="picdesc=new Array(";
	for (i=0; i<n; ++i)
	{
		if (i != 0)
		{
			pathHTML+=",";
			descHTML+=",";
		}
		pathHTML+="\""+picpath[intArray[i]]+"\"";
		descHTML+="\""+picdesc[intArray[i]]+"\"";
	}
	pathHTML+= ");";
	descHTML+= ");";

	width =660;
	height=680;
	framesplit="490,*,50";
	picscroll="no";

	width_avail= screen.availWidth-10;
	height_avail= screen.availHeight-25;
	zoomwidth= width_avail;
	zoomheight= height_avail;
	if (height>height_avail) {height=height_avail;framesplit="*,21,40";picscroll="auto";}

	html= "<html><head><title>Slideshow</title><script type='text/javascript'>var pic_nr="+startindex+";"+pathHTML+descHTML+"</script>";
	html+="</head><frameset rows='"+framesplit+"' framespacing=0 border=0 frameborder=0>"
	+"<frame name='picture' scrolling='"+picscroll+"' src='"+aussibase+"common/picdisplay.html' noresize marginwidth=0 marginheight=0>"
	+"<frame name='text' scrolling='auto' src='"+aussibase+"common/pictext.html' noresize marginwidth=0 marginheight=0>"
	+"<frame src='"+aussibase+"common/picnavi.html' target='picture' scrolling='no' noresize marginwidth=0 marginheight=0>"
	+"</frameset></html>";

	w1 = window.open("","normal","width="+width+",height="+height+",left=0,top=0,resizable=yes");

	w1.document.open();
	w1.document.write(html);
	w1.document.close();
	w1.focus();
}


function picLink(linkname, picname)
{
	document.write("<a href='javascript:displayPic("+numpics+");'>"+linkname+"</a>");
	++numpics;
}


function picSetLink(linkname, startindex, picArray)
{
	n = picArray.length;
	arrText = "new Array(";
	for (i=0; i<n; ++i)
	{
		if (i != 0) arrText+=",";
		arrText += numpics;
		++numpics;
	}
	arrText += ")";
	document.write("<a href='javascript:displayPics("+startindex+","+arrText+");'>"+linkname+"</a>");
}

