var isIE4;
var isNav4;
var isNav6;

// Determine which browser is used
function setbrowser() {
	if (navigator.appVersion.charAt(0) == "4") {
		if (navigator.appName.indexOf("Explorer") >= 0) {
			isIE4 = true;
		}
		else {
			isNav4 = true;
		}
	}
	else if (navigator.appVersion.charAt(0) > "4") {
		isNav6 = true;
	}
}

setbrowser();

//open external window
function MM_openBrWindow(theURL,winName,features) {
  window.open(theURL,winName,features);
}


// preload images
function wmLoadImage() { //v2.0
  if (document.images) {
    var imgFiles = wmLoadImage.arguments;
    if (document.preloadArray==null) document.preloadArray = new Array();
    var i = document.preloadArray.length;
    with (document) for (var j=0; j<imgFiles.length; j++) if (imgFiles[j].charAt(0)!="#"){
      preloadArray[i] = new Image;
      preloadArray[i++].src = imgFiles[j];
  } }
}

var CSAg = window.navigator.userAgent; 
var CSBVers = parseInt(CSAg.charAt(CSAg.indexOf("/")+1),10);


function IsIE() { return window.navigator.userAgent.indexOf("MSIE") > 0;}
function CSIEStyl(s) { return document.all.tags("div")[s].style; }
function CSNSStyl(s) { return CSFindElement(s,0); }


function CSFindElement(n,ly) { if (CSBVers < 4) return document[n];
	var curDoc = ly ? ly.document : document; var elem = curDoc[n];
	if (!elem) { for (var i=0;i<curDoc.layers.length;i++) {
		elem = CSFindElement(n,curDoc.layers[i]); if (elem) return elem; }}
	return elem;
}

e_CurrentChapter = "";
e_CurrentBook    = "";

e_CurrentSub     = "";

function wmSwitch(imageObject, imageAction) {
	var img = null;
	if (document.images) { 
	    if((!(e_CurrentChapter == imageObject)) && !(e_CurrentBook == imageObject )) {    
             if (!IsIE()) img = CSFindElement(imageObject[0],0);
		     else img = document.images[imageObject[0]];
		     
		     if (img) {
		           if(imageAction == 'on') {
		                 img.src = imageObject[2];
		           } else {
		                 img.src = imageObject[1];
		           }
		      }  
		}                          
	}	                    
}


function wmSetImage(imageObject) {
	var img = null;
	if (document.images) {    
		if (!IsIE()) img = CSFindElement(imageObject[0],0);
		else img = document.images[imageObject[0]];
		     
		if (img) {
			img.src = imageObject[1];
		}
	}  
}


function eSetSub(newSubmenu) {
   eSwitchImage(newSubmenu, 'on');
   e_CurrentSub = newSubmenu;  
}  

function eSetChapter(newChapter) {
   oldChapter = e_CurrentChapter;
   e_CurrentChapter = newChapter;
   eSwitchImage(oldChapter, 'off');    
}  

function eSetBook(newBook) {
   oldBook = e_CurrentBook;
   e_CurrentBook = newBook;
   eSwitchImage(oldBook, 'off');    
}  


 
       var current_popup     = "";
       var current_root      = "";
       var current_secondary = "";
 
	function wm_menuOpen(n,root) {
       		// check if the current chapter is the root
       		// of the submenu provided
			current_root = root;
       		//if((!(e_CurrentChapter == root))) {
             //leave_submenu();

             var layer_id = n;
             ae_showLayer(n);

             current_popup=n;
            //}
       }
       
       function enter_secondary(n) {
             ae_showLayer(n);
             current_secondary=n;
       }
       
       function leave_secondary() {
             if(current_secondary != ""){
                   var layer_id = current_secondary;
                    ae_hideLayer(layer_id);
             }
        }
   
       function wm_menuClose() {
             if(current_popup != ""){
                   var layer_id = current_popup;
                    ae_hideLayer(layer_id);
             }
        }

function ae_showLayer(layerName){
	if (isNav4) {
		n_layer = document.layers[layerName];
	}
	else if (isIE4) {
		n_layer = document.all(layerName).style;
	}
	else if (isNav6) {
		n_layer = document.getElementById(layerName).style;
	}
	
		n_layer.visibility="visible";
}

function ae_hideLayer(layerName){
	n_layer = null;
	if (isNav4) {
		n_layer = document.layers[layerName];
	}
	else if (isIE4) {
		n_layer = document.all(layerName).style;
	}
	else if (isNav6) {
		n_layer = document.getElementById(layerName).style;
	}
	
	if(n_layer != null) {
		n_layer.visibility="hidden";
    }
}


