// set abbreviations
d=document;
loc=document.location;

//browser detect
uA = navigator.userAgent; 
if (loc.href.indexOf('whichbrowser')!=-1){
	alert("uA (useragent): "+uA+"\naN (appname): "+navigator.appName+"\naV (appversion): "+navigator.appVersion);
}
if (document.layers){loc.href='http://archive.webstandards.org/upgrade/'}
ns =  (uA.indexOf('Netscape')!=-1)? true : false;
op =  (uA.indexOf('Opera')!=-1) ? true : false;
ie = ((uA.indexOf('MSIE')!=-1) && (!op) && (!ns))? true : false;
badbrowser = ((uA.indexOf('6')==-1)&&(uA.indexOf('7')==-1)) ? true : false;
if(uA.indexOf('Firefox')!=-1) badbrowser = false;
if (badbrowser){
	if (d.cookie.indexOf('badbrowser')!=-1){
    } else {//cookie user so badbrowser popup only comes once per day
//		myWin = window.open('/browser.htm','doh','width=250,height=250');
		expires = new Date(); da=1;h=8;m=60;s=60;ms=1000;
		expires.setTime(expires.getTime()+da*h*m*s*ms)
		d.cookie = "badbrowser;expires="+expires.toGMTString();
	}
}
if ((document.referrer.indexOf('google')!=-1) && (document.referrer.indexOf('ig?hl')==-1)){
	myGoogleWin = window.open('/google.htm','google','width=250,height=250');
}

d.write('<script type="text/javascript" src="/banners.js"></script>');//include banner info
d.write('<script type="text/javascript" src="/extras.js"></script>');//include odd bits like popup scripts, etc.
d.write('<link rel="shortcut icon" href="/favicon.ico" /> '); //add favicon
d.write('<meta http-equiv="imagetoolbar" content="no"><meta http-equiv="imagetoolbar" content="false">');//turn off image toolbar in ie

//css correction for IE5+
if (ie){
	d.write('<style type="text/css">.navItem {cursor:hand;}#main{top:76px;}</style>');
}

// ################# START OF FUNCTIONS ###############

function addBrackets(textToBracket){//add [] to folder or page name.
	text = eval("d.getElementById('"+textToBracket+"').innerHTML");
	text = '['+text+']';
	eval("d.getElementById('"+textToBracket+"').innerHTML = '"+text+"'");
}

function roll(id,status) {
//	if (d.getElementById(id).parentElement){alert('yes')}
	if (d.getElementById(id).parentNode.className == 'subNav'){ 
		bgCol = "#ff0"; //mouseoutcolour
		txCol = "#ff0"
	} else { //mainNav
		bgCol = "#ff0"
		txCol = "#ff0"
	}
	thisStyle = d.getElementById(id).style;
	if (status == 'over'){
    	thisStyle.background = bgRollOver;
		thisStyle.color = textRollOver;
		clearTimeout(t);
	} else {
		thisStyle.background = bgRollOut;
		thisStyle.color = textRollOut;

//	document.getElementById('bottom').innerHTML+=" <em><strong>"+newAtRest+"</strong></em>";
		t = setTimeout("hideSubNavs('"+atRest+"','here')", 1500);
//		eval("document.getElementById('"+whichFolder+"').style.backgroundColor = '#e1b0c0';");
	}
}

function hideSubNavs(id,where) {
//	if(where){
//	document.getElementById('bottom').innerHTML+=" <em>"+where+"</em>";}
//	document.getElementById('bottom').innerHTML += newAtRest
	for (i=0; i<parentNavs.length; i++){
		if (parentNavs[i] != id){
        	eval("d.getElementById('"+parentNavs[i]+"Nav').style.visibility = 'hidden'");
		} else {
			eval("d.getElementById('"+id+"Nav').style.visibility = 'visible'");
		}
    }//	alert('in menu.js fn hidesubnavs');
}

function subMenu(id, status){
	if(status == 'over'){ hideSubNavs(id);}
	roll(id,status);//alert('in menu.js fn submenu')
}


function setPage(){ //function called in footer.js; this function is to determine and highlight the appropriate part of the nav, depending on where the user is in the site.
	lastSlash = loc.pathname.lastIndexOf('/');
	loseLastSlash = loc.pathname.substr(loc.pathname.indexOf('/'),lastSlash-1);
	firstSlash = loseLastSlash.lastIndexOf('/');
	firstSlash++; 
	whichFolder = loc.pathname.substring(firstSlash, lastSlash);
	if (whichFolder=='') {//ie, if homepage, show date
    	whichFolder = 'logoDate';
	}
    subMenu(whichFolder,'over');
	atRest = whichFolder;
	newAtRest = whichFolder;

	if ((whichFolder=='friends')||(whichFolder=='escape')||(whichFolder=='contact')) {//friends has no submenu, so show date
//		document.getElementById('bottom').innerHTML += " l79 - "+whichFolder
		atRest = 'logoDate';
		hideSubNavs('logoDate');
    }
	eval("d.getElementById('"+whichFolder+"').style.background = '"+defaultNavBg+"';");
	addBrackets(whichFolder);

	if ((whichFolder!='logoDate')&&(whichFolder!='gallery')){//set page title
		titleText = (whichFolder == "farout") ? "far out" : whichFolder;
       	d.title = "graham price :: " + titleText;
	}

	//get the page name and add to page title
	page = '';
	
	if ((whichFolder=='strewth')&&(loc.href.indexOf('?v=')!=-1)){
    	page = loc.href.substr(loc.href.indexOf('=')+1);
		if(page.indexOf('&')!=-1) page = page.substring(0,page.indexOf('&'));
		addBrackets(page);
    }
	if ((whichFolder=='gallery')&&(loc.href.indexOf('?album=')!=-1)){
    	page = loc.href.substr(loc.href.indexOf('album=')+6);
		if(page.indexOf('gal')!=-1){
        	page = page.substring(0,page.indexOf('&gal'));
        }
		addBrackets(page);
    }

	if ((loc.pathname.indexOf('.php')!=-1)&&(loc.pathname.indexOf('index')==-1)) {
        page = loc.pathname.substring(lastSlash+1,loc.pathname.indexOf('.php'));
		if(whichFolder!="gallery") d.title+= " :: " + page;

		if ((page=='sitges')||(page=='tarragona')||(page=='barcelona')) page='spain';
		if ((page=='hammamet')||(page=='sahara')||(page=='tunis')) page='tunisia';
		if ((page=='brussels')||(page=='bruges')) page='belgium';
		if ((page=='venice')||(page=='verona')||(page=='rome')||(page=='sorrento')) page='italy';
		if ((page=='dublin')||(page=='cork')) page='ireland';
		if ((page=='sydney')||(page=='nsw')) page='australia';
		if ((page=='sanfrancisco')||(page=='newyork')) page='usa';
		if ((page=='france_sunsport')||(page=='france_early')||(page=='paris')) page='france';

		if(whichFolder!='gallery') addBrackets(page);
	}
	
	if(whichFolder!='') {
		whichBanners  = whichFolder;
	} else {
		whichBanners = "all";
	}
	
	if(whichFolder=='history') whichBanners = 'histor';
	if(whichFolder=='escape') whichBanners = 'escap';
	if((whichFolder=='friends')||(whichFolder=='logoDate')||(whichFolder=='gallery')||(whichFolder=='contact')) whichBanners = 'all';
	if((whichFolder=='strewth')||(whichFolder=='farout')) whichBanners='australia';
	if(whichFolder=='blimey') whichBanners='london';
	if((whichFolder=='travel')&&(page!='')) whichBanners = page;
	if((whichFolder=='travel')&&(page='thailand')) whichBanners = 'travel'; // no banners for thailand
	if((whichFolder=='travel')&&(page='usa')) whichBanners = 'sanfrancisco'; // no banners for new york
	//alert("whichFolder = "+whichFolder+"\npage = "+page+"\nbanner = "+whichBanners);
//	if(whichFolder=='web' && page=='portfolio') addBrackets('portfolio2');
	
	//pass page name to specificImage, which is used to get specific banner in footer.js
/*	specificImages = new Array ('education10','employment11');	//array of specific images
	if ((!specificImage)&&(page!='')) { 
		for (i=0; i<specificImages.length; i++){
			alphaString = specificImages[i].slice(0,-2)
			numString = parseInt(specificImages[i].slice(-2));
			if (page==alphaString){
				specificImage = numString;
            }
        }
    }*/

}

// clock function
function clock() {
	var days = new Array ('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday')
	var today = new Date();
	var dayNum = today.getDay();
	var day = days[dayNum];
	fullDate = today.toLocaleString();
	if(fullDate.indexOf('day')==-1){
    	fullDate = day+", "+fullDate;
    }
	document.getElementById('clockDisplay').innerHTML = fullDate;
	setTimeout(clock,1000);
}

// ################# END OF FUNCTIONS ###############

bgRollOut = "";
bgRollOver = "#c36";
textRollOut = "";
textRollOver = "#fff";
defaultNavBg = "url(/images/default_nav_bg.gif) #903 repeat-x top";

if (loc.href.indexOf('farout')!=-1 || loc.href.indexOf('blimey')!=-1 || loc.pathname=="/" || loc.href.indexOf('londoner')!=-1 || loc.href.indexOf('australia')!=-1 || loc.pathname=="/index.php"){
	bgRollOut = "";
	bgRollOver = "#002377";
	textRollOut = "";
	textRollOver = "#fff";
	defaultNavBg = "url(/images/blimey_nav_bg.gif) #c1211f repeat-x bottom";
}
if (loc.href.indexOf('strewth')!=-1  || loc.href.indexOf('sydneysider')!=-1){
	bgRollOut = "";
	bgRollOver = "#f60";
	textRollOut = "";
	textRollOver = "#fff";
	defaultNavBg = " url(/images/oz_nav_bg.gif) #ff9900 repeat-x top";
}


// get url posted variable
if (loc.href.indexOf('?')!=-1){
	getVar = loc.href.substring(loc.href.indexOf('=')+1);
} else {
	getVar = 0;
}



//set default values
var atRest = 'logoDate';//set default sub menu
newAtRest = "";
parentNavs = new Array('logoDate','farout','blimey','strewth','travel','career','web','history','friends','gallery','escape','contact');
t = setTimeout("hideSubNavs('"+atRest+"')", 60000);
