/*" edg.js version 1.3 modified by Jon to put onload script into a function to be called by onContent. Customizes image zooming and expanding menu. "*/
function loadOnContent() {
	loadZoomTriggers();
	createNavMenu();
	hideBorderOnLoad();
}
/*" ____________________ Enable image zooming. ____________________ "*/
function showGloss(chapterNum) {
    document.getElementById("chapter" + chapterNum).style.display = "block" ;
}
function hideGloss(chapterNum) {
    document.getElementById("chapter" + chapterNum).style.display = "none" ;
}
function loadZoomTriggers () {
	// body...
	new ZoomTrigger({ 
	    wrappedElement: document.getElementById(  "div-to-expand-wattenberg"  ) , 
	    containerElement: document.getElementById("content-home"),
	    expandToWidth: "150px",
	    functionAtEnd: function() { showGloss(1) } ,
	    functionReturning: function() { hideGloss(1) },
	    functionOnClick: function() {document.getElementById( "menulink-genre-1" ).menuItem.respond( {  menuItemEle: document.getElementById(    "menulink-genre-1"    )  } ); hideGloss(1) } ,
	    justification: "upper-left"
	 }) ;
	new ZoomTrigger({ 
	    wrappedElement: document.getElementById(  "div-to-expand-finalfantasy"  ) , 
	    containerElement: document.getElementById("content-home") ,
	    expandToWidth: "150px",
	    functionAtEnd: function() { showGloss(2) } ,
	    functionReturning: function() { hideGloss(2) },
	    functionOnClick: function() {document.getElementById( "menulink-genre-2" ).menuItem.respond( {  menuItemEle: document.getElementById(    "menulink-genre-2"    )  } ); hideGloss(2) } ,
	    justification: "lower-right"
	 }) ;
	new ZoomTrigger({ 
	    wrappedElement: document.getElementById(  "div-to-expand-norton"  ) , 
	    containerElement: document.getElementById("content-home") ,
	    expandToWidth: "150px",
	    functionAtEnd: function() { showGloss(3) } ,
	    functionReturning: function() { hideGloss(3) },
	    functionOnClick: function() {document.getElementById( "menulink-genre-3" ).menuItem.respond( {  menuItemEle: document.getElementById(    "menulink-genre-3"    )  } ); hideGloss(3) } ,
	    justification: "center-right"
	 }) ;
	 new ZoomTrigger({ 
	    wrappedElement: document.getElementById(  "div-to-expand-rsg"  ) , 
	    containerElement: document.getElementById("content-home") ,
	    expandToWidth: "150px" ,
	    justification: "upper-right",
	    functionAtEnd: function() { showGloss(4) } ,
	    functionReturning: function() { hideGloss(4) },
	    functionOnClick: function() {document.getElementById( "menulink-genre-4" ).menuItem.respond( {  menuItemEle: document.getElementById(    "menulink-genre-4"    )  } ); hideGloss(4) } ,
	    triggerHeight: "100px"
	 }) ;
	new ZoomTrigger({ 
	    wrappedElement: document.getElementById(  "div-to-expand-lovejoy"  ) , 
	    containerElement: document.getElementById("content-home") ,
	    expandToWidth: "150px" ,
	    functionAtEnd: function() { showGloss(5) } ,
	    functionReturning: function() { hideGloss(5) },
	    functionOnClick: function() {document.getElementById( "menulink-genre-5" ).menuItem.respond( {  menuItemEle: document.getElementById(    "menulink-genre-5"    )  } ); hideGloss(5) } ,
	    justification: "lower-left"
	 }) ;
	new ZoomTrigger({ 
	    wrappedElement: document.getElementById(  "div-to-expand-davis"  ) , 
	    containerElement: document.getElementById("content-home") ,
	    functionAtEnd: function() { showGloss(6) } ,
	    functionReturning: function() { hideGloss(6) },
	    functionOnClick: function() {document.getElementById( "menulink-genre-6" ).menuItem.respond( {  menuItemEle: document.getElementById(    "menulink-genre-6"    )  } ); hideGloss(6) } ,
	    expandToWidth: "150px"
	 }) ;
	 // sIFR doesn't seem to work on text that is initially hidden. DEPRECATED.
	 for (var chapterNum = 1 ; chapterNum <= 6 ; chapterNum++ ) {
	     hideGloss(chapterNum) ;
	 }
}
/*" ____________________ Enable expanding menu. ____________________ "*/
//____________________ Global utilities for all menus ___________________ //
ExpandingMenu.prototype.setMenuResponse = function(argObj) {
    // This particular response function must be called after parent-child relationships established.
    var menuSelected = this.htmlElement.id + "Obj" ;
    var responseFunVar = " " ;
    for ( var menuNum = 0; menuNum < argObj.menusNotSelected.length ; menuNum++ ) {
        responseFunVar += " " + argObj.menusNotSelected[menuNum] + ".setInitialCondition( " + argObj.menusNotSelected[menuNum] + ".itemManager[0] ); " ;
    }
    // Collapse menu selected if you clicked on a child (expand if you didn't).
    if ( this.itemManager[argObj.item].linkType == "child" ) {
        responseFunVar += " " + menuSelected + ".setInitialCondition(" + menuSelected + ".itemManager[0] );" ;
        responseFunVar += " " + menuSelected + ".itemManager[" + argObj.item + "].htmlElement.style.display = 'block' ; " ;
        responseFunVar += " " + menuSelected + ".itemManager[" + argObj.item + "].htmlElement.style.color = 'black' ; "; // Emulates visited link color (linkblack).
        responseFunVar += " " + menuSelected + ".itemManager[" + argObj.item + "].htmlElement.style.border = 'dimgray solid 1px' ; " ; // logo shadow.
        
    }
    for ( var menuNum = 0; menuNum < argObj.menusNotSelected.length ; menuNum++ ) {
        responseFunVar += " " + argObj.menusNotSelected[menuNum] + ".hideAllContent(); " ;
    }
    return responseFunVar ;
}
ExpandingMenu.prototype.prepareMenu = function() {
    //Associate superlinks with sublinks. UPGRADE: NEW FEATURE--add to ExpandingMenu.js as example.
    // Assume the first link may be a parent.
    menuParentCandidateObj = this.itemManager[0] ;
    for (var item=1; item < this.itemManager.length; item++) {
        // If the link id has no hyphen, then assume it may be a parent.
        if (this.itemManager[item].htmlElement.id.indexOf("-") == -1 ) {
            menuParentCandidateObj = this.itemManager[item] ;
             // _parentCandidate = this.itemManager[item].htmlElement.id ; debug("_parentCandidate") ;
        }
        // If the link id has a hyphen, associate it with the parent.
        else {
            menuParentCandidateObj.associateChildren(  [ this.itemManager[item] ]  ) ;
             // _childCandidate = this.itemManager[item].htmlElement.id ; debug("_childCandidate") ;
        }
    }
    //Here we automate these assignments for each particular application.
    //Associate all the content using a formulaic approach.
    for (var counter=0; counter < this.itemManager.length; counter++) {
        var contentIdStr = "content-" + this.itemManager[counter].htmlElement.id;
        this.itemManager[counter].associateContent( document.getElementById(contentIdStr) );
    }
    // Set classes and custom menu response using formulaic approach based on id nomenclature.
    // UPGRADE: think of a way to use className here. The problem is applying styles without knowing which class the target has.
    for (var item=0; item < this.itemManager.length; item++) {
        var itemClassesObj = {
            argBachelorUnselected: "menulink-bachelor-unselected", 
            argBachelorSelected: "menulink-bachelor-selected", 
            argParentCollapsedUnselected: "menulink-parent-collapsed-unselected",
            argParentCollapsedSelected: "menulink-parent-collapsed-selected",
            argParentExpandedUnselected: "menulink-parent-expanded-unselected",
            argParentExpandedSelected: "menulink-parent-expanded-selected",
            argChildUnselected: "menulink-child-unselected",
            argChildSelected: "menulink-child-selected",
            argMouseover: "this.style.cursor = 'pointer'; this.style.color = 'black' ; " , // These styles should be logically independent of styles set in CSS.
            argMouseout: "this.style.cursor = 'default'; this.style.color = 'dimgray' ; "
        } // mouseover color = logo shadow 
        /* UNUSED. Use if you want a special style for parent menu items.
        if (this.itemManager[item].linkType != "child") {
            itemClassesObj.argMouseover = "this.style.cursor = 'pointer'; this.style.border = 'black solid 1px' ; " ; // logo shadow.
            itemClassesObj.argMouseout = "this.style.cursor = 'default'; this.style.border = 'white solid 1px'; "
        }
        */
        this.itemManager[item].setClasses( itemClassesObj ) ;
    }
    // Initialize the menu and choose an initial item to select.
    this.setInitialCondition( this.itemManager[0] );
}
function nextContent(anchorEle) {
    // nextContent should be called from <a> in content div. Typically anchorEle would be "this", or if you're in a nested div, "this.parentNode".
    // UPGRADE: not sure this version will always leap across menus and all other obstacles. You could add a for loop to find the next content div.
    // UPGRADE: test if anchorEle is <a>, if not then do something else?
    // First trap for spaces between content divs.
    if (anchorEle.parentNode.nextSibling.nodeType == 1) { // Must be a tag, not just text (white space).
        var menuItemObj = anchorEle.parentNode.nextSibling.menuItem;
    }
    else {
        var menuItemObj = anchorEle.parentNode.nextSibling.nextSibling.menuItem; 
    }
    menuItemObj.respond({ menuItemEle: menuItemObj.htmlElement }) ;
}
function respondAsIf(menuItemEleArg) {
    menuItemEleArg.menuItem.respond({menuItemEle: menuItemEleArg}) ;
}
//____________________ Special functions for this page ___________________ //
function hideSplashDescription() {
    document.getElementById("splash-content").style.display = 'none' ;
}
function createNavMenu () {
	navMenu0Obj = new ExpandingMenu({ menuId: "navMenu0", isTwoLevelMenu: true, useDefaultContentManagement: true} ) ;
	navMenu0Obj.prepareMenu() ;
}
function endLoadingMessage() {
    document.getElementById("loading-message").style.display = 'none' ;
    document.getElementById("content-container").style.display = 'block' ;
}
//____________________ Special response functions ___________________ //
function hideBorderOnLoad () {
// Turn off border on load, to encourage people to click on first item.
	navMenu0Obj.itemManager[0].htmlElement.className = "menulink-parent-collapsed-unselected" ;
}
//____________________ Generate printable text ___________________ //
// navMenu0Obj.generatePrintableText() ; Unused here.
//____________________ DEBUG ___________________ //
// alert(document.getElementById("share").menu)
