
var bLocalPC = false;

var innerHTML = "innerHtml" ;
var outerHTML = "outerHtml" ;

var sFrames = "F" ;
var sOnePage = "O" ;

var gsVersionLabel = "";
var gsGraphicLabel = '&#187; Graphics version' ;
var gsTextLabel    = '&#187; Text-only version' ;
var gsHighVisibilityLabel = '&#187; High-visiblity version';

var gsVersion = "graphics";
var gsGraphic = 'graphics' ;
var gsText    = 'text' ;
var gsHighVisibility = 'high-visibility';
var gsSniff = "";
		
sContentDir = "content/" ;
sCssDir = "css/" ;
sJsDir = "scripts/" ;

// this will be toggled to start off false
var gbOpenPopupWindows = true  ;

var gsNoPopupsLabel = 'No popup windows' ;
var gsPopupsLabel = 'Popup windows' ;
var gsPopupText = "" ;	
var gsPopups = "yes";
var gsNoPopups = "no";
var gsPopupsFlag = "";

function initialise()
{
	/*-----------------------------------------------------------------------
	This function is called from the HTML head area.
	This means that you can't reference objects in the body which have 
	not yet been defined or call other functions which do that.
	You can use css rules to affect the display of elements which will
	take effect when they are defined.
	The advantage of doing that here is that the changes come into effect
	before the page is loaded rather than after as is the case with the
	onLoad function.
	If scripting is disabled then this function is not called. Neither
	is the onLoad function.
	-----------------------------------------------------------------------*/	
	reLoad();
	arrivePage();
 }

function toggleLoadUnloadStylesheets(override)
{
	/* -----------------------------------------------------------------------
	toggles between loading all stylesheets or unloading them
	for graphic or text only modes.
	
	----------------------------------------------------------------------- */
	
	var sMethod = "toggleLoadUnloadStylesheets()" ;
	var numArgsExpected = 0 ;

 	// default to graphics mode if possible
 	var sTwoHref = "css/wc3.css" ; sThreeHref = "css/index.css" ; 
 		
 	if ( ! override ) { override = "" ; }
 	// -----------------------------------------------------------------------
 	// this is to ensure that only IE 5, NN 6 and up browsers import stylesheets
 	// ----------------------------------------------------------------------- 		

  	if ( ! document.getElementById ) {  override = gsText };
  		
	// if an override has been passed in and it is 'text' e.g a user preference
	// from a previous page then change to text.
	// if no override has been passed in, assume we are just toggling between 
	// modes. In this case change to the other mode from the current one
		
  	switch ( override )
  	{	  
  		case gsText:
  		sTwoHref = "" ; sThreeHref =  "" ; gsVersion =  gsText;
  		break;
  			
  		case gsHighVisibility:
  		sTwoHref = "css/textonlyHV.css" ; sThreeHref =  "" ;
  		gsVersion = gsHighVisibility ;
  		break;
  			
  		case gsGraphic:
  		gsVersion = gsGraphic;
  		break;
  			
  		default:
  		if ( gsVersion == gsGraphic ) 
  		{
  			sTwoHref = "" ; sThreeHref =  "" ; gsVersion =  gsText;
  			break;  				
  		}
  	}
  		  		
 	// -----------------------------------------------------------------------
 	// I'd rather use the @import method but if you do you can't access the href
 	// property and don't know what the equivalent is. The getElementById will
 	// ensure that version 4 browsers etc.. don't import the stylesheets 
 	// -----------------------------------------------------------------------	
	
 	if (! document.body ) 
 	{		
 		document.write('<link type="text/css" media="all" id="wc3Style"' + 
			' rel="stylesheet" href="' +  sTwoHref + '" />');
				
		document.write('<link type="text/css" media="all" id="indexStyle"' +
			' rel="stylesheet" href="' +  sThreeHref + '" />');
 				
 	}
	else
	{
 		if ( !document.getElementById("wc3Style")) { return;}
 
		document.getElementById("wc3Style").href = sTwoHref;	
		document.getElementById("indexStyle").href = sThreeHref; 	
			
		// write the links to get back into the html
		toggleTextGraphic() ;
		
		// load or hide graphics that are individual to a particular page 
		// and need to be written into the html e.g clickable image maps
		loadGraphics();
	}
}




function loadPage( ) 
{ 	

	var domTopMenu = findDOM( "menu", 0 ) ;
	// although this is called in toggleLoadUnloadStylesheets() it is only if the body exists,
	// it has to be called again after the page has been loaded and the body rendered
	toggleTextGraphic( ) ;	

	
	
	setPopups();
	
	loadGraphics();
	
	//nothing gets done after this point
	re_direct_page( ) ;

	
	
	return ;
} 




function loadGraphics()
{
	var url = decodeURI( location.href);
	var sInner = "";	
	var sInner_two = "";

	var top_left_x = 545;
	var top_left_y = 10;
	var bottom_right_x = 810;
	var bottom_right_y = 90;
		
		
			
	// load or unload the shooting image map overlay 
	if ( url.indexOf("shooting.php") > 0 )
	{
		if (gsVersion == gsGraphic) 
		{ 
			sInner = ' <div id="mainpic" class="shooting_picture"> ' +
	 		' <img id="shooting_img" class="clickable_img" ' +
	 		' src="../img/clear_gallery.gif" usemap="#shooting_map" />  ' +
	 		' <map id="shooting_map" name="shooting_map"> ' +
	 		' <area shape="rect" coords="' +
	 		top_left_x + ',' +
	 		top_left_y + ',' +
	 		bottom_right_x + ',' +
	 		bottom_right_y +
	 		'" href="shooting_two.php">' +
	 		' </div> ' ;			 		
		}
		else
		{
			sInner = ' <div id="mainpic" class="shooting_picture"> ' +
			' </div> ' ;
		}
		document.getElementById("mainpic").innerHTML = sInner;	
	}
	
	
	//because of the re-direction from www.therealfoodcafe.com to www.eat-drink-highlands.com
	//when re-freshing the homepage, the index.php reference is not included in the address.
	//if no php page at all is referred to then assume that we are on the homepage
	if ( url.indexOf("index.php") > 0 ||  url.indexOf(".php") < 1)
	{	
		if (gsVersion == gsGraphic) 
		{  
		
			var domDayPic = findDOM( "embed_day_pic", 0 );
			top_left_x = 545;
			top_left_y = 10;
			bottom_right_x = 810;
			bottom_right_y = 90;
		
			sInner = ' <div id="embed_day_pic" class="cafe_interior_day_picture"> ' +
	 		' <img id="day_img" class="clickable_img" ' +
	 		' src="../img/clear_border.gif" usemap="#day_map" />  ' +
	 		' <map id="day_map" name="day_map"> ' +
	 		' <area shape="rect" coords="' +
	 		top_left_x + ',' +
	 		top_left_y + ',' +
	 		bottom_right_x + ',' +
	 		bottom_right_y +
	 		'" href="index_day_pic.php">' +		 	
	 		' </div> ' ;	
	 	/******************		
	 		alert(findLeft("embed_day_pic"));
	 		alert(findTop("embed_day_pic"));
	 	******************/	
	 	

			var domNightPic = findDOM( "embed_night_pic", 0 );
			top_left_x = 545;
			top_left_y = 10;
			bottom_right_x = 810;
			bottom_right_y = 90;
		
			sInner_two = ' <div id="embed_night_pic" class="cafe_interior_night_picture"> ' +
	 		' <img id="night_img" class="clickable_img" ' +
	 		' src="../img/clear_border.gif" usemap="#night_map" width="268px" height="100px"/>  ' +
	 		' <map id="night_map" name="night_map"> ' +
	 		' <area shape="rect" coords="' +
	 		top_left_x + ',' +
	 		top_left_y + ',' +
	 		bottom_right_x + ',' +
	 		bottom_right_y +
	 		'" href="index_night_pic.php">' +		 	
	 		' </div> ' ;	
	 	/******************		
	 		alert(findLeft("embed_night_pic"));
	 		alert(findTop("embed_night_pic"));
	 	******************/		 	
		}
		else
		{
			sInner = ' <div id="embed_day_pic" class="cafe_interior_day_picture"> ' +
			' </div> ' ;
			
			sInner_two = ' <div id="embed_night_pic" class="cafe_interior_night_picture"> ' +
			' </div> ' ;			
		}
		//document.getElementById("embed_day_pic").innerHTML = sInner;	
		//document.getElementById("embed_night_pic").innerHTML = sInner_two;
		
	}
	

}

function goToPage(url)
{

	// The plain url is passed in here from the web page if javascript is enabled
	// Any data to be persisted from page to page should be added to the url here
	// The data is decoded, somewhat crudely in the functions called from initialise() 
	// which are reLoad(); and arrivePage();
	
	var sJoinCharacter = ""; sSniff=""; sPopups = "";
	
	if ( url.indexOf("?") == -1 ) { sJoinCharacter = "?" } else { sJoinCharacter = "&" }
	
	url += sJoinCharacter + "mode=" + gsVersion ;
	
	
	if ( url.indexOf("sniff") == -1 ) 
	{ 
		if ( gsSniff != "" )
		{
			sSniff="sniff="+gsSniff;
		
			url += sJoinCharacter + sSniff;
		}
	
	}
	
	if ( url.indexOf("popups") == -1 ) 
	{ 
		if ( gsPopupsFlag != "" )
		{
			sPopups="popups="+gsPopupsFlag;
		
			url += sJoinCharacter + sPopups;
		}
	
	}
	
	location.href = encodeURI(url) ;
	
	return false;
	
}


function reLoad()
{
	var deskTopHeight = 450;
	var deskTopWidth  = 600;
	var sHhandheld    = 'handheld' ;
	var sDesktop      = 'desktop' ;

	var sJoinCharacter = "";
	var data = decodeURI( location.search.substring(1, location.search.length));
	var url = decodeURI( location.href);
	var sSniff = "";
	
	var screenHeight = 0;
	var screenWidth = 0;
	
	var liveScreenHeight = 0;
	var liveScreenWidth = 0;
	
	var sMode = "";
	

	
	if ( !data ) { data = ''; }
	
	if ( data.indexOf("sniff") == -1 ) 
	{ 
		screenHeight = screen.height;
		screenWidth = screen.width;
		liveScreenHeight = screen.availHeight;
		liveScreenWidth = screen.availWidth;
		
		if ( liveScreenHeight >= deskTopHeight && liveScreenWidth >= deskTopWidth )
		{
			gsSniff=sDesktop;
		}
		else
		{
			gsSniff=sHhandheld ;
		}
		sSniff="sniff="+gsSniff;
		
		if ( url.indexOf("?") == -1 ) 
			{ sJoinCharacter = "?" } else { sJoinCharacter = "&" }
				
		url += sJoinCharacter + sSniff ;
		
	
		
		location.replace(encodeURI(url));
	}
}

function arrivePage()
{
	// get all the arguments from the url before the page has loaded so we can
	// set stylesheets etc
	var sAllData = decodeURI( location.search.substring(1, location.search.length));
	var sData = "";
	
	if ( !sAllData ) { sAllData = ''; }
	
	if ( sAllData.indexOf("mode=" + gsText) != -1 ) 
	{ 
		sData = gsText ; 
	}
	else if ( sAllData.indexOf("mode=" + gsHighVisibility) != -1 ) 
	{ 
		sData = gsHighVisibility ; 
	}
	else 
	{ 
		sData = gsGraphic ; 
	}
	
	gsVersion = sData ;
	toggleLoadUnloadStylesheets( sData ) ;
	
	//----------------------------------------------------------------------------
	
	if ( sAllData.indexOf("popups=" + gsPopups) != -1 ) 
	{ 
		sData = gsPopups ; 
		gbOpenPopupWindows = true ;
	}
	else 
	{ 
		sData = gsNoPopups ; 
		gbOpenPopupWindows = false;
	}	
	
	gsPopupsFlag = sData ;
	
	// xhtml validator complained about calling the load/unload functions from
	// the body tag in the page so do it here
	if (window.attachEvent) {window.attachEvent("onload", loadPage) ;} 
	if (window.attachEvent) window.attachEvent("onunload", unloadPage) ;	
	
	
	return sData;
}



function toggleTextGraphic( ) 
{ 	
	var sInner = "";
	var changeTo = "" ;
	
	// if the tag doesn't exist then we can't change it
	if ( document.getElementById("toggleStylesheets") ) 
	{
	
		if (gsVersion == gsText )
		{
			gsVersionLabel = gsGraphicLabel ;
			changeTo = gsGraphic ;
				
			sInner = '<a href="#" onclick="toggleLoadUnloadStylesheets(' 
			+ "\'" + gsHighVisibility + "\'" + ');">' + gsHighVisibilityLabel + '</a>'
			document.getElementById("toggleTextStyles").innerHTML = sInner;					
		}
		else if ( gsVersion == gsHighVisibility)
		{
			gsVersionLabel = gsGraphicLabel ;
			changeTo = gsGraphic ;
				
			sInner = '<a href="#" onclick="toggleLoadUnloadStylesheets(' 
			+ "\'" + gsText + "\'" + ');">' + gsTextLabel + '</a>'
			document.getElementById("toggleTextStyles").innerHTML = sInner;			
		}
		else 
		{
			// ensure the mode is set to something
			if (gsVersion == "" ) { gsVersion == gsGraphic ; }
			// we are in graphics mode
			gsVersionLabel = gsTextLabel ;
			changeTo = gsText;
				
			// hide the high visibility button
			sInner = "" ;
			document.getElementById("toggleTextStyles").innerHTML = sInner;	
		}
	}
				
	sInner = '<a href="#" class="links" onclick="toggleLoadUnloadStylesheets('
	+ "\'" + changeTo + "\'" + ');">' + gsVersionLabel + '</a>'
	document.getElementById("toggleStylesheets").innerHTML = sInner;	

	return ;
} 


function unloadPage( asCallingPage ) 
{ 	
	return ;
} 




/****************   OPEN NEW WINDOW functions **********************************************/
var newWindow = null;






function openWindow(contentURL, windowName)
{
	
	if ( gbOpenPopupWindows )
	{
		newWindow = window.open( contentURL, windowName ) ;
		newWindow.focus();
		return false;
	}
	else
	{
		return true;
	}
}

closeWindow = function()
{
	if (newWindow != null)
	{
		newWindow.close();
		newWindow = null;
	}
}

toggleWindow = function(contentURL, windowName, windowWidth, windowHeight, externalURL)
{
	if (newWindow == null)
	{
		openWindow(contentURL, windowName, windowWidth, windowHeight, externalURL);
	}
	else
	{
		closeWindow();
	}
}



/****************   END OF  OPEN NEW WINDOW functions **********************************************/








/****************        MENU functions **********************************************/

function sfHover()
{
	// document.getElementById("nav")
	var domTopMenu = findDOM( "nav", 0 ) ;
	
	var	sfEls = domTopMenu.getElementsByTagName("LI") ;

	for ( var i=0; i<sfEls.length; i++)
	{
		sfEls[i].onmouseover=function(){ this.className+=" sfhover"; }
		sfEls[i].onmouseout=function()
		{ 
			this.className=this.className.replace(new RegExp(" sfhover\\b"), ""); 		       
		}
		
		sfEls[i].onfocus=function(){ this.className+=" sfhover"; }
		sfEls[i].onblur=function()
		{ 
			this.className=this.className.replace(new RegExp(" sfhover\\b"), ""); 		       
		}		
	}

}


/**********************************  attaching these events to be performed on load has
to be after the function definition ******************************************************/

if (window.attachEvent) window.attachEvent("onload", sfHover) ;



function showDebug( asArg )
{
	// if the object is not found then no other statements in the try block will be executed
	var domObj = findDOM( "Debug", 0 ) ;
		
	domObj.innerHTML= asArg ;
}




function re_direct_page( )
{
	if ( top.location.href != self.location.href ) 
	{
		// replace the top level frame of the other site with this page 
		top.location.href = self.location.href ;
		// if our page is contained in a frame of its own then use this
		//top.location.href = HTML_ROOT + "?" + self.location.href ;
	}
}


function displayMsg(message) 
{
    	window.status=message ;
}




function IsMac () 
{ 

	var sMethod = "IsMac()" ;
	var numArgsExpected = 0 ;

 	// convert all characters to lowercase to simplify testing 
    	var agt=navigator.userAgent.toLowerCase(); 

    	this.mac = (agt.indexOf("mac")!=-1); 
    		
    	return this.mac ;
}


function toggleText()
{

/*alert( document.getElementById("togglePopups").outerHTML );*/

/*
 	var sInner = "";
 	// if the tag doesn't exist then we can't change it
 	if ( document.getElementById("togglePopups") ) 
 	{

		if ( sPopupText == sNoPopups )
		{
			sPopupText = sPopups ;
		}
		else
		{
			sPopupText = sNoPopups ;
		}

 		sInner = '<a href="#" id="togglePopupsLink" class="links" ' +
 		' onMouseOver="toggleText()" onMouseOut="toggleText()" ' +
 		' onclick="togglePopups();">' + sPopupText + '</a>';	 	
 		
 		document.getElementById("togglePopups").innerHTML = sInner; 	
 	}
 */
 	return ;
}


function togglePopups()
{
	gbOpenPopupWindows = ! gbOpenPopupWindows ;
	setPopups();

}

function setPopups()
{
 	var sInner = "";
 	// if the tag doesn't exist then we can't change it
 	if ( document.getElementById("togglePopups") ) 
 	{
 		if ( gbOpenPopupWindows )
 		{	
 			gsPopupText = gsPopupsLabel ;
 			gsPopupsFlag = gsPopups; 		
 		}
 		else 
 		{
 			gsPopupText = gsNoPopupsLabel ;
 			gsPopupsFlag = gsNoPopups;
 		}

 		sInner = '<li id="togglePopups"> <a href="#" class="leftColumn" onmouseover="toggleText()" onmouseout="toggleText()" onclick="togglePopups();">' + gsPopupText + '</a></li>';	 	
 		
 		document.getElementById("togglePopups").outerHTML = sInner;
 	}	
	return ;
	
	//+ '&#187; ' 
 }
