var liston='';
var dir = new Array();
dir = dirdata.split(','); // load from dir.js in each directory
dir.length --;

document.styleSheets[1].disabled = true;
var ffxadj = 0;
var browser=new IdentifyBrowser();

// Set-up to use getMouseXY function onMouseMove
document.onmousemove = getMouseXY;
var tempX = 0;
var tempY = 0;

function IdentifyBrowser() {
	var agent = navigator.userAgent.toLowerCase();
	this.ie  = (agent.indexOf("msie") != -1);
	this.ffx = (agent.indexOf("firefox") != -1);
	this.opera = (agent.indexOf("opera") != -1);
	this.safari = (agent.indexOf("safari") != -1);

	if (! this.ie) {
		document.styleSheets[1].disabled = false;
		ffxadj = 7;
	}
}

var loc=location.toString(); // break up location

var pat = /[\w-]+/g;
loc=loc.match(pat);


var tc ="<b>ISBuC's Terms &amp; Conditions</b><br />Normal messages to ISBuC will NOT be published on the ISBuC web-site unless we specifically receive your permission to do so.<br /><br />";
tc += "<b>Events, Business & Property</b><br />You allow ISBuC to make all, some or none of the information you are sending available to the world on the ISBuC web-site ";
tc += "and confirm that<br /><br />&nbsp; &nbsp; a) the Event, Business or Property is based on Skye or Raasay<br />&nbsp; &nbsp; b) you are allowed to give ISBuC this information<br />&nbsp; &nbsp; c) you are giving ISBuC permission to use this information<br /><br />";
tc += "You accept that ISBuC can not be held liable for anything that results from you making this information available.";

locode = -1;
var mousex;
var mousey;

var sitewin='';

var ArcC = '#996'; 
var BusC = '#66c';
var ForC = '#09f';
var GalC = '#6a9'; 
var ISBC = '#b68'; 
var MagC = '#aaa'; 
var MapC = '#963';
var PeoC = '#969';
var PlaC = '#696';
var ProC = '#c66';
var SigC = '#69c';
var SeaC = '#f90';
var TimC = '#666';
var WalC = '#693';
var WilC = '#96c';

var timer ='';

function showmenu() {
	clearTimeout(timer);
	if (liston=='') {
		if (document.getElementById('minibox')) {
			document.getElementById('minibox').style.visibility='hidden';
		}
		document.getElementById('dropdown').style.visibility='visible';
		liston='yes';
	}
}

function hidemenu() {
	timer = setTimeout("closemenu()",500);
}

function closemenu() {
	liston='';
	document.getElementById('dropdown').style.visibility='hidden';
	if (document.getElementById('minibox')) {
		document.getElementById('minibox').style.visibility='visible';
	}
}

function stroll(way) {
	var page=0;
	if (dir.length > 1) {
		if (dir.length > 2) {
			if (loc[6]){
				for(i=0;i<dir.length;i++) {
					if (loc[6] == dir[i]) {
						page=i+way;
						break;
					}
				}
			} else {
				page=way;
			}
			if (page < 1) page = dir.length-1;
			if (page > dir.length-1) page = 1;
			location=dir[page]+".php";
		} else {
			alert('ISBuC Message\n\nSorry. There is only one page in this section.');
		}
	} else {
		if (!loc[5] || loc[5] == 'index') {
			location='ISBuC/Help.php';
		} else {
			alert('ISBuC Message\n\nSorry. There are no pages in this section.');
		}
	}
}

function locate(px,py) {
	if (dir.length==0) {
		document.getElementById('indx').href=location;
	}
	var sec = " "+loc[5];
	if (sec == " ISBuC") sec = ". Isle of Skye Business Community";
	var line = "<b>ISBuC"+sec+"</b>";
	document.getElementById('heading').innerHTML=line;
	var clr = eval(loc[5].substr(0,3)+"C");
	document.getElementById('heading').style.backgroundColor=clr;
	document.getElementById('foot').style.backgroundColor=clr;

	if (loc[5]=='Maps' && loc[8]) {
		if (loc[8] < 112 && loc[8] > 0) {
			locode=loc[8];
		}
	}

	if (locode > 0) {
		if (px && py){
			document.getElementById('locbox').style.left = px + 441;
			document.getElementById('locbox').style.top = py + 46;
			document.getElementById('locbox').style.visibility = 'visible';
		}
		var L = (locode % 8) * 7;
		var T = parseInt(locode / 8) * 7;
			document.getElementById('minibox').style.left = L;
			document.getElementById('minibox').style.top = T + 16;
			document.getElementById('minibox').style.visibility = 'visible';
			if (loc[8]) {
				var L = (locode % 8) * 48;
				var T = parseInt(locode / 8) * 48;
				document.getElementById('mapcursor').style.left = L + 2 ;
				document.getElementById('mapcursor').style.top = T + 51;
				document.getElementById('mapcursor').style.visibility = 'visible';
			}
	}
	pickt();
	
}

function pickt() {
	if (document.getElementById('pickture')) {
		var i = rnd(picks.length);
		img = '../pic/thumb/'+picks[i]+'.jpg';
		document.getElementById('pickture').src=img;
	}
}

function rnd(n) {
	n = n*Math.random();
	n = Math.floor(n);
	return n
}

function map() {
	location='../Maps/Areas.php?'+locode;	
}

function view(file) {
	file = file.replace(/thumb\//,"");
	
	if (sitewin) {
		sitewin.close();
	}
	
	sitewin = open(file,'_blank');

	if (! sitewin) {
		top.location=file;
	} 
}

function srch() {
	if (document.getElementById('srchfrm').query.value) {
 		var qry = clean(document.getElementById('srchfrm').query.value);
 		document.getElementById('srchfrm').query.value = qry;
		document.getElementById('srchfrm').submit();
	}
}

function clean(txt) {
	txt=txt.replace(/[^\w ]/g,'');
	return txt;
}

function tell(txt) {
	document.getElementById('dsc').innerHTML = txt;
	document.getElementById('dsc').style.top = mousey + 15;
	document.getElementById('dsc').style.left = mousex - ((pw()-650)/2) +10;
	document.getElementById('dsc').style.display='inline';
	
}

function told() {
	document.getElementById('dsc').style.display='none';
}

function getMouseXY(e) {
  if (browser.ie) { // grab the x-y pos.s if browser is IE
    tempX = event.clientX + document.body.scrollLeft;
    tempY = event.clientY + document.body.scrollTop;
  } else {  // grab the x-y pos.s if browser is NS
    tempX = e.pageX;
    tempY = e.pageY;
  }  

  mousex = tempX;
  mousey = tempY;
}

function pw() {
	return window.innerWidth != null? window.innerWidth: document.body.clientWidth != null? document.body.clientWidth:null;
}

function showppt(px,py) {
	clearTimeout(timer);
	document.getElementById('pptbox').style.left = px + 441;
	document.getElementById('pptbox').style.top = py + 46;
	document.getElementById('pptbox').style.visibility='visible';
}

function hideppt() {
	timer = setTimeout("closeppt()",500);
}

function closeppt() {
	document.getElementById('pptbox').style.visibility='hidden';
}

function stylee() {
	alert('OKDoh');
}