// Copyright 2003-2005, Stuart Massey (smassey@ibss.net).  All rights reserved. 
function getCookie(nam) {

        var x = document.cookie.split("; ");

        for (i=0; i<x.length; i++)
        {
                var y = x[i].split("=");
                if (y[0] == nam)
		{	
			return y[1];
		}
        }

	return "";
}

function getImagesVisited() {
	if (visitedInit > 0)
		return;
	var vCookVal= getCookie(vCookName);
	var vCookVisited = vCookVal.split(",");
	for (var i=0; i<galleryImages.length/5; i++)
		galleryVisited[i] = 0;
	for (var i=0; i<vCookVisited.length; i++)
		galleryVisited[vCookVisited[i]] = 1;
	visitedInit = 1;
}

function getCategoriesVisited() {
	if (visitedInit > 1)
		return;
	getImagesVisited();
	for (var cat=0; cat<gCategories.length; cat++)
	{
		var ct = 0;
		var latest = -1;
		for (var i=0; i<gCatLists[cat].length; i++)
		{
			if (galleryVisited[gCatLists[cat][i]] == 0)
				ct++;
			if (gCatLists[cat][i] > latest)
				latest = gCatLists[cat][i];
		}
		gCatNew[cat] = ct;
		for (var i=galleryDates.length; i>0; i=i-2)
			if (galleryDates[i-2] <= latest)
			{
				gCatDates[cat] = galleryDates[i-1];
				break;
			}
	}
	visitedInit = 1;
}

function setCategoryVisited(cat) {
	getImagesVisited();
	for (var i=0; i<gCatLists[cat].length; i++)
		galleryVisited[gCatLists[cat][i]] = 1;
	gCatNew[cat] = 0;
	setVisitedCookie();
}

function setVisitedCookie() {
	var newCook = "";

	for (var i=0; i<galleryVisited.length; i++)
		if (galleryVisited[i] != 0)
			if (newCook == "")
				newCook = "" + i;
			else
				newCook = newCook + "," + i;

	document.cookie = vCookName + "=" + newCook + "; expires=Fri, 31 Dec 2004 23:59:59 GMT;path=/";
}


function galleryWin(cat) {
//	window.alert("/cgi-bin/imgList?" + cat + "," + gCategories[cat]);
//	setCategoryVisited(cat);
	location.replace("/cgi-bin/imgList?" + cat + "," + gCategories[cat]);
}

var gCategories = new Array (
    "Tandems"	// 0
   ,"AFF"	// 1
   ,"Relative Work"	// 2
   ,"Free Fly"	// 3
   ,"Tracking"	// 4
   ,"Hybrids"	// 5
   ,"Canopies"	// 6
   ,"Exits"	// 7
   ,"Odds and Ends"	// 8
   ,"Demos"	// 9 
   ,"Parties"	// 10
   ,"Pies"	// 11
   ,"People"	// 12
);

var gCatLists = new Array(13);
gCatLists[0] = new Array(2,8,10,14,21,22,23,26,27,28,30,31,32,34,37,40,41,47,81,82);	// Tandems
gCatLists[1] = new Array(38,39);	// AFF
gCatLists[2] = new Array(25,35,42,50,51,53,66,67,84,85); 	// RW
gCatLists[3] = new Array(3,4,5,6,7,12,17,24,29,36,42,45,52,74,75,76,78,83);	// FF
gCatLists[4] = new Array("11");	// Tracking
gCatLists[5] = new Array("42");	// Hybrids
gCatLists[6] = new Array(9,15,16,18,19,20,33,39,40,41);	// Canopies
gCatLists[7] = new Array(23,26,28,30,31,32,34,37,43,44);	// Exits
gCatLists[8] = new Array(2,9,36,67,68,73,85,86,87);	// Odds & Ends
gCatLists[9] = new Array(0,1,2);	// Demos
gCatLists[10] = new Array(56,57,58,59,60,61,62,63,64);	// Parties
gCatLists[11] = new Array(48,49,54,55,79,80);	// Pies
gCatLists[12] = new Array(0,1,46,65,69,70,71,72,77,87,88);	// People

var galleryImages = new Array(
  "Demo.jpg",		"Camp Happy Days Demo, July 5", 			"",			640, 480 // 0, Apr 22, 2003
 ,"10000002.jpg",	"Camp Happy Days Demo, July 5", 			"",			640, 480 // 1
 ,"10000062.jpg",	"Camp Happy Days Demo, July 5", 			"",			640, 480 // 2
 ,"shes_got_it.jpg",	"She's got it!", 					"",			480, 360 // 3
 ,"jeffbig_2.jpg",	"Jeff", 						"",			640, 480 // 4
 ,"julie_2.jpg",	"Julie", 						"",			640, 480 // 5
 ,"Sunset_Freefly.jpg",	"Sunset Freefly", 					"",			480, 360 // 6
 ,"Peace_2.jpg",	"Peace", 						"",			640, 480 // 7
 ,"tandem1_2.jpg",	"Tandem", 						"",			862, 514 // 8
 ,"RandK.jpg",		"PC CRW, anyone ?", 					"",			640, 480 // 9
 ,"KB0321.jpg",		"", 							"",			293, 380 // 10
 ,"photo_track.jpg",	"Tracking", 						"",			480, 360 // 11
 ,"Sit_fly.jpg",	"Gather round the campfire", 				"",			640, 480 // 12
 ,"KB0367.jpg",		"", 							"",			253, 174 // 13
 ,"10000059.jpg",	"", 							"",			640, 480 // 14
 ,"wpe2.jpg",		"CRW from the inside", 					"",			640, 480 // 15
 ,"10000027.jpg",	"CRW from the inside", 					"",			640, 480 // 16
 ,"conquistador.jpg",	"Conquistador", 					"",			480, 360 // 17
 ,"Joeunder120-2.jpg",	"SieteCinco under canopy", 				"",			299, 359 // 18
 ,"Freak_under_canopy.jpg","Freak under canopy", 				"",			640, 480 // 19
 ,"dusk_129.jpg",	"Under canopy at dusk", 				"",			480, 413 // 20
 ,"geek_for_me.jpg",	"Geek for me...", 					"",			480, 360 // 21
 ,"KB0317.jpg",		"", 							"",			367, 239 // 22
 ,"KB0318.jpg",		"", 							"",			385, 265 // 23
 ,"10000041.jpg",	"Jalisco", 						"Jason Hulett",		640, 480 // 24
 ,"4-way_Sunset.jpg",	"Sunset 4-way", 					"",			640, 480 // 25
 ,"BF0342.jpg",		"", 							"",			163, 218 // 26
 ,"De0301.jpg",		"", 							"",			300, 400 // 27
 ,"DE0362.jpg",		"", 							"",			213, 302 // 28
 ,"Estilo_heddwn_2.jpg","Estilo head-down", 					"",			640, 480 // 29
 ,"KB0316.jpg",		"", 							"",			300, 400 // 30
 ,"KB0357.jpg",		"", 							"",			300, 400 // 31
 ,"KB0380.jpg",		"", 							"",			300, 400 // 32
 ,"kenlanding_2.jpg",	"Touchdown", 						"",			640, 480 // 33
 ,"wpe3.jpg",		"Pierre Cilliers prepares to exit with his tandem student","Joe Funderburk", 	480, 640 // 34
 ,"wpe7.jpg",		"5-way", 						"", 			546, 414 // 35
 ,"PointyRain.jpg",	"Proof that raindrops have pointy ends...", 		"Joe Funderburk",	640, 480 // 36
 ,"Tandem-Exit-Geek.jpg","Pierre Cillier's tandem student geeks for the camera","Joe Funderburk",	640, 480 // 37
 ,"AFFpullTime.jpg",	"Pull time for Nayong on her AFF level 1 jump", 	"Brent Neely",		640, 480 // 38
 ,"AFFdeployed.jpg",	"Nayong's canopy deploys on her AFF level 1 jump", 	"Brent Neely",		640, 480 // 39
 ,"scottTandem1.jpg",	"Scott Weed and a tandem student", 			"Keith Rudd",		360, 240 // 40
 ,"tandemDeploy.gif",	"Scott Weed and a tandem student deploy", 		"Keith Rudd",		360, 240 // 41
 ,"nadiaScottKeith.jpg","Scott and Keith dock on Nadia", 			"Robin Kellam",		600, 400 // 42
 ,"joeCessna.jpg",	"Joe hanging out on a sunset Cessna load", 		"",			640, 480 // 43
 ,"robinCasa.jpg",	"Robin exits the Casa", 				"",			640, 388 // 44
 ,"KamiFreakSunset.jpg","Kami and Freak at sunset", 				"Joe Funderburk",	481, 402 // 45
 ,"gravity_bomb.jpg",	"Gravity Bomb, 2003", 					"Jackie Smith",		316, 197 // 46, Jan 8, 2004
 ,"dane.jpg",		"Dane's Tandem",					"Keith Rudd",		640, 480 // 47, Feb 6, 2004
 ,"waynePie.jpg",	"Wayne Page gets pied after his 2000th",		"MaryAnne BAnich",	330, 540 // 48
 ,"mePie.jpg",		"Stuart Massey, pied for his 200th",			"Amanda Younggreen",	730, 670 // 49
 ,"cmCrank.jpg",	"Critical Mass crankin'",				"Joe Funderburk",	740, 310 // 50
 ,"missing2.jpg",	"Missing slot -- missing another one",			"Joe Reed",		300, 300 // 51, Feb 10, 2004
 ,"freak1000.jpg",	"Freak docks on Joe on Freak's 1000th",			"Tom Morton",		640, 480 // 52
 ,"freak1001.jpg",	"Jeff organizes a 9-way, celebrating Freak's 1000th",	"Tom Morton",		640, 480 // 53
 ,"freakPie.jpg",	"Freak gets pied for his 1000th",			"Tom Morton",		640, 480 // 54
 ,"elvisiopie.jpg",	"Elvisio, pied after 1000",				"Stuart Massey",	350, 404 // 55, Mar 22, 2004
 ,"mariejeff.jpg",	"Marie &amp; Jeff after dark",				"Stuart Massey",	400, 500 // 56
 ,"keiths.jpg",		"Two Keiths",						"Stuart Massey",	500, 400 // 57
 ,"kamimarcus.jpg",	"Kami &amp; Marcus",					"Stuart Massey",	500, 400 // 58
 ,"kamihankfire.jpg",	"Kami &amp; Hank discuss the fire",			"Stuart Massey",	500, 400 // 59
 ,"talkingshelter.jpg",	"Freefliers after dark",				"Stuart Massey",	500, 400 // 60
 ,"kami.jpg",		"Kami enjoys a good joke",				"Stuart Massey",	400, 500 // 61
 ,"aroundthefire.jpg",	"Jumpers around the fire",				"Stuart Massey",	500, 400 // 62
 ,"marietinya.jpg",	"Marie &amp; Tinya wind down with a beer",		"Stuart Massey",	500, 400 // 63
 ,"marcus.jpg",		"Marcus on the deck",					"Stuart Massey",	400, 500 // 64
 ,"iwantyou.jpg",	"Jack wants you to come skydive",			"Stuart Massey",	400, 500 // 65
 ,"10way.jpg",		"10-way",						"Robin Kellam",		600, 480 // 66
 ,"17way.jpg",		"17-way, organized by Jeff Wragg",			"Robin Kellam",		500, 400 // 67
 ,"birdmanexit.jpg",	"Joe Reid exits in his birdman suit",			"Keith Wilbur",		640, 480 // 68, Mar 29, 2004
 ,"winners.jpg",	"Winners at 2004 CaSL meet #1",				"MaryAnne Banich",	600, 500 // 69, Apr 21, 2004
 ,"winrobin.jpg",	"Robin - best videographer at 2004 CaSL meet #1",	"MaryAnne Banich",	400, 500 // 70
 ,"winmass.jpg",	"Critical Mass - 2nd in intermediate at 2004 CaSL meet #1","MaryAnne Banich",	500, 500 // 71
 ,"winslot.jpg",	"Missing Slot - 1st in I-class at 2004 CaSL meet #1",	"MaryAnne Banich",	400, 575 // 72
 ,"BSA_Grasscutter.jpg","How fast can YOU cut the grass?",			"Christian Logan",	572, 390 // 73 Apr 28, 2004
 ,"MarquisOverBSA.jpg",	"Marquis head-down over BSA",				"Rich Whitney",		382, 382 // 74 Jun 21, 2004
 ,"TomBall.jpg",	"Tom head-down with the Ball",				"Rich Whitney",		360, 543 // 75 Jun 29, 2004
 ,"TomFreakDZ.jpg",	"Tom and El Freako over the DZ",			"Rich Whitney",		334, 500 // 76 Jan 3, 2005
 ,"affiAwards.jpg",	"Jack &amp; Keith get their AFFI ratings",		"Joe Funderburk",	300, 400 // 77 Feb 17, 2005
 ,"MarquisJudiceJalisco.jpg","Marquis, Papachulo &amp; Jalisco head-down",	"Jason Hulett",		640, 480 // 78 
 ,"pie-jack.jpg",	"Jack gets pied for his 2000th (and his birthday)",	"Gene Stuart",		500, 500 // 79 Mar 23, 2005
 ,"tom1000.jpg",	"Tom gets pied for his 1000th",				"Gene Stuart",		400, 600 // 80 
 ,"jason-tandem.jpg",	"Jason Judice videos a tandem skydive",			"Noah Bullock",		500, 500 // 81 Aug 16, 2005
 ,"jason-getting-the-opening.jpg","Jason Judice captures a tandem opening",	"Noah Bullock",		550, 550 // 82 
 ,"joeSit.jpg",		"Joe sit-flying",					"Noah Bullock",		600, 400 // 83 Sep 27, 2005
 ,"keithCoaching.jpg",	"Keith and Joe Rich on a two-way",			"Noah Bullock",		600, 400 // 84
 ,"tumble.jpg",		"Cliff Derreth hones his rw skills",			"Noah Bullock",		600, 400 // 85
 ,"leegearcheck.jpg",	"Lee Crouch gets a gear check before a camo jump",	"Alice Massimi",	600, 450 // 86 Oct 19, 2005
 ,"BDU-Jump2.jpg",	"A camo jump group shot",				"Alice Massimi",	600, 457 // 87
 ,"keithandlee.jpg",	"Keith Rudd and Lee Crouch",				"Alice Massimi",	600, 450 // 88
);

var galleryDates = new Array(
	  0, "Apr 22, 2003"
	,46, "Jan 8, 2004"
	,47, "Feb 6, 2004"
	,51, "Feb 10, 2004"
	,55, "Mar 22, 2004"
	,68, "Mar 29, 2004"
	,69, "Apr 21, 2004"
	,73, "Apr 28, 2004"
	,74, "Jun 21, 2004"
	,75, "Jun 29, 2004"
	,76, "Jan 3, 2005"
	,77, "Feb 17, 2005"
	,79, "Mar 23, 2005"
	,81, "Aug 16, 2005"
	,83, "Sep 27, 2005"
	,86, "Oct 19, 2005"
);


var vCookName = "bsaGalleryVisited";
var galleryVisited = new Array(galleryImages.length / 5);
var gCatNew = new Array(gCategories.length);
var gCatDates = new Array(gCategories.length);
var visitedInit = 0;

