var IE4 = (document.all?true:false);
var NN4 = (document.layers?true:false);

function findCentre() {
	if (NN4) {
		document.NN4centre.left = (window.innerWidth - 700)/2;
	}
}

var fishwin;
function getBigPicture(n) {
	var w = (screen.width > 800?imgarray[n].width:Math.round(imgarray[n].width/2));
	var h = (screen.width > 800?imgarray[n].height:Math.round(imgarray[n].height/2));
	windoc = "<HTML><HEAD><TITLE>Really Wrecked Photos: " + imgarray[n].minicaption + "</TITLE><STYLE TYPE=\"text/css\">BODY{font-family:verdana,arial,helvetica,sans serif; background-color:#0094D3; color:#FFFFFF; font-size:" + (screen.width > 800?"11":(IE4?"9":"10")) + "px}TD{font-family:verdana,arial,helvetica,sans serif; background-color:#0094D3; color:#FFFFFF; font-size:" + (screen.width > 800?"11":(IE4?"9":"10")) + "px}.gap6{margin-bottom:6px}.gap12{margin-bottom:12px}.bold14{font-weight:bold;font-size:" + (screen.width > 800?"14":(IE4?"11":"12")) + "px}.bold12{font-weight:bold;font-size:" + (screen.width > 800?"12":(IE4?"10":"11")) + "px}.bold{font-weight:bold}</STYLE></HEAD><BODY onBlur=\"self.close();opener.fishwin=null;\"><DIV CLASS=\"gap6\"><DIV CLASS=\"bold14\">" + imgarray[n].captor + "</DIV></DIV>" + "<DIV CLASS=\"gap6\"><IMG SRC=\"../images/fish/" + imgarray[n].largepic + "\" WIDTH=" + w + " HEIGHT=" + h + " BORDER=0 ALT=\"\"></DIV><DIV CLASS=\"gap12\"><DIV CLASS=\"bold12\">Caption</DIV>" + imgarray[n].fullcaption + "</DIV><DIV CLASS=\"bold12\">Details</DIV><TABLE CELLPADDING=0 CELLSPACING=0 BORDER=0 WIDTH=\"100%\"><TR>" + (imgarray[n].species?"<TD WIDTH=\"49%\" VALIGN=TOP><SPAN CLASS=\"bold\">Species:</SPAN> " + (imgarray[n].species.indexOf("(non-fish)") != -1?imgarray[n].species.substring(0,imgarray[n].species.indexOf("(non-fish)")):imgarray[n].species) + "<BR>" + (imgarray[n].weight?"<SPAN CLASS=\"bold\">Weight:</SPAN> " + imgarray[n].weight + "<BR>":"") + (imgarray[n].record?"<SPAN CLASS=\"bold\">Current club record</SPAN><BR>":"") + "<SPAN CLASS=\"bold\">Photo by:</SPAN> " + imgarray[n].photographer + "</TD><TD WIDTH=\"2%\">&nbsp;</TD><TD WIDTH=\"49%\" VALIGN=TOP><SPAN CLASS=\"bold\">Skipper:</SPAN> " + imgarray[n].skipper + "<BR><SPAN CLASS=\"bold\">Boat:</SPAN> " + imgarray[n].boat + "<BR><SPAN CLASS=\"bold\">Port:</SPAN> " + imgarray[n].port + "<BR><SPAN CLASS=\"bold\">Date of trip:</SPAN> " + imgarray[n].date[0] + "/" + imgarray[n].date[1] + "/" + imgarray[n].date[2] + "</TD>":"<TD WIDTH=\"49%\" VALIGN=TOP><SPAN CLASS=\"bold\">Skipper:</SPAN> " + imgarray[n].skipper + "<BR><SPAN CLASS=\"bold\">Boat:</SPAN> " + imgarray[n].boat + "<BR><SPAN CLASS=\"bold\">Port:</SPAN> " + imgarray[n].port + "<BR></TD><TD WIDTH=\"2%\">&nbsp;</TD><TD WIDTH=\"49%\" VALIGN=TOP><SPAN CLASS=\"bold\">Date of trip:</SPAN> " + imgarray[n].date[0] + "/" + imgarray[n].date[1] + "/" + imgarray[n].date[2] + "<BR><SPAN CLASS=\"bold\">Photo by:</SPAN> " + imgarray[n].photographer + "</TD>") + "</TR></TABLE></BODY></HTML>";
	w = (imgarray[n].width < 300?w + 50:w + 20) + (screen.width > 800?0:15);
	h = (imgarray[n].minicaption == "Plaice galore"?(screen.width > 800?h+270:h+320):(imgarray[n].minicaption == "Andy's superb undulate"?h+220:h+210)) + (screen.width > 800?0:50);
	fishwin = window.open("","fishwin","WIDTH=" + w + ",HEIGHT=" + h + ",SCROLLBARS=NO,RESIZABLE=YES,DIRECTORIES=NO,BUTTONS=NO,LOCATION=NO,STATUS=NO,MENUBAR=NO");
	fishwin.document.write(windoc);
	fishwin.document.close();
	if (fishwin)
		fishwin.focus();
}

var opened = "";
function doSubMenu(x) {
	hideSubMenu("date");
	hideSubMenu("captor");
	hideSubMenu("species");
	hideSubMenu("port");
	hideSubMenu("skipper");
	if (opened == x) {
		hideSubMenu(x)
		opened = "";
	} else
		showSubMenu(x)
}

function showSubMenu(x) {
	var theObj = eval("document.all." + x + "box.style");
	theObj.position = "relative";
	theObj.visibility = "visible";
	opened = x;
//	theObj = eval("document.all." + x + "plus");
//	theObj.innerHTML = "-";
}

function hideSubMenu(x) {
	var theObj = eval("document.all." + x + "box.style");
	theObj.position = "absolute";
	theObj.visibility = "hidden";
//	theObj = eval("document.all." + x + "plus");
//	theObj.innerHTML = "+";
}

function makeMenu() {
	var captors = [];
	var species = [];
	var ports = [];
	var skippers = [];
	for (var i = 0; i < images.length; i++) {
		for (var j = 0; j < captors.length; j++) {
			if (captors[j] == images[i].captor)
				break;
		}
		if (j == captors.length && images[i].captor.split(" ").length <= 2)
			captors[captors.length] = images[i].captor;
		for (var j = 0; j < species.length; j++) {
			if (species[j] == images[i].species || (species[j].indexOf("non-fish") != -1 && images[i].species.indexOf("non-fish") != -1))
				break;
		}
		if (j == species.length && images[i].species)
			species[species.length] = images[i].species;
		for (var j = 0; j < ports.length; j++) {
			if (ports[j] == images[i].port)
				break;
		}
		if (j == ports.length)
			ports[ports.length] = images[i].port;
		for (var j = 0; j < skippers.length; j++) {
			if (skippers[j] == images[i].skipper)
				break;
		}
		if (j == skippers.length)
			skippers[skippers.length] = images[i].skipper;
	}
	captors.sort();
	species.sort();
	ports.sort();
	skippers.sort();
	var n = Math.floor(images.length/12) + (images.length%12?1:0);
	var datearray = sortImageArray(images);
	var menu = "<DIV CLASS=\"menubutton\"><A HREF=\"index.htm?show=all\">Show all pics</A></DIV>";
	menu += "<DIV CLASS=\"menubutton\"><A HREF=\"javascript:doSubMenu('date')\"><SPAN ID=\"dateplus\" CLASS=\"plusbox\">+</SPAN> Dates</A></DIV><DIV ID=\"datebox\" CLASS=\"menubox\">";
	var firstdate,lastdate;
	var months = ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];
	for (var i = n-1; i >= 0; i--) {
		firstdate = months[datearray[i*12].date[1]-1] + " '" + datearray[i*12].date[2].toString().substring(2);
		lastdate = (((i+1)*12) > datearray.length-1?months[datearray[datearray.length-1].date[1]-1] + " '" + datearray[datearray.length-1].date[2].toString().substring(2):months[datearray[((i+1)*12)-1].date[1]-1] + " '" + datearray[((i+1)*12)-1].date[2].toString().substring(2));
		var datetext = (firstdate != lastdate?lastdate + " - " + firstdate:firstdate);
		menu += "&nbsp;<A HREF=\"index.htm?show=date&page=" + (i+1) + "\">" + datetext + "</A><BR>";
	}
	menu += "</DIV><DIV CLASS=\"menubutton\"><A HREF=\"javascript:doSubMenu('captor')\"><SPAN ID=\"captorplus\" CLASS=\"plusbox\">+</SPAN> Captor</A></DIV><DIV ID=\"captorbox\" CLASS=\"menubox\">";
	for (var i = 0; i < captors.length; i++) {
		if (captors[i])
			menu += "&nbsp;<A HREF=\"index.htm?captor=" + captors[i] + "\">" + captors[i] + "</A><BR>";
	}
	menu += "</DIV><DIV CLASS=\"menubutton\"><A HREF=\"javascript:doSubMenu('species')\"><SPAN ID=\"speciesplus\" CLASS=\"plusbox\">+</SPAN> Species</A></DIV><DIV ID=\"speciesbox\" CLASS=\"menubox\">";
	for (var i = 0; i < species.length; i++) {
		menu += "&nbsp;<A HREF=\"index.htm?species=" + (species[i].indexOf("non-fish") == -1?species[i]:"non-fish") + "\">" + (species[i].indexOf("non-fish") == -1?species[i]:"non-fish") + "</A><BR>";
	}
	menu += "</DIV><DIV CLASS=\"menubutton\"><A HREF=\"javascript:doSubMenu('port')\"><SPAN ID=\"portplus\" CLASS=\"plusbox\">+</SPAN> Port</A></DIV><DIV ID=\"portbox\" CLASS=\"menubox\">";
	for (var i = 0; i < ports.length; i++) {
		menu += "&nbsp;<A HREF=\"index.htm?port=" + ports[i] + "\">" + ports[i] + "</A><BR>";
	}
	menu += "</DIV><DIV CLASS=\"menubutton\"><A HREF=\"javascript:doSubMenu('skipper')\"><SPAN ID=\"skipperplus\" CLASS=\"plusbox\">+</SPAN> Skipper</A></DIV><DIV ID=\"skipperbox\" CLASS=\"menubox\">";
	for (var i = 0; i < skippers.length; i++) {
		menu += "&nbsp;<A HREF=\"index.htm?skipper=" + skippers[i] + "\">" + skippers[i] + "</A><BR>";
	}
	menu += "</DIV><DIV CLASS=\"menubutton\"><A HREF=\"index.htm?record=true\">Club records</A></DIV>";
	return menu;
}

function makeNNMenu() {
	var captors = [];
	for (var i = 0; i < images.length; i++) {
		for (var j = 0; j < captors.length; j++) {
			if (captors[j] == images[i].captor)
				break;
		}
		if (j == captors.length && images[i].captor.split(" ").length <= 2)
			captors[captors.length] = images[i].captor;
	}
	captors.sort();
	var n = Math.floor(images.length/12) + (images.length%12?1:0);
	var datearray = sortImageArray(images);
	var menu = "<DIV CLASS=\"boldwhite12\"><A HREF=\"index.htm?show=all\">Show all pics</A></DIV><BR>";
	menu += "<DIV CLASS=\"boldwhite12\"><A HREF=\"index.htm?record=true\">Club records</A></DIV><BR>";
	menu += "<DIV CLASS=\"boldwhite12\">Dates</DIV><DIV CLASS=\"boldwhite10\">";
	var firstdate,lastdate;
	var months = ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];
	for (var i = n-1; i >= 0; i--) {
		firstdate = months[datearray[i*12].date[1]-1] + " '" + datearray[i*12].date[2].toString().substring(2);
		lastdate = (((i+1)*12) > datearray.length-1?months[datearray[datearray.length-1].date[1]-1] + " '" + datearray[datearray.length-1].date[2].toString().substring(2):months[datearray[((i+1)*12)-1].date[1]-1] + " '" + datearray[((i+1)*12)-1].date[2].toString().substring(2));
		var datetext = (firstdate != lastdate?lastdate + " - " + firstdate:firstdate);
		menu += "&nbsp;<A HREF=\"index.htm?show=date&page=" + (i+1) + "\">" + datetext + "</A><BR>";
	}
	menu += "</DIV><BR><DIV CLASS=\"boldwhite12\">Captor</DIV><DIV CLASS=\"boldwhite10\">";
	for (var i = 0; i < captors.length; i++) {
		if (captors[i])
			menu += "&nbsp;<A HREF=\"index.htm?captor=" + escape(captors[i]) + "\">" + captors[i] + "</A><BR>";
	}
	menu += "</DIV>";
	return menu;
}

function sortImageArray(arr) {
	var tmp;
	for (var i = 0; i < arr.length; i++) {
		for (var j = i+1; j < arr.length; j++) {
			if (arr[i].date[2] < arr[j].date[2]) {
				tmp = arr[i];
				arr[i] = arr[j];
				arr[j] = tmp;
			} else if (arr[i].date[2] == arr[j].date[2]) {
				if (arr[i].date[1] < arr[j].date[1]) {
					tmp = arr[i];
					arr[i] = arr[j];
					arr[j] = tmp;
				} else if (arr[i].date[1] == arr[j].date[1]) {
					if (arr[i].date[1] < arr[j].date[1]) {
						tmp = arr[i];
						arr[i] = arr[j];
						arr[j] = tmp;
					}
				}
			}
		}
	}
	return arr;
}

var imgarray = [];
var page = 1;
var viewtype = "show";
var viewval = "all";
function buildImageArray() {
	var s = unescape(location.search);
	while (s.indexOf("+") != -1) {
		s = s.substring(0,s.indexOf("+")-1) + " " + s.substring(s.indexOf("+")+1);
	}
	if (s) {
		if (s.indexOf("&") != -1) {
			viewtype = s.substring(1,s.indexOf("="));
			viewval = s.substring(s.indexOf("=")+1,s.indexOf("&"));
			page = parseInt(s.substring(s.indexOf("&")+6));
		} else {
			viewtype = s.substring(1,s.indexOf("="));
			viewval = s.substring(s.indexOf("=")+1);
		}
		if (viewtype == "show" && viewval == "all")
			imgarray = images;
		else {
			for (var i = 0; i < images.length; i++) {
				if (viewtype == "record" && eval("images[i]." + viewtype) == eval(viewval))
					imgarray[imgarray.length] = images[i];
				else if (viewtype != "record" && viewval != "date" && eval("images[i]." + viewtype).indexOf(viewval) != -1)
					imgarray[imgarray.length] = images[i];
				else if (viewval == "date")
					imgarray = images;
			}
		}
	} else
		imgarray = images;
	imgarray = sortImageArray(imgarray);
}

function renderAlbum() {
	buildImageArray();
	var album = (NN4?"<LAYER ID=\"NN4centre\">":"<DIV ALIGN=CENTER>") + "<TABLE CLASS=\"greenborder\" CELLPADDING=3 CELLSPACING=0 BORDER=0 BGCOLOR=\"FFFFF0\" WIDTH=" + (NN4?"600":"705") + "ALIGN=CENTER><TR>" +  (IE4?"<TD CLASS=\"white10ongreen\" ROWSPAN=7 WIDTH=105 VALIGN=TOP><DIV CLASS=\"size16\">&nbsp;</DIV><DIV CLASS=\"menubutton2\">Pic 'n' mix</DIV>" + makeMenu() + "</TD>":"<TD CLASS=\"white10ongreen\" ROWSPAN=7 WIDTH=105 VALIGN=TOP><DIV CLASS=\"size16\">&nbsp;</DIV><DIV CLASS=\"NNmenubutton2\">Pic 'n' mix</DIV>" + makeNNMenu() + "</TD>") + "<TD CLASS=\"whitebold16ongreencentred\" COLSPAN=5>Really Wrecked photo album</TD></TR><TR><TD COLSPAN=4><DIV CLASS=\"gap6\">To view an image at full size with a caption, click on any of the thumbnails below. If the text doesn't fit, grab the bottom edge of the window and stretch it until it does." + (IE4?" Click one of the Pic 'n' mix buttons to view the pictures according to who caught what, and on which boat etc.":" You can also jump straight to a certain period of club 'history' or view a club member's photos by clicking on a link on the left.") + "</DIV><DIV CLASS=\"bold\">" + (viewtype == "show"?"":(viewval=="true"?"Club records: ":viewval + ": ")) + "There " + (imgarray.length > 1?"are ":"is ") + imgarray.length + " photo" + (imgarray.length > 1?"s ":" ") + (viewtype == "show"?"in total":"in this category") + " with the most recent shown first</DIV></TD></TR>";
	for (var i = (12*(page-1)); i < (12*page); i++) {
		if (!(i%4))
			album += "<TR>";
		album += (imgarray[i]?"<TD WIDTH=\"150\" ALIGN=CENTER CLASS=\"size10\" HEIGHT=130><A HREF=\"javascript:getBigPicture(" + i + ")\"><IMG SRC=\"../images/fish/" + imgarray[i].smallpic + "\" WIDTH=" + (screen.width > 800?"100":"60") + " HEIGHT=" + (screen.width > 800?"100":"60") + " BORDER=0 ALT=\"" + imgarray[i].minicaption + "\"></A><BR>" + imgarray[i].minicaption + "</TD>":"<TD WIDTH=\"150\" HEIGHT=130 CLASS=\"size1\">&nbsp;</TD>");
		if (i%4 == 3)
			album += "</TR>";
	}
	album += (imgarray.length > 12?"<TR><TD COLSPAN=2 WIDTH=\"300\" ALIGN=RIGHT>" + (page > 1?"<A CLASS=\"greenbold\" HREF=\"index.htm?" + viewtype + "=" + escape(viewval) + "&page=" + (page-1) + "\"><IMG SRC=\"../images/site/button_album_more_active.gif\" WIDTH=96 HEIGHT=25 BORDER=0 ALT=\"More recent pics\"></A>&nbsp;":"<IMG SRC=\"../images/site/button_album_more_inactive.gif\" WIDTH=96 HEIGHT=25 BORDER=0 ALT=\"More recent pics\">") + "</TD><TD COLSPAN=2 WIDTH=\"300\" ALIGN=LEFT>&nbsp;" + (page*12 < imgarray.length?"<A CLASS=\"greenbold\" HREF=\"index.htm?" + viewtype + "=" + escape(viewval) + "&page=" + (page+1) + "\"><IMG SRC=\"../images/site/button_album_less_active.gif\" WIDTH=96 HEIGHT=25 BORDER=0 ALT=\"Less recent pics\"></A>":"<IMG SRC=\"../images/site/button_album_less_inactive.gif\" WIDTH=96 HEIGHT=25 BORDER=0 ALT=\"Less recent pics\">") + "</TD></TR>":"");
	album += "<TR><TD COLSPAN=4 CLASS=\"size1\">&nbsp;</TD></TR>";
	album += "<TR><TD CLASS=\"whitebold10ongreencentred\" COLSPAN=5>-- <A HREF=\"../index.htm\">home</A>|<A HREF=\"../about/index.htm\">about RWSAC</A>|<A HREF=\"../records.htm\">records</A>|<A HREF=\"../newsletters/index.htm\">newsletters</A>|<A HREF=\"../news/index.htm\">news</A>|<A HREF=\"../nothing.htm\">rigs and tactics</A>|<A HREF=\"index.htm\">pictures</A> --<BR><A HREF=\"http://www.beetlebrow.co.uk\">web design and hosting by Beetlebrow</A><BR></TD></TR>";
	album += "</TABLE>" + (NN4?"</LAYER>":"</DIV>");
	document.writeln(album);
	if (IE4) {
		if (viewtype != "record" && viewval != "all") {
			var submenu = (viewtype == "show"?viewval:viewtype);
			var theObj = eval("document.all." + submenu + "box.style");
			theObj.position = "relative";
			theObj.visibility = "visible";
			opened = submenu;
		}
	}
}


renderAlbum();