/////////////////////////////////////////////////////////////////////////////
// Version 2.3 Signed by Sid Paral @ WEDNESDAY on 2009/01/04 23:06:48 (GMT-0800)
// Authentication (do not edit) $62VQ97$
// Copyright (c) 2004-2009 by Sid Paral. All rights reserved.
/////////////////////////////////////////////////////////////////////////////
//
// galleries' webpage support JavaScript
//

var	g_Gallery					=	new Array ();
var g_iGalleryIndex				=	-1;

function GalleryEntry (sKey,
			  		   sLargeURL, iLargeWidth, iLargeHeight,
			  		   sThumbURL, sTitleText, iThumbWidth)
{
	this.m_sKey					=	sKey;
	this.m_sLargeURL			=	sLargeURL;
	this.m_iLargeWidth			=	iLargeWidth;
	this.m_iLargeHeight			=	iLargeHeight;
	this.m_sThumbURL			=	sThumbURL;
	this.m_sTitleText			=	sTitleText;
	this.m_iThumbWidth			=	iThumbWidth;
	var	iSepPos					=	sTitleText.indexOf(" | ");
	if (!(this.m_bHasCaptionSep	=	(iSepPos >= 0)))
	{
		this.m_sCaptionTextL	=	sTitleText;
		this.m_sCaptionTextR	=	"";
	}
	else
	{
		this.m_sCaptionTextL	=	sTitleText.substring (0, iSepPos);
		this.m_sCaptionTextR	=	sTitleText.substring (iSepPos + 3);
	}
}

function optShowPicEntry (sKey,
			  sLargeURL, iLargeWidth, iLargeHeight,
			  sThumbURL, sTitleText, iThumbWidth)
{
	var		iIndex				=	g_Gallery.length;									
	var		entry				=	new GalleryEntry (sKey,
			  										  sLargeURL, iLargeWidth, iLargeHeight,
			  										  sThumbURL, sTitleText, iThumbWidth);			  										  
	g_Gallery.push (entry);

	document.writeln("<A ONCLICK=\"return onGalleryInvoke(" + iIndex + ");\"");
	document.writeln("\t\tID=\"" + sLargeURL + "\"");
	document.writeln("\t\tHREF=\"" + sLargeURL + "\" TARGET=\"_blank\"><IMG");
	document.writeln("\t\tSRC=\"" + sThumbURL + "\"");
	document.writeln("\t\tALT=\"" + sTitleText + "\" TITLE=\"" + sTitleText + "\"");
	document.writeln("\t\tWIDTH=\"" + iThumbWidth + "\" HEIGHT=\"80\" CLASS=\"pix_link\"></A>");
}

function indexOfGalleryURL (sURL)
{
	var	i;
	for (i = 0; i < g_Gallery.length; ++i)
	{
		if (g_Gallery[i].m_sLargeURL == sURL)
			return i;
	}
	return -1;
}

function galleryBody (iIndex)
{
	var		iLen			=	g_Gallery.length;
	var		sPrev			=	(iIndex > 0)
							?	(	"<A HREF=\""
								+	g_Gallery[0].m_sLargeURL
								+	"\" ONCLICK=\"return onGalleryPix(0);\">"
								+	"<IMG CLASS=\"pix_link\" ALT=\"|&lt;\" SRC=\"../common/le.png\"></A>\r\n"
								+	"<A HREF=\""
								+	g_Gallery[iIndex-1].m_sLargeURL
								+	"\" ONCLICK=\"return onGalleryPix("
								+	(iIndex-1)
								+	");\">"
								+	"<IMG CLASS=\"pix_link\" ALT=\"&lt;\" SRC=\"../common/ln.png\"></A>\r\n")
							:	(	"<IMG CLASS=\"pix_link\" ALT=\"|x\" SRC=\"../common/lex.png\">\r\n"
								+	"<IMG CLASS=\"pix_link\" ALT=\"x\" SRC=\"../common/lnx.png\">\r\n");
//	alert (sPrev);
	var		sNext			=	(iIndex < (iLen - 1))
							?	(	"<A HREF=\""
								+	g_Gallery[iIndex+1].m_sLargeURL
								+	"\" ONCLICK=\"return onGalleryPix("
								+	(iIndex+1)
								+	");\">"
								+	"<IMG CLASS=\"pix_link\" ALT=\"&gt;\" SRC=\"../common/rn.png\"></A>\r\n"
								+	"<A HREF=\""
								+	g_Gallery[iLen-1].m_sLargeURL
								+	"\" ONCLICK=\"return onGalleryPix("
								+	(iLen-1)
								+	");\">"
								+	"<IMG CLASS=\"pix_link\" ALT=\"&gt;\" SRC=\"../common/re.png\"></A>\r\n")
							:	(	"<IMG CLASS=\"pix_link\" ALT=\"x\" SRC=\"../common/rnx.png\">\r\n"
								+	"<IMG CLASS=\"pix_link\" ALT=\"x|\" SRC=\"../common/rex.png\">\r\n");
//	alert (sNext);
	var		sBody			=	"<CENTER>\r\n"
							+	sPrev
							+	"<SPAN CLASS=\"gal_count\">&nbsp;&nbsp;" + (iIndex+1) + "&nbsp;/&nbsp;" + iLen + "&nbsp;&nbsp;</SPAN>"
							+	sNext
							+	"<BR><BR>\r\n"
							+	"<IMG SRC=\""
							+	g_Gallery[iIndex].m_sLargeURL
							+	"\" WIDTH=\""
							+	g_Gallery[iIndex].m_iLargeWidth
							+	"\" HEIGHT=\""
							+	g_Gallery[iIndex].m_iLargeHeight
							+	"\" ALT=\""
							+	g_Gallery[iIndex].m_sTitleText
							+	"\" TITLE=\""
							+	g_Gallery[iIndex].m_sTitleText
							+	"\"><BR><BR>\r\n<SPAN CLASS=\"gal_caption\">"
							+	g_Gallery[iIndex].m_sCaptionTextL
							+	(g_Gallery[iIndex].m_bHasCaptionSep ? "<BR>\r\n" : "")
							+	g_Gallery[iIndex].m_sCaptionTextR
							+	"</SPAN>\r\n</CENTER>\r\n";
//	alert (sBody);
	return sBody;
}

function isValidGalleryIndex (iIndex, sWhere)
{
	if ((iIndex < 0) || (iIndex >= g_Gallery.length))
	{
		alert ("Error in " + sWhere + "(iIndex=" + iIndex + 
			   "): gallery index out of bounds (0 ... " + 
			   (g_Gallery.length-1) + ")");
		return false;
	}
	return true;
}

function onGalleryInvoke (iIndex)
{
	if (!isValidGalleryIndex (iIndex, "onGalleryInvoke"))
		return true;
	var		sLink				=	window.location.pathname;
	var		iSlashPos			=	window.location.pathname.lastIndexOf("/");
	if (iSlashPos >= 0)
		sLink					=	sLink.substr (iSlashPos + 1);
	window.open (sLink + "?" + iIndex, "_blank");
	return false;
}

function onGalleryPix (iIndex)
{
	if (!isValidGalleryIndex (iIndex, "onGalleryPix"))
		return true;
	document.body.innerHTML	=	galleryBody (iIndex);
	g_iGalleryIndex			=	iIndex;
	return false;
}

function onGalleryKey (e)
{
	if ((g_iGalleryIndex < 0) || (g_iGalleryIndex >= g_Gallery.length))
		return;
	var	iLast				=	g_Gallery.length - 1;
	var	iIndex				=	g_iGalleryIndex;
	// distinguish between IE's explicit event object (window.event) and Firefox's implicit.
	var objEvent			=	window.event ? event : e;
	var wcCode				=	objEvent.charCode ? objEvent.charCode : objEvent.keyCode;
	switch (wcCode)
	{
	case 33:	// pg-up
		iIndex				-=	10;
		break;
	case 34:
		iIndex				+=	10;
		break;
	case 35:	// end
		iIndex				=	iLast;
		break;
	case 36:	// home
		iIndex				=	0;
		break;
	case 37:	// up
	case 38:	// left
		--iIndex;
		break;
	case 39:	// right
	case 40:	// down
		++iIndex;
		break;
	case 27:
		window.close ();
		return;
	default:
//		alert ("event:onkeypress keyCode=" + wcCode);
		return;
	}
	if (iIndex < 0)
		iIndex				=	0;
	else if (iIndex > iLast)
		iIndex				=	iLast;
	if (iIndex == g_iGalleryIndex)
		return;
	onGalleryPix (iIndex);
}

function gallery_onDocLoaded ()
{
	g_iGalleryIndex			=	-1;
	if (window.location.search == "")
		return;
	var	sParam				=	window.location.search.substr(1);
	var	iIndex				=	isNaN(parseInt(sParam,10))
							?	indexOfGalleryURL (sParam)
							:	parseInt(sParam,10);
	if (iIndex < 0)
		return;
	var		sHTML			=	galleryBody (iIndex);
//	alert (sHTML);
	document.body.innerHTML	=	sHTML;
	g_iGalleryIndex			=	iIndex;
//	document.onkeypress		=	onGalleryKey;
	document.onkeyup		=	onGalleryKey;
}

/////////////////////////////////////////////////////////////////////////////
// deferred script invocation
// Dean Edwards/Matthias Miller/John Resig
// http://dean.edwards.name/weblog/2006/06/again/

function gallery_init() {
  // quit if this function has already been called
  if (arguments.callee.done) return;

  // flag this function so we don't do the same thing twice
  arguments.callee.done = true;

  // kill the timer
  if (_timer) clearInterval(_timer);

  // do stuff
  gallery_onDocLoaded ();
};

/* for Mozilla/Opera9 */
if (document.addEventListener) {
  document.addEventListener("DOMContentLoaded", gallery_init, false);
}

/* for Internet Explorer */
/*@cc_on @*/
/*@if (@_win32)
  document.write("<script id=__ie_onload defer src=javascript:void(0)><\/script>");
  var script = document.getElementById("__ie_onload");
  script.onreadystatechange = function() {
    if (this.readyState == "complete") {
      gallery_init(); // call the onload handler
    }
  };
/*@end @*/

/* for Safari */
if (/WebKit/i.test(navigator.userAgent)) { // sniff
  var _timer = setInterval(function() {
    if (/loaded|complete/.test(document.readyState)) {
      gallery_init(); // call the onload handler
    }
  }, 10);
}

/* for other browsers */
window.onload = gallery_init;
