
// BROWSER SNIFFER (Sniff out the good and bad browsers)//

function Is() {
    var agent = navigator.userAgent.toLowerCase();
    this.major = parseInt(navigator.appVersion);
    this.minor = parseFloat(navigator.appVersion);
    this.ns  = ((agent.indexOf('mozilla')!=-1) && ((agent.indexOf('spoofer')==-1) && (agent.indexOf('compatible') == -1)));
    this.ns2 = (this.ns && (this.major == 2));
    this.ns3 = (this.ns && (this.major == 3));
    this.ns4b = (this.ns && (this.minor < 4.04));
    this.ns4 = (this.ns && (this.major >= 4));
    this.ie   = (agent.indexOf("msie") != -1);
    this.ie3  = (this.ie && (this.major == 2));
    this.ie4  = (this.ie && (this.major >= 4));
    this.op3 = (agent.indexOf("opera") != -1);
    this.win   = (agent.indexOf("win")!=-1);
    this.mac   = (agent.indexOf("mac")!=-1);
    this.unix  = (agent.indexOf("x11")!=-1);
}

var is = new Is();

function onerror() {
    document.location.href = "javascript:";
}

// DOCUMENT OBJECT SWITCH (Used for building cross_browser functions)//

if(is.ns4) {
    doc = "document";
    sty = "";
    htm = ".document"
} else if(is.ie4) {
    doc = "document.all";
    sty = ".style";
    htm = ""
}

var count = 0;

function preLoad() {
    button_up = new Image();
    button_up.onload = (is.ns4b) ? loadCheck() : loadCheck;
    button_up.src = "images/button_up.gif";

    button_dn = new Image();
    button_dn.onload = (is.ns4b) ? loadCheck() : loadCheck;
    button_dn.src = "images/button_dn.gif";
}

function loadCheck() {
    count++;
    if(count == 2) {
        var status = eval(doc + '["msgLyr"]' + sty);
        status.visibility = "hidden";
        positionLayers();
    } else {
        var status = eval(doc + '["msgLyr"]' + htm);
        var msg = '<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=5 WIDTH=300><TR><TD WIDTH=' + Math.round((count/2)*100) + '% BGCOLOR=#FF0000 ALIGN=RIGHT>' + '<FONT class="status">' + Math.round((count/2)*100) + '%</FONT>' +'</TD><TD BGCOLOR=#800000 VALIGN=MIDDLE>&nbsp;</TD></TR><TR><TD COLSPAN=2 ALIGN=CENTER><FONT class="main">Percent Images Loaded</FONT></TD></TR></TABLE>';
        if(is.ns4) {
            status.write(msg);
            status.close();
        } else if(is.ie4) {
            status.innerHTML = msg;
        }
    }
}

function positionLayers() {
    arrowObj = eval(doc + '["arrowLyr"]' + sty);
    arrowObj.left = available_width-40;
    arrowObj.top = 20;
	
	storyObj = eval(doc + '["storyLyr"]' + sty);
    storyObj.left = 10;
    storyObj.top = 10;
	
	firstObj = eval(doc + '["firstLyr"]' + sty);
    firstObj.left = 10;
    firstObj.top = 10;
	
	diagObj = eval(doc + '["diagLyr"]' + sty);
    diagObj.left = 10;
    diagObj.top = 10;
	
	treatObj = eval(doc + '["treatLyr"]' + sty);
    treatObj.left = 10;
    treatObj.top = 10;
	
	helpObj = eval(doc + '["helpLyr"]' + sty);
    helpObj.left = 10;
    helpObj.top = 10;
	
	siteObj = eval(doc + '["siteLyr"]' + sty);
    siteObj.left = 10;
    siteObj.top = 10;
	
    buttonImg = eval(doc + '["menuLyr"]' + '.document');
    menuObj = eval(doc + '["menuLyr"]' + sty);
    menuObj.left = available_width-155;
    menuObj.top = available_height-180;

    arrowObj.visibility = "visible";
	storyObj.visibility = "visible";
	menuObj.visibility = "visible";
			
	menuToggle('story');
    buttonOver('story');
}

var menu_selection = "story";

function buttonOver(selection,pos) {
    if(menu_selection != selection) {
        buttonImg[selection].src = button_dn.src;
    }
}

function buttonOut(selection) {
    if(menu_selection != selection) {
        buttonImg[selection].src = button_up.src;
    }
}

function menuToggle(selection) {
    buttonImg[menu_selection].src = button_up.src;
    buttonImg[selection].src = button_dn.src;

    var old_page = eval(menu_selection + "Obj");
    old_page.visibility = "hidden";

    var new_page = eval(selection + "Obj");
    new_page.visibility = "visible";

    menu_selection = selection;

}

/////////////////////////////////////////////////////
//                                                 //
//  SECTION 9: INTERACTIVITY (Page Scroller)       //
//  ---------------------------------------------  //
//  Layer animation technique for srolling page.   //
//                                                 //
/////////////////////////////////////////////////////

var loop = true;
var direction = "up";
var speed = 10;
var timer1 = null;

function scroll(dir,spd) {
    direction = dir;
    speed = spd;
    var page = eval(menu_selection + "Obj");
    var y_pos = parseInt(page.top);
    	
    if(loop == true) {
        if(direction == "dn") {
            page.top = (y_pos-(speed));
            
            clearTimeout(timer1);
            timer1 = setTimeout("scroll(direction,speed)", 1);
        } else if(direction == "up" && y_pos < 10) {
            page.top = (y_pos+(speed));
            
            clearTimeout(timer1);
            timer1 = setTimeout("scroll(direction,speed)", 1);
        } else if(direction == "top") {
            page.top = 10;
            }
    }
}