//Store the Layer name in a global varaible for access from other functions in this page
var divId= 'MenuLayer';

//Find the current page name
page_name = getPageName('current');
// The above gives the page name which is used as the varable "page_name". This was done because Opera needs the varaible before the page loads.
//Alternative to this could be to print out the whole menu as the page loads and then swap the appropriate image "onload".

/*
Sidenav handler for DawnJudd Ents Main menu

=====NOTES=====================================================================================================

DEBUGGING:
send 'all' as argument to expand all parents & show all children.

===============================================================================================================
*/
					
//image pre-loads

/*
Pre-load all the images.
*/
//MainOut is the Home image for BandsMenu - it is wider than the normal Out images
MainOut= new Image();
MainOut.src  = "/jimjak/art/menuimages/buttons/MainOut.gif";
HomeOut = new Image();
HomeOut.src  = "/jimjak/art/menuimages/buttons/HomeOut.gif";
HomeOver = new Image();
HomeOver.src  = "/jimjak/art/menuimages/buttons/HomeOverAlt.gif";
HomeOn = new Image();
HomeOn.src  = "/jimjak/art/menuimages/buttons/HomeIn.gif";
BandsOut = new Image();
BandsOut.src  = "/jimjak/art/menuimages/buttons/BandsOut.gif";
BandsOver = new Image();
BandsOver.src  = "/jimjak/art/menuimages/buttons/BandsOverAlt.gif";
BandsOn = new Image();
BandsOn.src  = "/jimjak/art/menuimages/buttons/BandsIn.gif";
DiscoOut = new Image();
DiscoOut.src  = "/jimjak/art/menuimages/buttons/DiscoOut.gif";
DiscoOver = new Image();
DiscoOver.src  = "/jimjak/art/menuimages/buttons/DiscoOverAlt.gif";
DiscoOn = new Image();
DiscoOn.src  = "/jimjak/art/menuimages/buttons/DiscoIn.gif";
KaraokeOut = new Image();
KaraokeOut.src  = "/jimjak/art/menuimages/buttons/KaraokeOut.gif";
KaraokeOver = new Image();
KaraokeOver.src  = "/jimjak/art/menuimages/buttons/KaraokeOverAlt.gif";
KaraokeOn = new Image();
KaraokeOn.src  = "/jimjak/art/menuimages/buttons/KaraokeIn.gif";
RaceOut = new Image();
RaceOut.src  = "/jimjak/art/menuimages/buttons/RaceOut.gif";
RaceOver = new Image();
RaceOver.src  = "/jimjak/art/menuimages/buttons/RaceOverAlt.gif";
RaceOn = new Image();
RaceOn.src  = "/jimjak/art/menuimages/buttons/RaceIn.gif";
ShowsOut = new Image();
ShowsOut.src  = "/jimjak/art/menuimages/buttons/ShowsOut.gif";
ShowsOver = new Image();
ShowsOver.src  = "/jimjak/art/menuimages/buttons/ShowsOverAlt.gif";
ShowsOn = new Image();
ShowsOn.src  = "/jimjak/art/menuimages/buttons/ShowsIn.gif";
ThemeOut = new Image();
ThemeOut.src  = "/jimjak/art/menuimages/buttons/ThemeOut.gif";
ThemeOver = new Image();
ThemeOver.src  = "/jimjak/art/menuimages/buttons/ThemeOverAlt.gif";
ThemeOn = new Image();
ThemeOn.src  = "/jimjak/art/menuimages/buttons/ThemeIn.gif";
JollyOut = new Image();
JollyOut.src  = "/jimjak/art/menuimages/buttons/JollyOut.gif";
JollyOver = new Image();
JollyOver.src  = "/jimjak/art/menuimages/buttons/JollyOverAlt.gif";
JollyOn = new Image();
JollyOn.src  = "/jimjak/art/menuimages/buttons/JollyIn.gif";
ContactOut = new Image();
ContactOut.src  = "/jimjak/art/menuimages/buttons/ContactOut.gif";
ContactOver = new Image();
ContactOver.src  = "/jimjak/art/menuimages/buttons/ContactOverAlt.gif";
ContactOn = new Image();
ContactOn.src  = "/jimjak/art/menuimages/buttons/ContactIn.gif";


//Objects.
/*
We will use an object to hold all information relevant to each clickable sidenav image.
*/

//argChildren is an array
//argOn & argOff are references to a TImage object
function TNavObject(argName, argOut, argOn, argOver, argHeight, argLink, argAlt, argMsg, argParent, argChildren) 
{
  //data
  this.name			= argName;	    //a text identifier, for use to identify image for rollovers. Not important outside of the page's html, used to identify each image: in <img name= ..... >
  this.off 			= argOut;	      //reference to an image object
  this.on			= argOn;			 //reference to an image object
  this.over			= argOver;	      //reference to an image object
  this.urlLink 		= argLink;		  //url to a page
  this.parent 		= argParent;	  //reference to a TNavObject or null
  this.children 	= argChildren;  //Array of strings or null
  this.alt			= argAlt;		    //alt tag
  this.msg			= argMsg;		//window status message
  this.height     	= argHeight;    // height of image
  //methods
  this.makeActive = makeActive;   //make the OFF state the same as the ON state
  this.asHTML   	= asHTML;       //a function to return a string of HTML using the object's parameters.
  this.childrenContains = childrenContains; //boolean - does the array of children (text ovjects) contain the current text reference ?
  return this;
}
  


//method of TNavObject
function makeActive() //mark this Nav object as active.
{
  this.off = this.over;
}

//method of TNavObject
function asHTML(argCurrent) //return the HTML for the page
{//if argCurrent is a child, return also the code for all child objects.
  var childObject;
  ret = ( (arrSidenav[argCurrent] != this) ? '<a href="' + this.urlLink + '" onMouseOver="window.status=\'' + this.msg +'\'; SwapImageInDiv(\'' + divId + '\',\'' + this.name + '\',\'' + this.over + '\');return true;" onMouseDown="window.status=\'' + this.msg +'\'; SwapImageInDiv(\'' + divId + '\',\'' + this.name + '\',\'' + this.on + '\');return true;" onMouseOut= "window.status=\'\'; SwapImageInDiv(\'' + divId + '\',\'' + this.name + '\',\'' + this.off + '\')">' : '');
  ret += '<img id="' + this.name + '" vspace="1" name="' + this.name + '" src="' + eval(this.off + '.src') + '" width="90" height="' + this.height + '" border="0" alt="' + this.alt + '">' + ( (arrSidenav[argCurrent] != this) ? '</a>' : '') + '<br>';

  //is argCurrect a child of this node? OR print all children if this is currently selected parent node (and there are any children!).
  
  if( this.childrenContains(argCurrent) || (this == arrSidenav[argCurrent] && this.children) || (argCurrent == 'all' && this.children) )
  {
	//print out the children.
	for(c = 0;c < this.children.length; c++)
	{
	  childObject = arrSidenav[this.children[c]];
	  ret += ( (arrSidenav[argCurrent] != childObject) ? '<a href="' + childObject.urlLink + '" onMouseOver="window.status=\'' + this.msg +'\'; SwapImageInDiv(\'' + divId + '\',\'' + childObject.name + '\',\'' + childObject.on + '\')" onMouseOut= "window.status=\'\'; SwapImageInDiv(\'' + divId + '\',\'' + childObject.name + '\',\'' + childObject.off + '\')">' : '');
      ret += '<img id="' + this.name + '" vspace="1" name="' + childObject.name + '" src="' + eval(childObject.off + '.src') + '" width="153" height="' + childObject.height + '" border="0" alt="' + childObject.alt + '">' + ( (arrSidenav[argCurrent] != childObject) ? '</a>' : '') + '<br>';
    }
  }
  return ret;
}




//method of TNavObject
function childrenContains(argCurrent)
{//boolean. look for argCurrent in this object's children array
  if (this.children == null)
    return false;
  for(c = 0; c < this.children.length; c++)
  {
    if(this.children[c] == argCurrent)
	  return true;
  }
  return false;
}


//Instantiate objects;
//list of all parent nav objects
  var arrParents = new Array('index','Bands','Disco','Karaoke','RaceNights','ShowsCabaret','ThemeMusic','JollyRogerHome','Contact'); //**** UPDATE THIS SO IT KNOWS ABOUT ALL PARENT OBJECTS ONLY (NOT CHILDREN).
//associative array of TNavObject objects.
  var arrSidenav = new Array();
  
/*initialize elements in the sidenav array.
Terminology: 
Parent = the sidenav elements like 'home' - blue roundangle shapes with text inside.
Child  = subnav elements, like 'Dual speed Switch 5 Plus'.

Explaination of arguments:
  arrSidenav['home']  =  new TNavObject('SNhome',    'swsackable_0','swsackable_1',  28          '/produits','OfficeConnect&reg; Home',      null,                null); 
               ^                          ^            ^          ^           ^                 ^                        ^                           ^                    ^
    Element name. This is           Internal name     These are references  This is          This is the URL for     This is the ALT text.       This is the array      This is an array of
    sent from HTML page             used to refer     to pre-loaded images, the image        the link.                                           element name of        children element names.
    to identify the current         to the image.     defined above.        height.                                                              this element's         See 'switches' for 
    navigation. NO duplicate        Just use SN                                                                                                  parent. It will only   correct syntax.
    names are allowed.              followed by a                                                                                                be required by                 
                                    sensible word.                                                                                               child elements.


*NOTE if you add elements (which presumably you will - after all this is only a template!!), make sure you add the parents (not children) to the arrParents array, above, in the correct order. Be sure to let the parents know who the children are, and vice-versa (the last 2 arguments).

*/
//this function holds the urls to goto after sliding the menu off - you can easily add add urls to the array if needed
  function locality(x){//This was called location but Opera produced an error when I used that name.Mabey it is a reserved word
		var locations = new Array('/jimjak/Bandsmenu.html?s','/jimjak/JollyRogerHome.htm?s');
		document.location.href = locations[x];
	}
	
  arrSidenav['index']	= new TNavObject('SNHome',' HomeOut',' HomeOn',' HomeOver',25,'/jimjak/index.html','Home','Home',null,null);

  arrSidenav['Bands']	= new TNavObject('SNBands','BandsOut','BandsOn','BandsOver',25,'javascript:Slide(\'MenuLayer\',-108,1,10,0,\'locality(0)\')','Live Bands','Rock it Live',null,null);
 
  arrSidenav['Disco']	= new TNavObject('SNDisco','DiscoOut','DiscoOn','DiscoOver',25,'/jimjak/Disco.htm','Disco','Disco Dave',null,null);
  
  arrSidenav['Karaoke']	= new TNavObject('SNKaraoke','KaraokeOut','KaraokeOn','KaraokeOver',25,'/jimjak/Karaoke.htm','Karaoke','Karaoke King',null,null);
  
  arrSidenav['RaceNights']	= new TNavObject('SNRace','RaceOut','RaceOn','RaceOver',25,'/jimjak/RaceNights.htm','Race Night','Horsing About',null,null);
  
  arrSidenav['ShowsCabaret']	= new TNavObject('SNShows','ShowsOut','ShowsOn','ShowsOver',25,'/jimjak/ShowsCabaret.htm','Shows','Cabaret Crazy',null,null);
  
  arrSidenav['ThemeMusic']   = new TNavObject('SNTheme','ThemeOut','ThemeOn','ThemeOver',25,'/jimjak/ThemeMusic.htm','Themes Nights','Themes',null,null);
  
  arrSidenav['JollyRogerHome']   = new TNavObject('SNJolly','JollyOut','JollyOn','JollyOver',25,'javascript:Slide(\'MenuLayer\',-108,1,10,0,\'locality(1)\')','Jolly Roger','Clowning About',null,null);
  
  arrSidenav['Contact']   = new TNavObject('SNContact','ContactOut','ContactOn','ContactOver',25,'/jimjak/Contact.htm','Contact Us','Talk to us',null,null);
  



//This is the string that will be put into the Layer
outPutStr = '<div id=' + divId + '>';
//The Div is to create the Layer to hold the Menu

//function called from HTML
function outPut(argCurrent) //eg. drawSidenav('dswitch16');
{
  //make current nav item active
  if(argCurrent != 'all')arrSidenav[argCurrent].makeActive();
  //draw all parent items.
  for(i = 0; i < arrParents.length; i++)
  {
     //build up the OutPut and store in outPutStr
	 outPutStr = outPutStr + arrSidenav[arrParents[i]].asHTML(argCurrent);//write to string ,write out each parent. As the parent is written, check to see whether argCurrent is the name of a child. If so, write out the children.
  }
  	outPutStr = outPutStr + '</div>';
	//Write the whole menu at once to the Div
	document.write(outPutStr);  //write the Layer with the menu inside it, to the page - This will happen as the page loads.
 	//writetoLyr(divId,outPutStr);  Cant use this method because the function does not work with Opera 
	
}

// check for the presance of the page name in the list of menu parent Nodes
var all_check = arrParents;
//if the page name is not in the list of menu parent Nodes, All parents are show - If child elements are added this will have to be changed because the child one will show too
if ((all_check.join().match(page_name) == null) || (page_name == '')){page_name = 'all'}


outPut(page_name);


/*
//-----Start Check all images loaded ----------------
//I am deleying the showmenu() until the Layer has definatly been writen to the page
//This is because NS6 tries to execute the JS before the layer is drawn  
//once all images are loaded the menu is shown
//if opera browser use goo()
if (navigator.appName == 'Opera'){
	//alert(navigator.appName);
	ContactOn.onload=goo()
}else{
	//alert('not opera');
	ContactOn.onload=goo
}

//When the last image is loaded run show_menu()
function goo(){
	show_menu();
}
   
 */ 

//-----------Check and Display Menu's Layer---------------
function show_menu(){	
	//if the slide was used on the calling pages menu then we must slide the menu back on to the screen
	//else it is dumped into view.
	if ( self.location.search  == '?s'){		
			//Slide(layer,distancex,inc,pause,distancey)	
			Slide('MenuLayer',108,1,10,0,null);	
		}else{
			findDOM('MenuLayer',1,null).left = 8;
		}
}		

/*
//alert("document.links(0)= "+ document.links['style1']);
if (ContactOut.complete == false){
alert("ContactOut.complete= "+ContactOut.complete);
//show_menu();
}
//if (images_loaded){alert(images_loaded);}
*/