poswitch = false;
if (document.location.hash == "#pos") poswitch = true; 

var msnindex= [];
var msnpics = [];

function localInit() {
prebox();
try {pageInit()} catch (e) {;}
//reBadge();
}

//====================================
// find badges sent by a person and flashes them

var counter = 0;
var boxer;
var flashnum = 20;
var flashrate=500;
var nam = new String;

//------------------------------------
function prebox()	{
if (urlsrch != "") box(urlsrch);
}
//------------------------------------
function box(contributor)	{
nam = contributor;
for (var x=0; x<document.images.length; x++)	{
    if (document.images[x].alt.indexOf(unescape(nam))>-1) {
	document.images[x].scrollIntoView();
	x = document.images.length;
	}
    }
flashnum=0;
unbox();
flashnum=20;
cycle();
}

//------------------------------------
function cycle() {
setTimeout(rebox,flashrate);
}

//------------------------------------
function rebox()	{
flashnum--;
numimg = document.images.length;
for (var x=0; x<numimg; x++)	{
    if (document.images[x].alt.indexOf(unescape(nam))>-1) {
	document.images[x].style.filter="Xray";
	document.images[x].style.backgroundColor="red";
	}
    }
setTimeout(unbox,flashrate);
}

//------------------------------------
function unbox()	{
numimg = document.images.length;
for (var x=0; x<numimg; x++)	{
	document.images[x].style.filter="none";
	document.images[x].style.backgroundColor="transparent";
	}
if (flashnum>0) setTimeout(rebox,flashrate);
}

//========================================================
// opens a form for rally report

function badger(rally)    {
newWindow=window.open('../forms/formrally.htm?' + rally , 'formwin','width=470,height=420,left=165,top=150');
}

//========================================================
function unthumb(pic) {
p = pic.src.lastIndexOf("/s_");
ELmainpic = document.getElementById("mainpic");
ELmainpic.src = "graphics/" + pic.src.substring(p+1);
ELmainpic.title = "Please wait for the big picture";

var bigphoto = "graphics/" + pic.src.substring(p+3);
if (msnpics.length>0) {
	var keypic = pic.src.substring(p+3).slice(0,-4);
	for (var x=0;x<msnpics.length;x++) {
		var keybit = msnpics[x].split("/");
		if (keybit[1] == keypic) bigphoto = "http://kokqvw.bay.livefilestore.com/" + msnpics[x] + ".jpg"
		}
	}
ELmainpic.src = bigphoto;
ELmainpic.title = "Click to close";
ELmainpic.style.border = "1px solid navy";
document.getElementById("pictitle").innerHTML = pic.title;
document.getElementById("IDframe").style.top = (pic.offsetTop-10) + "px";
document.getElementById("IDframe").style.display = "block";
alert("Please email Ben that this page needs updating\nThanks");
}

//------------------------------------
function frameclose(obj) {
obj.style.display='none';
document.getElementById("mainpic").src = "../home/graphics/blank.gif";
}

//------------------------------------
function dunloadin() {
document.getElementById("pictitle").style.display = "block";
}

//------------------------------------
function precap(obj) {
// needs dunloadin() in the last pre image
document.getElementById("IDframe").style.top= obj.offsetTop;
}

//------------------------------------

var ReportCount = 0;
var ReportList = "";

function badgeSet() {
var LastRally = "";
for (var x=0;x<badge_db.length;x++) {
	var badge_field = badge_db[x].split("|");
	if (badge_field[0] != LastRally && badge_field[0].charAt(0) == Q && badge_field[7] != "") {
		LastRally = badge_field[0];
		var frm = "";
		if (badge_field[6]!="") frm = " from " + badge_field[6];
		document.writeln("<a href=" + badge_field[7] + ".htm onMouseover=\'window.status=\"Go to " + badge_field[0] + " Rally report\";return true\' onMouseout=\'window.status=\"\";return true\'>");
//		document.writeln("<img src=gifs/" + badge_field[1] + ".gif width=" + badge_field[2] + " height=" + badge_field[3] + " title=\'" + badge_field[0] + " rally badge" + frm + "\'  align=\'right\'></a>");//
		document.writeln("<img src=gifs/" + badge_field[1] + ".gif title=\'" + badge_field[0] + " rally badge" + frm + "\'  align=\'right\'></a>");//
		document.writeln("<div id=\'" + badge_field[1] + "\'></div>");
		AjaxRequest(badge_field[7],badge_field[1]);
		document.writeln("<hr class=cl>");
		ReportCount++;
		ReportList += "," + badge_field[0];
		}
	}
meta = document.getElementsByTagName("META");
for (var x=0;x<meta.length;x++) {
	if (meta[x].name=="description") meta[x].content = textNum(ReportCount) + " reports for motorcycle rallies beginning with " + Q;
	if (meta[x].name=="keywords") meta[x].content += ReportList;
	}
}

//------------------------------------
function docap() {
// needs dunloadin() in the last pre image
var obj = document.getElementById("firsthumb");
document.getElementById("IDframe").style.top=(obj.offsetTop + 60) + "px";
}
//========================================================
//	August 2009
//
//	AUTOMATIC THUMBNAIL SYSTEM
//
//	thumbn_triple() takes various arguments
//	("[caption]|[thumbstub]|[375x500]|[20]", ... 2 more ... [,"http://www.cloud.com/"])
//	     non std dimensions-----^       ^--top offset                   root
//	no caption  = no caption
//	filestub    = b_filestub.jpg --- look up filestub in msnpics for photo name
//	no filestub = calculate thumbname as b_idonlyXX.jpg -- photo name is msn[xx]
//	no dimensions = default 500px x 375px
//	offset = minus distance to set thumbnail from top of frame to correct aspect ratio, default top zero
//	IMPORTANT portrait photos should be at the END of the series and NOT included in menu_db[10] thumbs count
//
//	(2);	number of ROWS ie 3N thumbnails with calculated filenames = b_idonlyXX.jpg
//	();	default single row of three calculated thumbnails	
//
//	()	default three thumbnails calculated names with lookup table
//
//	var msnindex = root; // if not last triple argument in PAGE
//	var msnpics = array of full size photo name stubs   in PAGE
//
//	run thumbn_init() in pageInit();
//	if thumb_init has an argument it is for the date/time offset in msnpics stubs AND ...
//	...	there must by a thumbn_days lookup array in the PAGE - see thumbnday() function
//--------------------------------------------------------
function thumbn_init() {
var offset = null;
if (arguments.length == 1) offset = arguments[0];
var ims = document.getElementsByTagName("IMG");
for (var x=0;x<ims.length;x++) {
	if (ims[x].className == "thumbn") {
		ims[x].onclick = thumbn_load;
		if (offset) {
			var index  = ims[x].src.slice(-6,-4)*1-1;
			var pointer= msnpics[index].lastIndexOf("/")+offset;
			var d = thumbnday(msnpics[index].substr(pointer,2));
			var h = msnpics[index].substr(pointer+2,2);
			var m = msnpics[index].substr(pointer+4,2);
			ims[x].title += " Photo taken at " + h + "." + m + " on " + d;
			}
		}
	if (ims[x].className == "mainpic") ims[x].onclick = thumbn_shut;
	}
}
//---------------------------------------------
var thumbnum = 0;

function thumbn_triple() {
if (msnindex.length >0) root = msnindex[0];
var picount = arguments.length;
if (picount < 3) {
	picount = 3; //default if no number passed
	if (arguments.length == 1) picount = arguments[0]*3;
	for (var x=0;x<picount;x++) arguments[x] = "||";
	} else {
	if (picount%3 == 0) {
		// no root passed - use default
		} else {
		picount--;
		root = arguments[picount];
		}
	}

document.write("<div class=framen style=height:" + picount/3*126 + "px;>");
var tp = 0;
for (var x=0;x<picount;x+=3) {
	for (var y=0;y<3;y++) {
		var locs = arguments[x+y].split("|");
		var ttps = 0;
		var thumbpre = "s_";
		if (locs[1] == "") {
			thumbnum++; // increment the global counter
			locs[1] = idonly + prezero(thumbnum,2);
			if (msnindex.length > 1) locs[1] = idonly + prezero(msnindex[thumbnum],2);
			thumbpre = "b_";
			}
		if (locs[2] != "") {
			var xy = locs[2].split("x");
			ttps = Math.round(62 - (164 * xy[1] / xy[0] / 2));
			}
		if (locs.length == 4) ttps = -locs[3];
		document.write("<div class=thumbn style=top:" + tp + "px;left:" + (y*167) + "px;>");
		document.write("<img class=thumbn src=thumbs/" + thumbpre + locs[1] + ".jpg title=\"" + locs[0] + "\" + dims=\"" + locs[2] + "\" width=164 style=top:" + ttps + "px;>");
		document.write("</div>");
		}
	tp+=126;
	}
document.write("<div class=captn>Click on a small picture to open a larger photograph</div>");
document.write("<img class=shadon src=../home/gifs/black.gif>");
document.write("<img class=mainpic src=../home/gifs/black.gif root=\"" + root + "\" >");
document.write("</div>");
}
//---------------------------------------------

var mainpc = new Object();
var shader = new Object();
var capn   = new Object();
var inc_left = 1;
var inc_top = 1;
var inc_width = 1;
var inc_height = 1;
var target_width = 500;
var shader_off = 0;

//---------------------------------------------
function thumbn_load() {
// may need to set the objects globally
var dims= this.getAttribute("dims");
var cell= this.parentNode;
mainpc  = cell.parentNode.lastChild;
shader  = mainpc.previousSibling;
capn    = shader.previousSibling;

mainpc.style.width = 0;
mainpc.style.height = 0;
mainpc.src = this.src;
shader.style.width = 0;
shader.style.height = 0;
capn.style.display = "none";
capn.innerHTML = unbreak(this.title);

// set the mainpic etc
var b = this.src.lastIndexOf("/s_");
if (b>0) {
	var bigpic = this.src.substring(b+3).slice(0,-4);
	for (var x=0;x<msnpics.length;x++) {
		var msnbits = msnpics[x].split("/");
		if (msnbits[msnbits.length-1] == bigpic) bigpic = msnpics[x]; 
		}
	}
var b = this.src.lastIndexOf("/b_");
if (b>0) {
	var bigpic = this.src.substring(b+3).slice(0,-4);
	var index = bigpic.slice(-2)*1; // GOT to be a 2 digit number!
	if (msnindex.length > 1) {
		for (var x = 1;x<msnindex.length;x++) if (msnindex[x] == index) bigpic = msnpics[msnindex[x]];
		} else {
		bigpic = msnpics[index-1];
		}
	}
var newfile = mainpc.getAttribute("root") + bigpic + ".jpg";
mainpc.src = newfile;
var start_width = 164;	//	always
var start_top = parseInt(cell.style.top,10) + parseInt(this.style.top,10);
var start_left = parseInt(cell.style.left,10);
var target_top = 0;	//	nominal value here
var target_left = 75;	//	always here - see local.css
if (dims != "") {
	var xy = dims.split("x");
	target_width = xy[0]*1;
	var target_height = xy[1]*1;
	var start_height = 164 * target_height / target_width;
	} else {
	target_width = 500;
	var target_height = 375;
	var start_height = 123; 
	}
if (start_top + target_height < parseInt(cell.parentNode.style.height,10)) target_top = start_top + 10;
if (start_top + target_height > parseInt(cell.parentNode.style.height,10)) target_top = parseInt(cell.parentNode.style.height) - target_height + 10;
if (target_top < 1) target_top = 10;
inc_top = (target_top - start_top)/20;
inc_left = (target_left - start_left)/20;
inc_width = (target_width - start_width)/20;
inc_height = (target_height - start_height)/20;
mainpc.style.left   = start_left;
mainpc.style.top    = start_top;
mainpc.style.width  = start_width;
mainpc.style.height = start_height;
mainpc.style.display= "block";
shader.style.left   = start_left;
shader.style.top    = start_top;
shader.style.width  = start_width;
shader.style.height = start_height;
shader.style.display= "block";
shader_off = 0;

thumbn_enlarge();
}
//---------------------------------------------
function thumbn_enlarge() {
var mp_left   = parseInt(mainpc.style.left,10);
var mp_top    = parseInt(mainpc.style.top,10);
var mp_width  = parseInt(mainpc.style.width,10);
var mp_height = parseInt(mainpc.style.height,10);
//alert("left = " + (mp_left + inc_left) + "\ntop = " + (mp_top + inc_top) + "\nwidth = " + (mp_width + inc_width) + "\nheight = " + (mp_height + inc_height));

mainpc.style.left   = mp_left + inc_left;
mainpc.style.top    = mp_top + inc_top;
mainpc.style.width  = mp_width + inc_width;
mainpc.style.height = mp_height + inc_height;
shader.style.left   = mp_left + inc_left + shader_off;
shader.style.top    = mp_top + inc_top + shader_off;
shader.style.width  = mp_width + inc_width;
shader.style.height = mp_height + inc_height;
shader_off++;
if (mp_width + inc_width < target_width) {
	setTimeout(thumbn_enlarge,20);
	} else {
	capn.style.top = parseInt(mainpc.style.top,10)+10;
	if (capn.innerHTML !="") capn.style.display = "block";
	}
}
//---------------------------------------------
function thumbn_shut() {
this.style.display = "none";
this.previousSibling.style.display = "none";
this.previousSibling.previousSibling.style.display = "none";
}
//---------------------------------------------
function unbreak(txt) {
var t = txt.split("\n").join("<br>");
return t;
}
//---------------------------------------------
function thumbnday(dayid) {
var r = "the day";
for (var x=0;x<thumbn_days.length;x+=2) {
	if (thumbn_days[x] == dayid) r = thumbn_days[x+1];
	}
return r;
}
