var clicked=""
var gtype=".gif"
var selstate="_over"
var loc = "";

document.write("<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tr>");
document.write("<td><img src=\""+loc+"images/blueballs_b3_on_top.gif\" alt=\"\" width=\"150\" height=\"27\"></td>");
tr(false);
writeButton(loc,"holidays.php","images/blueballs_b3_on_b1",150,22,"","",0);
writeButton(loc,"props.php","images/blueballs_b3_on_b2",150,22,"Holiday Properties","",0);
writeButton(loc,"offers.php","images/blueballs_b3_on_b3",150,22,"Special Offers","",0);
writeButton(loc,"sbreaks.php","images/blueballs_b3_on_b4",150,22,"Short Breaks","",0);
writeButton(loc,"bform.php","images/blueballs_b3_on_b5",150,22,"Booking Form","",0);
writeButton(loc,"contact.php","images/blueballs_b3_on_b6",150,22,"Contact Us","",0);
writeButton(loc,"tandc.php","images/blueballs_b3_on_b7",150,22,"Terms and Conditions","",0);
writeButton(loc,"info.php","images/blueballs_b3_on_b8",150,22,"Useful Information","",0);
writeButton(loc,"brochure.php","images/blueballs_b3_on_b9",150,22,"Brochure Request","",0);
//writeButton(loc,"owners.php","images/blueballs_b3_on_b10",150,22,"Owners Information","",0);
writeButton(loc,"links.php","images/blueballs_b3_on_b11",150,22,"Local Attractions","",0);
writeButton(loc,"resources.php","images/blueballs_b3_on_b12",150,22,"Links","",0);
tr(true);
document.write("<td><img src=\""+loc+"images/blueballs_b3_on_bottom.gif\" alt=\"\" width=\"150\" height=\"27\"></td>");
document.write("</tr></table>");
loc="";

function tr(b){if (b) document.write("<tr>");else document.write("</tr>");}

function turn_over(name) {
	if (document.images != null && clicked != name) {
		document[name].src = document[name+"_over"].src;
		//alert(document[name].src); //ok
	}
}

function turn_off(name) {
	if (document.images != null && clicked != name) {
		document[name].src = document[name+"_off"].src;
	}
}

function reg(gname,name)
{
if (document.images)
	{
	document[name+"_off"] = new Image();
	document[name+"_off"].src = loc+gname+gtype;
	//alert(loc+gname+gtype);//ok
	document[name+"_over"] = new Image();
	document[name+"_over"].src = loc+gname+"_over"+gtype;
	}
}

function evs(name){ return " onmouseover=\"turn_over('"+ name + "')\" onmouseout=\"turn_off('"+ name + "')\""}

function writeButton(urld, url, name, w, h, alt, target, hsp)
{
	gname = name;
	while(typeof(document[name])!="undefined") name += "x";
	reg(gname, name);
	tr(true);
	document.write("<td>");
	if (alt != "") alt = " alt=\"" + alt + "\"";
	if (target != "") target = " target=\"" + target + "\"";
	if (w > 0) w = " width=\""+w+"\""; else w = "";
	if (h > 0) h = " height=\""+h+"\""; else h = "";	
	var l = clicked!="" || !isCurrentFile(url);
	if (url != "") url = " href=\"" + urld + url + "\"";
	
	if (l) document.write("<a " + url + evs(name) + target + ">");
	else gname += selstate;
	
	gname += gtype;
	
	if (hsp == -1) hsp =" align=\"right\"";
	else if (hsp > 0) hsp = " hspace=\""+hsp+"\"";
	else hsp = "";
	//alert(loc+gname);//ok
	document.write("<img src=\""+loc+gname+"\" name=\"" + name + "\"" + w + h + alt + hsp + " border=\"0\" />");
	
	if (l) document.write("</a>");
		
	document.write("</td>");
	tr(false);
}

function syncFile(f,nf)
{
	var matches = 'home.html*index.html*welcome.html*default.asp';
	var p = f.lastIndexOf('/');
	var sf = f;
	
	if (p >= 0) sf = f.substr(p+1, f.length-1);
	if (matches.indexOf(sf) == -1) return "";
	
	return sf;
}

function isCurrentFile(str)
{
	var p = str.lastIndexOf(':');
	if (p > 0) str = str.substr(p+1, str.length-1);
	str = escape(str);
	str = str.toLowerCase();
	while (str.length > 3 && str.substring(0,3) == "../")
		str = str.substr(3, str.length-1);
	var fstr = str.indexOf(".htm");
	if (fstr == -1) fstr = str.indexOf(".asp");
	if (fstr < 1 && str.charAt(str.length-1) != '/') str += "/";
	var current = document.location.href.toLowerCase();
	p = current.lastIndexOf('?');
	if (p > 0) current = current.substr(0, p);
	var fcurrent = current.indexOf(".htm");
	if (fcurrent == -1) fcurrent = current.indexOf(".asp");
	if (fcurrent < 1 && current.charAt(current.length-1) != '/') current += "/";	
	if (fstr != -1 && fcurrent == -1) current += syncFile(str, current);
	if (fstr == -1 && fcurrent != -1) str += syncFile(current, str);
		
	var currsize = current.length;
	var strsize = str.length;
	
	// find the 2nd to last occurence of "/"
	var second_last_slash = -1;
	var temp_slash = current.indexOf("/"); // make sure it occurs once
	while (temp_slash != -1 && temp_slash != currsize - 1)
	{
		second_last_slash = temp_slash; // on exit will contain 2nd to last slash :)
		temp_slash = current.indexOf("/", temp_slash + 1); // start search after last match found
	}
	
	// alert (current + " contains its 2nd to last slash at: " + second_last_slash);
	
	var i;
	for (i = currsize; i > second_last_slash; i--)
	{
		if (strsize < 0) return false;
		if (current.charAt(i) != str.charAt(strsize)) return false;
		strsize--;
	}
	
	// majorly fails as more_info.php matches info.php
	// instead loop from end of current (currsize) to / last (str.indexOf("/"));
	//
	//while (strsize >=0 && currsize >=0)
	//{
	//	if (current.charAt(currsize) != str.charAt(strsize))
	//		return false;
	//		
	//	currsize = currsize -1;
	//	strsize = strsize -1;
	//}

	
	
	return true;
}
