/////////////////////////////////////////////////////
//                                                 //
//  BROWSER SNIFFER & DOMS                         //
//  ---------------------------------------------  //
//  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 = ""
}


/////////////////////////////////////////////////////
//                                                 //
//  PRELOADING                                     //
//  ---------------------------------------------  //
//  Preload images memory for realtime animation.  //
//                                                 //
/////////////////////////////////////////////////////

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";

    sphere1 = new Image();
    sphere1.onload = (is.ns4b) ? loadCheck() : loadCheck;
    sphere1.src = "images/sphere1.gif";

    sphere2 = new Image();
    sphere2.onload  = (is.ns4b) ? loadCheck() : loadCheck;
    sphere2.src = "images/sphere2.gif";


    singmap = new Image();
    singmap.onload  = (is.ns4b) ? loadCheck() : loadCheck;
    singmap.src = "images/singmap.gif";

}

function loadCheck() {
    count++;
    if(count == 5) {
        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/5)*100) + '% BGCOLOR=#FF0000 ALIGN=RIGHT>' + '<FONT class="status">' + Math.round((count/5)*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;
        }
    }
}


/////////////////////////////////////////////////////
//                                                 //
//  POSITIONING                                    //
//  ---------------------------------------------  //
//  Build layer objects then position using        //
//  screen width and height dimensions, then       //
//  turn on layer visibility.                      //
//                                                 //
/////////////////////////////////////////////////////

function positionLayers() {
    sunObj = eval(doc + '["sunLyr"]' + sty);
    sunObj.left = available_width;
    sunObj.top = 190;
    sunObj.visibility = "visible";

    buttonImg = eval(doc + '["menuLyr"]' + '.document');
    menuObj = eval(doc + '["menuLyr"]' + sty);
    menuObj.left = 8;
    menuObj.top = 90;

    introObj = eval(doc + '["introLyr"]' + sty);
    introObj.left = available_width;
    introObj.top = 90;

    overviewObj = eval(doc + '["overviewLyr"]' + sty);
    overviewObj.left = available_width;
    overviewObj.top = 90;

    typesObj = eval(doc + '["typesLyr"]' + sty);
    typesObj.left = available_width;
    typesObj.top = 90;

    interestObj = eval(doc + '["interestLyr"]' + sty);
    interestObj.left = available_width;
    interestObj.top = 90;

    implementObj = eval(doc + '["implementLyr"]' + sty);
    implementObj.left = available_width;
    implementObj.top = 90;

    it2000Obj = eval(doc + '["it2000Lyr"]' + sty);
    it2000Obj.left = available_width;
    it2000Obj.top = 90;

    infrastructureObj = eval(doc + '["infrastructureLyr"]' + sty);
    infrastructureObj.left = available_width;
    infrastructureObj.top = 90;

    usingecObj = eval(doc + '["usingecLyr"]' + sty);
    usingecObj.left = available_width;
    usingecObj.top = 90;

    businessObj = eval(doc + '["businessLyr"]' + sty);
    businessObj.left = available_width;
    businessObj.top = 90;

    considerObj = eval(doc + '["considerLyr"]' + sty);
    considerObj.left = available_width;
    considerObj.top = 90;

    examplesObj = eval(doc + '["examplesLyr"]' + sty);
    examplesObj.left = available_width;
    examplesObj.top = 90;

    futureObj = eval(doc + '["futureLyr"]' + sty);
    futureObj.left = available_width;
    futureObj.top = 90;

    arrowObj = eval(doc + '["arrowLyr"]' + sty);
    arrowObj.left = available_width-40;
    arrowObj.top = 120;

    sphere1Img = eval(doc + '["sphere1Lyr"]' + '.document');
    sphere1Obj = eval(doc + '["sphere1Lyr"]' + sty);
    sphere1Obj.left = 7;
    sphere1Obj.top = available_height-200;

    sphere2Img = eval(doc + '["sphere2Lyr"]' + '.document');
    sphere2Obj = eval(doc + '["sphere2Lyr"]' + sty);
    sphere2Obj.left = parseInt(sphere1Obj.left) + 40;
    sphere2Obj.top = parseInt(sphere1Obj.top) + 74;

    singmapImg = eval(doc + '["singmapLyr"]' + '.document');
    singmapObj = eval(doc + '["singmapLyr"]' + sty);
    singmapObj.left = 7;
    singmapObj.top = available_height-200;

    bannerObj = eval(doc + '["bannerLyr"]' + sty);
    bannerObj.left = 8;
    bannerObj.top = 0;

    infoObj = eval(doc + '["infoLyr"]' + sty);
    infoObj.visibility = "hidden";
    infoObj.left = 7;
    if (is.ie4) {
	infoObj.top = 440;
    } else {
	infoObj.top = 410;
    }
 
    moveSun();
}

/////////////////////////////////////////////////////
//                                                 //
//  Initial Animation                              //
//  ---------------------------------------------  //
//  Show the sun moving from the right of the      //
//  page to the left                               //
//                                                 //
/////////////////////////////////////////////////////

var sun_timer = null;
var sun_delay = 1;
function moveSun() {
    var sun_x = parseInt(sunObj.left);
    var sun_dx = Math.round(available_width / 50);
    if (sun_x > 0) {
        sunObj.left = sun_x - sun_dx;
        sun_timer = setTimeout("moveSun()",sun_delay);
    } else {
        clearTimeout(sun_timer);
        sunObj.visibility = "hidden";

        menuObj.visibility = "visible";
        bannerObj.visibility = "visible";
        arrowObj.visibility = "visible";
        sunObj.left = 0;
        sunObj.visibility = "visible";

        menuToggle('intro');
    }
}
/////////////////////////////////////////////////////
//                                                 //
//  Button selector                                //
//  ---------------------------------------------  //
//                                                 //
/////////////////////////////////////////////////////

var menu_selection = "overview";
var new_menu_selection;
var swapping = false;
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;
    }
    hideInfo();
}

/////////////////////////////////////////////////////
//                                                 //
//  Menu Selector                                  //
//  ---------------------------------------------  //
//  Scroll out the old page and scroll in the new  //
//  page                                           //
//                                                 //
/////////////////////////////////////////////////////

function menuToggle(selection) {
    if ((swapping == false)  && (menu_selection != selection)){
       swapping = true;
        new_menu_selection = selection;
        if (selection == "intro") {
           var old_page = eval(menu_selection + "Obj");
           var new_page = eval(selection + "Obj");
           swapPageOut(new_page);
        } else {
           buttonImg[selection].src = button_dn.src;
           var old_page = eval(menu_selection + "Obj");

           var new_page = eval(selection + "Obj");
           swapPageOut(new_page);

           sunObj.left = 0;
  
           if(selection == "usingec" || selection == "business") {
               sphere1Obj.visibility = "visible";
               sphere2Obj.visibility = "visible";
       	       singmapObj.visibility = "hidden";
           } else if(selection == "it2000"){
               sphere1Obj.visibility = "hidden";
               sphere2Obj.visibility = "hidden";
	       singmapObj.visibility = "visible";
           } else {
               sphere1Obj.visibility = "hidden";
               sphere2Obj.visibility = "hidden";
	       singmapObj.visibility = "hidden";
           }	
        }
    }
}

var page_out_timer = null;
var page_in_timer = null;
var new_page;
function swapPageOut(newp) {
    new_page = newp;
    var old_page = eval(menu_selection + "Obj");
    var page_x = parseInt(old_page.left);
    var page_dx = Math.round((available_width - 220) / 4);
    if (page_x < available_width) {
        old_page.left = page_x + page_dx;
        page_timer = setTimeout("swapPageOut(new_page)",1);
    } else {
        clearTimeout(page_out_timer);
        page_out_timer = null;
        old_page.left = available_width;
        old_page.visibility = "hidden";
        swapPageIn(new_page);
    }
}


function swapPageIn(newp) {

    new_page = newp;
    new_page.visibility = "visible";
    var page_x = parseInt(new_page.left);
    var page_dx = Math.round((available_width - 220) / 4);
    if (page_x > (220 + page_dx)) {
        new_page.left = page_x - page_dx;
        page_in_timer = setTimeout("swapPageIn(new_page)",1);
    } else {
        clearTimeout(page_in_timer);
        page_in_timer = null;
        new_page.left = 220;
        if ((menu_selection != "intro") && (menu_selection != new_menu_selection)) {
           buttonImg[menu_selection].src = button_up.src;
        }
        menu_selection = new_menu_selection;
        if (menu_selection != "intro") {
            buttonImg[new_menu_selection].src = button_dn.src;
        }
        swapping = false;    
    }
}

/////////////////////////////////////////////////////
//                                                 //
//   Page Scroller                                 //
//  ---------------------------------------------  //
//  Scroll page up or down according to the 'dir'  //
//  and with the given speed                       //
//                                                 //
/////////////////////////////////////////////////////

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 < 90) {
            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 = 90;
            sunObj.left = 0;
        }
    }
}

/////////////////////////////////////////////////////////////
//							   //
//   Infomation Box                 			   //
//  -----------------------------------------------------  //
//  Display information below the Main Menu		   //
//							   //
/////////////////////////////////////////////////////////////

var info_timer = null;

function displayInfo(info) {
    if(info != null) {
        var msg = '<TABLE BORDER="0" BACKGROUND="images/blackscreen.gif" CELLPADDING="4" CELLSPACING="0" WIDTH="190"><TR><TD VALIGN="TOP"><FONT CLASS=INFO>' + info + '<FONT></TD></TR></TABLE>';
        if(is.ns4) {
            document.infoLyr.document.open();
            document.infoLyr.document.write(msg);
            document.infoLyr.document.close();
        } else {
            document.all.infoLyr.innerHTML = msg;
        }
        infoObj.visibility = "visible";
//        info_timer = setTimeout("infoLyr.visibility='hidden'", 6500);
    }
}

function hideInfo() {
    if(is.ie4 || is.ns4) {
        infoObj.visibility="hidden";
    }
}