/////////////////////////////////////////////////////
//                                                 //
//  SECTION 5: BROWSER SNIFFER & fourth                                //
//  ---------------------------------------------  //
//  Document Object switch routine use to          //
//  maintain cross-browser compatibility.          //
//                                                 //
/////////////////////////////////////////////////////


// 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 = ""
}

/////////////////////////////////////////////////////
//                                                 //
//  SECTION 6: fifth                          //
//  ---------------------------------------------  //
//  Preload images memory for realtime seventh.  //
//                                                 //
/////////////////////////////////////////////////////

var count = 0;

function preLoad() {
    button_up = new Image();
    button_up.onload = (is.ns4b) ? loadCheck() : loadCheck;
    button_up.src = "img/button_up.gif";

    button_dn = new Image();
    button_dn.onload = (is.ns4b) ? loadCheck() : loadCheck;
    button_dn.src = "img/button_dn.gif";
}

function loadCheck() {
    count++;
    if(count == 2) {
        var status = eval(doc + '["msgLyr"]' + sty);
        status.visibility = "hidden";
        positionthird();
    } else {
        var status = eval(doc + '["msgLyr"]' + htm);
        var msg = '<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=5 WIDTH=300><TR><TD WIDTH=' + Math.round((count/17)*100) + '% BGCOLOR=#FF0000 ALIGN=RIGHT>' + '<FONT class="status">' + Math.round((count/17)*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;
        }
    }
}

/////////////////////////////////////////////////////
//                                                 //
//  SECTION 7: sixth                         //
//  ---------------------------------------------  //
//  Build layer objects then position using        //
//  screen width and height dimensions, then       //
//  turn on layer visibility.                      //
//                                                 //
/////////////////////////////////////////////////////

function positionthird() {
    sunObj = eval(doc + '["sunLyr"]' + sty);
    sunObj.left = 0;
    sunObj.top = 190;

    buttonImg = eval(doc + '["menuLyr"]' + '.document');
    menuObj = eval(doc + '["menuLyr"]' + sty);
    menuObj.left = 8;
    menuObj.top = 0;

    zeroObj = eval(doc + '["zeroLyr"]' + sty);
    zeroObj.left = 160;
    zeroObj.top = 10;

    firstObj = eval(doc + '["firstLyr"]' + sty);
    firstObj.left = 160;
    firstObj.top = 10;

    secondObj = eval(doc + '["secondLyr"]' + sty);
    secondObj.left = 160;
    secondObj.top = 10;

    thirdObj = eval(doc + '["thirdLyr"]' + sty);
    thirdObj.left = 160;
    thirdObj.top = 10;

    fourthObj = eval(doc + '["fourthLyr"]' + sty);
    fourthObj.left = 160;
    fourthObj.top = 10;

    backObj = eval(doc + '["backLyr"]' + sty);
    backObj.left = 160;
    backObj.top = 10;

    arrowObj = eval(doc + '["arrowLyr"]' + sty);
    arrowObj.left = available_width-40;
    arrowObj.top = 20;


    sunObj.visibility = "visible";
    menuObj.visibility = "visible";
    arrowObj.visibility = "visible";

    menuToggle('zero');
    buttonOver('zero');
}


/////////////////////////////////////////////////////
//                                                 //
//  SECTION 9: back (Menu Selector)       //
//  ---------------------------------------------  //
//  Techniques for toggling and selecting buttons  //
//  then displaying the selected page while hiding //
//  previous page.                                 //
//                                                 //
/////////////////////////////////////////////////////

var menu_selection = "zero";

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";

    sunObj.left = 0;

     menu_selection = selection;

}

/////////////////////////////////////////////////////
//                                                 //
//  SECTION 9: back (Page Scroller)       //
//  ---------------------------------------------  //
//  Layer seventh 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);
    var x_pos = parseInt(sunObj.left);
    if(loop == true) {
        if(direction == "dn") {
            page.top = (y_pos-(speed));
            if(x_pos < available_width) {
                sunObj.left = x_pos + 1;
            } else {
                sunObj.left = -100;
            }
            clearTimeout(timer1);
            timer1 = setTimeout("scroll(direction,speed)", 1);
        } else if(direction == "up" && y_pos < 10) {
            page.top = (y_pos+(speed));
            if(x_pos > -100) {
                sunObj.left = x_pos - 1;
            } else {
                sunObj.left = available_width;
            }
            clearTimeout(timer1);
            timer1 = setTimeout("scroll(direction,speed)", 1);
        } else if(direction == "top") {
            page.top = 10;
            sunObj.left = 0;
        }
    }
}
