/* Numbers to reuse since KANDD removed
photos_154.htm
photos_155.htm
*/
var thumbcyc = [];
var tcx = 0;
var thumbhi = 94;// HHH

function localInit() {
try {pageInit()} catch (e) {;}
if (idonly.length>3) rotateInit();
if (localflag) document.getElementById("IDcontent").ondblclick = whatpics;
}

function putpics(){
for (var x=0;x<document.images.length;x++)	{
	if (document.images[x].getAttribute("cycle"))	{
		thumbcyc[tcx]=document.images[x];
		tcx++;
		littlepics = document.images[x].getAttribute("cycle");
		picarray = littlepics.split(",")
		newimage = picarray[(picarray.length-1).rnd()+1];
		newimage = "../" + picarray[0] + "/thumbs/b_" + newimage + ".jpg";
		document.images[x].src = newimage;
		}
	}
tcx=0;
}

function randchange(){
tcx++;
if (tcx == thumbcyc.length) tcx = 0;
obj = thumbcyc[tcx];
oldimage = obj.src.substring(obj.src.lastIndexOf("/")+3,obj.src.length-4);
newimage = oldimage;
littlepics = obj.getAttribute("cycle");
picarray = littlepics.split(",")
while (oldimage == newimage) {newimage = picarray[(picarray.length-1).rnd()+1]}
newimage = "../" + picarray[0] + "/thumbs/b_" + newimage + ".jpg";
if (document.all) obj.filters[0].Apply();
obj.src = newimage;
if (document.all) obj.filters[0].Play();

}

var thumbs_db = [];
function gallerise() {

make_thumbs_db(spath);// function in common.js - thumbs_db becomes a subset of menu_db
//delete for non gallery entries
for (var x=thumbs_db.length-1;x>0;x--){
	var thumbs = thumbs_db[x].split("|");
	if (thumbs[2].split("/")[1].slice(0,6) != "photos") thumbs_db.splice(x,1);
	}

for (var x=0;x<thumbs_db.length;x++) {
	
	var gal_page = thumbs_db[x].split("|");
	var thumbs = [];
	var tbit = gal_page[2].split("_")[1].slice(0,-4);
	for (var y = 0; y < 1*gal_page[10]; y++) {thumbs.push(tbit + "" + prezero(y+1,2));}
	thumbs.shuffle();
	var cyclepics = thumbs.join(",");
	cyclepics = spath + "," + cyclepics;

	document.writeln("<div class=albumbox>");
	document.writeln("<div class=rollbox photos=" + cyclepics + " onClick=self.location=\'../" + gal_page[2] + "\' title=\'Click to go to this album\'><img");
	document.writeln("src=../" + spath + "/thumbs/b_" + thumbs[1] + ".jpg class=two><img");
	document.writeln("src=../" + spath + "/thumbs/b_" + thumbs[0] + ".jpg class=one ></div>");
	document.writeln("<div class=albumcard>");
	document.writeln("<h4 style=font-size:14px;margin-bottom:5px;>" + gal_page[1] + "</h4>");
	document.writeln("<p style=font-size:12px;margin:0px;line-height:120%;>" + gal_page[3] + "<br><br>");

	upto = average(gal_page[5]);
	codeline = "";	
	if (upto>0) {
	codeline = "<span class=help title=\'" + upto + " star rating for this page\'>";
	for (var y=0;y<upto;y++)	{codeline+="<img src=../home/graphics/starsmall.gif height=12 width=12>"}
	codeline += "</span>"
	}

	document.writeln(gal_page[9] + " photos on this page. " + codeline + "</p>");
	document.writeln("</div>");
	document.writeln("</div>");
	}	
}
//===================================================
//3 Sep 2007

function rotateInit(){
var temp = document.getElementsByTagName("DIV");
for (var x=0;x<temp.length;x++) {
	if (temp[x].className=="rollbox") {
		temp[x].setAttribute("pre",false);
		rollbox.push(temp[x]);
		temp[x].onmouseover = redit;
		temp[x].onmouseout = whiteit;
		}
	}
rep = document.getElementById("report");
xxx = 2000/rollbox.length;
rotater(rollbox[cub]);

}
//==================================

var tim = 20;
var inc = 10;

var one = new Object;
var two = new Object;
var rollbox = [];
var pi = Math.PI;
var fortyfive = pi/4;
var rbindex = -fortyfive;
var rad = thumbhi / Math.sqrt(2);// HHH
var cub = 0;

//==================================
//function rotatestart() {
//obj = this;
//rotater(obj);
//}
//----------------------------------
function rotater(obj) {
var h1 = H(rbindex);
var h2 = H(rbindex+(pi/2));
var h3 = H(rbindex+pi);
one = obj.childNodes[1];
two = obj.childNodes[0];
rad = thumbhi / Math.sqrt(2);// HHH

if (obj.getAttribute("pre") && rbindex == -fortyfive) {
	presetroll(obj);
	}
obj.setAttribute("pre",true);

one.style.top = h2;
one.style.height = h3 - h2;

two.style.top = h1;
two.style.height = h2 - h1;

rbindex += fortyfive/inc;
tim = 20;
if (rbindex > fortyfive) {
	rbindex = -fortyfive;
	cub++;
	if (cub==rollbox.length) cub = 0;
	tim = 2000/rollbox.length; //variable to pause box between rolls
	}
setTimeout("rotater(rollbox[cub])",tim);
}
//---------------------------------
function presetroll(obj) {
one = obj.childNodes[1];
two = obj.childNodes[0];

one.src = two.src;

var twopic = two.src.substring(two.src.lastIndexOf("b_"));

var picarray = rollbox[cub].getAttribute("photos").split(","); 
var sub_dir = picarray[0]; // firstitem in the array is the subdirectory eg "2006"
var newpic = picarray[1]; // default if present pic is the last in the array

for (var x = 1; x <picarray.length-1 ; x++) {
	if ("b_" + picarray[x] + ".jpg" == twopic) newpic = picarray[x+1];
	}
two.src = "../" + sub_dir + "/thumbs/b_" + newpic + ".jpg";
}

//---------------------------------
function H(angle) {
return Math.round(rad*(1-Math.cos(angle)));
}
//---------------------------------
function redit() {
this.style.borderColor = "#cdf";
this.style.backgroundColor = "#cdf";
}
//---------------------------------
function whiteit() {
this.style.borderColor = "white";
this.style.backgroundColor = "white";
}
//---------------------------------

function whatpics() {
var ims = document.getElementById("IDcontent").getElementsByTagName("IMG");
var lst = [];
for (var x=0;x<ims.length;x++) {
	var scc = ims[x].src;
	var sra = scc.split("/");	
	if (scc.substring(scc.length-4) == ".jpg") lst.push(sra[sra.length-1]);// + "\t" + ims[x].width + "x" + ims[x].height);
	}
lst = uniqueArray(lst);
alert(lst.join("\n") + "\n\n" + lst.length + " photos");
}
