/**
 * Performs the actions required to initialize a page properly on loading.
 * It ensures the use of frames, sets the browser to display the title of the
 * page currently shown, updates the outliner, and pre-loads the selected next and
 * previous images (to improve response time in showing these images when needed).
 */
function initializePage() {
    ensureFraming();
    top.document.title = document.title; //"top" ensures that the title is set correctly for SCORM complaint material, where there might be another frame wrapping around the course content.
    //May21st,2003: with the current default mode of course generation being to include navigation toolbar in the course 
    //banner, instead of in every course page, we no longer need to preload the mouse over images for each course page.
    //If generating content with navigation in course pages, as done in the past, the following two lines should 
    //be uncommented:
    //MM_preloadImages('course_graphics/icon_next_over.gif');
    //MM_preloadImages('course_graphics/icon_previous_over.gif');
    jumpToCoursePage();
}

//selects the current page on the tree
function jumpToCoursePage() {
    href = location.href.substring(location.href.lastIndexOf("/")+1, location.href.length);

    //extracts only the file name, removing any parameters (?) and local anchors (#) that might follow
    if (href.indexOf("#") != -1)
	href = href.substring(0, href.indexOf("#"));
    if (href.indexOf("?") != -1)
	href = href.substring(0, href.indexOf("?"));

    if (parent.theBrowser) {// if true, the menu is already installed, safe to run
        var entryToSelect= parent.theMenu.findEntry(href);
        if (entryToSelect != parent.theMenu.selectedEntry ) {
            parent.theMenu.itemClicked(entryToSelect);
            var menuChanged = parent.theMenu.setEntry(entryToSelect, true);
            if (menuChanged) parent.theMenu.refresh();
        }
    }
    return true;
}

//Based on ensure framing script from the JavaScript Bible, Gold Edition, by Danny Goodman
//Includes workaround for NS4-specific behaviour that prevents printing a frame - see book page 222 for more information
function ensureFraming () {
    var isNav4 = (navigator.appName == "Netscape" && parseInt (navigator.appVersion) == 4);
    var hrefPieces = window.location.href.split ("/");
    var selfFile = hrefPieces[hrefPieces.length - 1];
    if (parent.location.href == window.location.href) { //if true then we do need to place framing around
	if (isNav4){
            if (window.innerWidth != 0) {
                parent.location.href = "index.html?page=" + selfFile;
            }
        } else {
            parent.location.href = "index.html?page=" + selfFile;
        }
    }
}
