
//
// Preload
//
img_pr_main  = new Image(); img_pr_main.src  = 'Images/i/pr_main.gif';
img_pr_over  = new Image(); img_pr_over.src  = 'Images/i/pr_over.gif';
img_pr_trans = new Image(); img_pr_trans.src = 'Images/i/pr_trans.gif';
img_pr_base  = new Image(); img_pr_base.src  = 'Images/i/pr_base.gif';
img_pr_platf = new Image(); img_pr_platf.src = 'Images/i/pr_platf.gif';

img_sh_main  = new Image(); img_sh_main.src  = 'Images/i/sh_main.gif';
img_sh_over  = new Image(); img_sh_over.src  = 'Images/i/sh_over.gif';
img_sh_trans = new Image(); img_sh_trans.src = 'Images/i/sh_trans.gif';
img_sh_tubes = new Image(); img_sh_tubes.src = 'Images/i/sh_tubes.gif';
img_sh_platf = new Image(); img_sh_platf.src = 'Images/i/sh_platf.gif';

shtock_timer = false;
priraz_timer = false;
visible_menu = false;
visible_menu = false
active_li    = false;


function show_menu(menu_id, li_id) {
    if (menu_id == 'shtock') {
        clearTimeout(shtock_timer);
    }
    else {
        clearTimeout(priraz_timer);
    }
    
    document.getElementById(menu_id).style.display = 'block';
    
    if (active_li) {
        document.getElementById(active_li).className = '';
    }

    if (li_id) {
        document.getElementById(li_id).className = 'hover';
        active_li = li_id;
    }
}

function hide_menu(menu_id) {
    if (menu_id == 'shtock') {
        shtock_timer = window.setTimeout("_hide('"+menu_id+"')", 500);
    }
    else {
        priraz_timer = window.setTimeout("_hide('"+menu_id+"')", 500);
    }
}

function _hide(menu_id) {
    var menu = document.getElementById(menu_id);
    menu.style.display = 'none';
    
    lis = menu.getElementsByTagName("li");
    for (i=0;i<lis.length;i++) {
        lis[i].className='';
    }

}


//
// Prirazlomnoe
//
pr_timer = false;
function pr_over() {
    show_menu('priraz', false);
    pr_img = document.getElementById('i_pr');
    if (pr_timer) clearTimeout(pr_timer);
    now_sh_main();
    pr_img.style.zIndex=6;
    pr_img.src = img_pr_over.src;
}

function pr_main() {
    hide_menu('priraz');
    pr_img = document.getElementById('i_pr');
    pr_timer = window.setTimeout("pr_img.src = img_pr_main.src; pr_img.style.zIndex=5;", 100);
}

function now_pr_main() {
    pr_img = document.getElementById('i_pr');
    pr_img.src = img_pr_main.src; 
    pr_img.style.zIndex=5;
    if (pr_timer) clearTimeout(pr_timer);
}

function pr_trans() {
    show_menu('priraz','li_pr_trans');
    pr_img = document.getElementById('i_pr');
    if (pr_timer) clearTimeout(pr_timer);
    now_sh_main();
    pr_img.style.zIndex=6;
    pr_img.src = img_pr_trans.src;
}

function pr_base() {
    show_menu('priraz','li_pr_base');
    pr_img = document.getElementById('i_pr');
    if (pr_timer) clearTimeout(pr_timer);
    now_sh_main();
    pr_img.style.zIndex=6;
    pr_img.src = img_pr_base.src;
}

function pr_platf() {
    show_menu('priraz','li_pr_platf');
    pr_img = document.getElementById('i_pr');
    if (pr_timer) clearTimeout(pr_timer);
    now_sh_main();
    pr_img.style.zIndex=6;
    pr_img.src = img_pr_platf.src;
}

//
// Shtockmanovskoe
//
sh_timer = false;
function sh_over() {
    show_menu('shtock', false);
    sh_img = document.getElementById('i_sh');
    if (sh_timer) clearTimeout(sh_timer);
    now_pr_main();
    sh_img.style.zIndex=6;
    sh_img.src = img_sh_over.src;
}

function sh_main() {
    hide_menu('shtock');
    sh_img = document.getElementById('i_sh');
    sh_timer = window.setTimeout("sh_img.src = img_sh_main.src; sh_img.style.zIndex=5;", 100);
}

function now_sh_main() {
    sh_img = document.getElementById('i_sh');
    sh_img.src = img_sh_main.src; 
    sh_img.style.zIndex=5;
    if (sh_timer) clearTimeout(sh_timer);
}

function sh_trans() {
    show_menu('shtock','li_sh_trans');
    sh_img = document.getElementById('i_sh');
    if (sh_timer) clearTimeout(sh_timer);
    now_pr_main();
    sh_img.style.zIndex=6;
    sh_img.src = img_sh_trans.src;
}

function sh_tubes() {
    show_menu('shtock','li_sh_tubes');
    sh_img = document.getElementById('i_sh');
    if (sh_timer) clearTimeout(sh_timer);
    now_pr_main();
    sh_img.style.zIndex=6;
    sh_img.src = img_sh_tubes.src;
}

function sh_platf() {
    show_menu('shtock','li_sh_platf');
    sh_img = document.getElementById('i_sh');
    if (sh_timer) clearTimeout(sh_timer);
    now_pr_main();
    sh_img.style.zIndex=6;
    sh_img.src = img_sh_platf.src;
}




function init() {
    //
    // Event handlers for bottom butons
    //
    buttons = new Array();
    buttons[0] = 'about';
    buttons[1] = 'projects';
    buttons[2] = 'activity';
    buttons[3] = 'contacts';
    
    button_images_over = new Array();
    button_images_down = new Array();
    button_images_base = new Array();
    
    for (i=0; i<buttons.length; i++) {
        button_images_base[i] = new Image(); button_images_base[i].src = 'TopImages/'+buttons[i]+'_Base.gif';
        button_images_over[i] = new Image(); button_images_over[i].src = 'TopImages/'+buttons[i]+'_Over.gif';
        button_images_down[i] = new Image(); button_images_down[i].src = 'TopImages/'+buttons[i]+'_Down.gif';
        
        obj = document.getElementById('butt_'+buttons[i]);
        obj.onmouseover = new Function("this.src=button_images_over["+i+"].src; return true;");
        obj.onmouseout  = new Function("this.src=button_images_base["+i+"].src; return true;");
        obj.onmousedown = new Function("this.src=button_images_down["+i+"].src; return true;");
        obj.onmouseup   = new Function("this.src=button_images_base["+i+"].src; return true;");
    }
    
    
    //
    // Functions for event handlers
    //
    var _pr_over_f  = new Function("pr_over(); return true;");
    var _pr_out_f   = new Function("pr_main(); return true;");
    var _pr_base_f  = new Function("pr_base(); return true;");
    var _pr_trans_f = new Function("pr_trans(); return true;");
    var _pr_platf_f = new Function("pr_platf(); return true;");

    var _sh_over_f  = new Function("sh_over(); return true;");
    var _sh_out_f   = new Function("sh_main(); return true;");
    var _sh_tubes_f = new Function("sh_tubes(); return true;");
    var _sh_trans_f = new Function("sh_trans(); return true;");
    var _sh_platf_f = new Function("sh_platf(); return true;");
    
    //
    // Event handlers for list items and menu headers
    //
    obj = document.getElementById('li_sh_platf');
    obj.onmouseover = _sh_platf_f;
    obj.onmouseout  = _sh_out_f;
    

    obj = document.getElementById('li_sh_tubes');
    obj.onmouseover = _sh_tubes_f;
    obj.onmouseout  = _sh_out_f;

    obj = document.getElementById('li_sh_trans');
    obj.onmouseover = _sh_trans_f;
    obj.onmouseout  = _sh_out_f;

    obj = document.getElementById('li_pr_platf');
    obj.onmouseover = _pr_platf_f;
    obj.onmouseout  = _pr_out_f;

    obj = document.getElementById('li_pr_base');
    obj.onmouseover = _pr_base_f;
    obj.onmouseout  = _pr_out_f;

    obj = document.getElementById('li_pr_trans');
    obj.onmouseover = _pr_trans_f;
    obj.onmouseout  = _pr_out_f;
    
    obj = document.getElementById('shtock');
    h1 = obj.getElementsByTagName('h1');
    h1[0].onmouseover = _sh_over_f;
    h1[0].onmouseout  = _sh_out_f;
    
    obj = document.getElementById('priraz');
    h1 = obj.getElementsByTagName('h1');
    h1[0].onmouseover = _pr_over_f;
    h1[0].onmouseout  = _pr_out_f;
    
    
    //
    // Event handlers for area maps
    //
    for (i=1;i<4;i++) {
        obj = document.getElementById('m_pr_ba'+i);
        obj.onmouseover = _pr_base_f;
        obj.onmouseout  = _pr_out_f;
    }

    for (i=1;i<3;i++) {
        obj = document.getElementById('m_pr_tr'+i);
        obj.onmouseover = _pr_trans_f;
        obj.onmouseout  = _pr_out_f
    }
    
    obj = document.getElementById('m_pr_pla');
    obj.onmouseover = _pr_platf_f;
    obj.onmouseout  = _pr_out_f
    
    obj = document.getElementById('m_pr');
    obj.onmouseover = _pr_over_f;
    obj.onmouseout  = _pr_out_f
    
    
    for (i=1;i<3;i++) {
        obj = document.getElementById('m_sh_tr'+i);
        obj.onmouseover = _sh_trans_f;
        obj.onmouseout  = _sh_out_f
    }

    obj = document.getElementById('m_sh_pla');
    obj.onmouseover = _sh_platf_f;
    obj.onmouseout  = _sh_out_f

    obj = document.getElementById('m_sh_tub');
    obj.onmouseover = _sh_tubes_f;
    obj.onmouseout  = _sh_out_f
    
    obj = document.getElementById('m_sh');
    obj.onmouseover = _sh_over_f;
    obj.onmouseout  = _sh_out_f


    return false;
}


