//  ~/menus/mainscript.js
//
//  03-02-09


// --------------------------------------------------------------------------------------
// ------------------------- WriteImageTag
// --------------------------------------------------------------------------------------

function WriteImageTag(){

	var ran_images=new Array()

	//random images
	ran_images[1]="/images/header/finalpix01.jpg"
	ran_images[2]="/images/header/finalpix02.jpg"
	ran_images[3]="/images/header/finalpix03.jpg"
	ran_images[4]="/images/header/finalpix04.jpg"
	ran_images[5]="/images/header/finalpix05.jpg"

	var ry=Math.floor(Math.random()*ran_images.length)
	if (ry==0)
		ry=1
	//define height and width in td tag
	document.write('<img src="'+ran_images[ry]+'" border=0 width="551" height="200" '+
		'alt="St. Vincent de Paul Parish [ Lincoln Park, Chicago ]" '+
		'title="St. Vincent de Paul Parish [ Lincoln Park, Chicago ]" />')
}


// --------------------------------------------------------------------------------------
// ------------------------- launchWindow
// --------------------------------------------------------------------------------------

function launchWindow(source,name,features) {
	
	winref=window.open(source,name,features);
	winref.window.focus()
}


// --------------------------------------------------------------------------------------
// ------------------------- eventList, eventFullPix, eventClose
// --------------------------------------------------------------------------------------

//  global vars - required
//  var  evtitle="";            // appears centered at top of eventList & eventFullPix
//  var  evdesc="";             // appears centered below evtitle in eventList
//  var  evdir="";              // full path to photo dir, with trailing '/'
//  var  evphoto=new Array(     // photo array, used in eventList & eventFullPix
//     new Array("","",""),     // vars: photo filename, opt photo text, opt photo credit
//     new Array("","")         // opt ending array; if given photo filename must be empty
//  )

//  global vars - optional
//  var  evgeneralcredit="";    // general photo credit (any text), appears below evdesc
                                // in eventList
//  var  evphotocredit="";      // default photo credit (name), appears below right of photo
                                // in eventFullPix, overridden if opt photo credit given
//  var  evthumbnailprefix="";  // thumbnail prefix for photo filenames in eventList,
                                // if given, all photos need thumbnail & evthumbnailht unused

//  global vars w/defaults for eventList():
//  var  evthumbnailcols=3;     // num cols for thumbnail display
//  var  evthumbnailht=100;     // height of each thumbnail (width floats)
//  var  evthumbnailsp=16;      // spacing (in pixals) between thumbnails
//  var  evthumbnailspcol=0;    // column spacing (in num 'nbsp;') between thumbnails

//  global vars w/defaults for eventFullPix():
//  var  evfullpixwinht=660;    // full pix window height
//  var  evfullpixwinwd=870;    // full pix window width

//  global vars, optional for eventFullPix():
//  var  evfullpixht;           // full pix height
//  var  evfullpixwd;           // full pix width

//  Usage in a page:
//  1. add at top:  <!--#include virtual="/menus/func.aspx"-->
//  2. add javascript ref with:  src="<%=fix_query_value("jsf",".js","evdata.js")%>"
//  3. add to <body> tag:  onunload="eventClose()"
//  4. add to body section a script call:  eventList(opt-mainheader,opt-grouptitle)
//  Ref links to page:
//  5. setup photo dir with photos & setup evdata.js file
//  6. call page using query w/opt .js filename (eg):  ?jsf=/evphoto/20080714-theotap/

	//  global vars used in eventList, eventFullPix, eventClose
	var  evmainheader;           // main header, set in eventList call, used in eventFullPix
	var  evgrouptitle;           // group title, set in eventList call, used in eventFullPix
	var  evwinref;               // eventFullPix winref, used in eventClose


function eventList(mainheader,grouptitle) {

	//  mainheader:  optional main header, shown in eventFullPix
	//  grouptitle:  optional group title text, shown below mainheader, in eventFullPix

	var  pixcount;
	var  thumbnailprefix;
	var  thumbnailhtline;

	// set mainheader & grouptile
	evmainheader=(typeof(mainheader)=="undefined")? "" : mainheader;
	evgrouptitle=(typeof(grouptitle)=="undefined")? "" : grouptitle;

	// set global thumbnail var defaults if needed
	if(typeof(evthumbnailcols)=="undefined")
		evthumbnailcols=3;
	if(typeof(evthumbnailht)=="undefined")
		evthumbnailht=100;
	if(typeof(evthumbnailsp)=="undefined")
		evthumbnailsp=16;
	if(typeof(evthumbnailspcol)=="undefined")
		evthumbnailspcol=0;

	evthumbnailcolstotal=evthumbnailcols;
	if(evthumbnailspcol>0) {
		evthumbnailspcoltext="";
		for(i=0; i<evthumbnailspcol; i++)
			evthumbnailspcoltext+="&nbsp;"
		evthumbnailcolstotal+=evthumbnailcolstotal-1;
	}

	// set pixcount, adjust if last array has blank filename
	pixcount=(evphoto[evphoto.length-1][0]=="")? evphoto.length-1 : evphoto.length;

	// set thumbnail prefix and thumbnail height line
	thumbnailprefix="";
	thumbnailhtline=" height='"+evthumbnailht+"'";
	if(typeof(evthumbnailprefix)!="undefined") {
		thumbnailprefix=evthumbnailprefix;
		thumbnailhtline="";
	}

	document.writeln("<div class='divheader'>"+evtitle+"</div>");
	document.writeln("<div align='center'>"+evdesc+"</div>");
	if(typeof(evgeneralcredit)!="undefined" && evgeneralcredit!="")
		document.writeln("<div class='evcredit' align='center'><i>("+
		evgeneralcredit+")</i></div>");

	document.writeln("<table border='0' cellspacing='"+evthumbnailsp+"' cellpadding='0' "+
		"class='pagecopytable' align='center'>");
	document.writeln("<tr align='center'><td colspan='"+evthumbnailcolstotal+
		"' class='photocaption'>Click any image to view larger version &amp; caption.</td></tr>");
	for(i=0; i<pixcount; i++) {
		if(i%evthumbnailcols==0) {
			if(i!=0)
				document.writeln("</tr>");
			document.writeln("<tr align='center' valign='top'>");
		}
		document.writeln(
			"<td><a href='javascript:eventFullPix("+i+")' class='evlistanchor'>"+
			"<img src='"+evdir+thumbnailprefix+evphoto[i][0]+"'"+thumbnailhtline+
			" border='2' hspace='0' /></a><br>"+(i+1)+" of "+pixcount+"</td>");
		if(evthumbnailspcol!=0 && i%evthumbnailcols<evthumbnailcols-1) {
			document.writeln("<td>"+evthumbnailspcoltext+"</td>");
		}
	}
	document.writeln("</tr></table>");
}


function eventFullPix(pindex) {

	var  pixcount;
	var  prevpix;
	var  nextpix;
	var  photocreditline;
	var  winref;
	var  pixhtline;
	var  pixwdline;

	// set default full pix window height & width, if needed
	if(typeof(evfullpixwinht)=="undefined")
		evfullpixwinht=660;
	if(typeof(evfullpixwinwd)=="undefined")
		evfullpixwinwd=870;

	// set pix count and prev & next pix indexes
	pixcount=(evphoto[evphoto.length-1][0]=="")? evphoto.length-1 : evphoto.length;
	prevpix=(pindex==0)? pixcount-1 : pindex-1;
	nextpix=(pindex==pixcount-1)? 0 : pindex+1;

	// set photocreditline: specific for photo > general photo credit > blank
	photocreditline="&nbsp;";
	if(typeof(evphoto[pindex][2])!="undefined" && evphoto[pindex][2]!="")
		photocreditline="Photo Credit: "+evphoto[pindex][2];
	else if(typeof(evphotocredit)!="undefined" && evphotocredit!="")
		photocreditline="Photo Credit: "+evphotocredit;

	// set pixhtline, pixwdline, if needed
	pixhtline=(typeof(evfullpixht)=="undefined")? "" : " height='"+evfullpixht+"'";
	pixwdline=(typeof(evfullpixwd)=="undefined")? "" : " height='"+evfullpixwd+"'";

	winref=window.open("","_eventphoto","height="+evfullpixwinht+",width="+evfullpixwinwd+","+
		"menubar=yes,status=yes,toolbar=no,location=no,scrollbars=yes,resizable=yes");
	evwinref=winref;
	winref.document.writeln("<html><title>"+evtitle+"</title>");
	winref.document.writeln("<link rel='stylesheet' type='text/css' href='/menus/style.css'>");
	winref.document.writeln("<body link='#660000' alink='#660000' vlink='#660000'>");
	winref.document.writeln("<div class='pagecopy'>");
	if(evmainheader!="")
		winref.document.writeln("<div class='evheader'>"+evmainheader+"</div>");
	if(evgrouptitle!="")
		winref.document.writeln("<div class='evheader'>"+evgrouptitle+"</div>");
	winref.document.writeln("<br>");
	winref.document.writeln("<div class='evtitle'>"+evtitle+"</div><br>");
	winref.document.writeln("<div class='evnavig'>"+
		"<a href='javascript:opener.eventFullPix("+prevpix+")'>"+
		"&lt;&lt; Prev</a>&nbsp;&nbsp;&nbsp;&nbsp;"+
		"Photo:&nbsp;&nbsp;"+(pindex+1)+"&nbsp;&nbsp;of&nbsp;&nbsp;"+pixcount+
		"&nbsp;&nbsp;&nbsp;&nbsp;<a href='javascript:opener.eventFullPix("+nextpix+")'>"+
		"Next &gt;&gt;</a>&nbsp;&nbsp;&nbsp;"+
		"</div>");
	winref.document.writeln("<br>");
	winref.document.writeln("<table cellspacing='0' cellpadding='0' align='center' "+
		"class='pagecopytable'>");
	if(evphoto[pindex][1]!="")
		winref.document.writeln("<caption align='bottom'><div class='evphotocaption'>"+
			evphoto[pindex][1]+"</div></caption>");
	winref.document.writeln("<tr valign='top'>");
	winref.document.writeln("<td><img src='"+evdir+evphoto[pindex][0]+
		"' border='1'"+pixhtline+pixwdline+"></img></td>");
	winref.document.writeln("</tr>");
	winref.document.writeln("<tr><td align='right' class='evcredit'>"+photocreditline+
		"</td></tr>");
	winref.document.writeln("</table>");
	winref.document.writeln("</div>");
	winref.document.writeln("</body></html>");
	winref.document.close();
	winref.focus();
}


function eventClose() {

	if(typeof(evwinref)!="undefined" && ! evwinref.closed)
		evwinref.close();
}

