/* *******************************************************
J  a  v  a  c  a  t  z
Filename:   bodyOnLoader.js
Purpose:    This file is created to hold the function used
            in the onload="..." attribute of <body> tag.
            Please do not put other codes in this file.
Created by: KY 2009.10.02
******************************************************* */

function bodyOnLoader(currentNav,currentSubnav,currentSubnav2) {
	if($('nav-'+currentNav)) $('nav-'+currentNav).up('li').addClassName('current');
	if($('subnav-'+currentSubnav)) $('subnav-'+currentSubnav).up('li').addClassName('current');
	if($('sidenav-'+currentSubnav)) $('sidenav-'+currentSubnav).up('li').addClassName('current');
	if($('sidenav-'+currentSubnav2)) $('sidenav-'+currentSubnav2).up('li').addClassName('current');
	current_subnav_init();
	kyMenu.init('blind');

	// init flash font after init "current" nav, to apply "current" style
	var topSifr = new Font('arial.swf', { tags: 'span', classFilter: 'sifr', textalign: 'left' } );
	topSifr.replace();
}

document.observe('dom:loaded', domLoaded = function() {
	if($('loginLayer')) $('loginLayer').hide();
	project_init();
    disableOverlay.init();
	
    $$('ul').each(function(node) {
        var li = $(node).firstDescendant();
        if($(li)) li.addClassName('first');
        var lis = $(node).childElements();
        var li_last = $(node).childElements().last();
        if($(li_last)) li_last.addClassName('last');
    });
	
    $$('ol').each(function(node) {
        var li = $(node).firstDescendant();
        if($(li)) li.addClassName('first');
        var li_last = $(node).childElements().last();
        if($(li_last)) li_last.addClassName('last');
    });

    printbar_init();
    tableAltRow();
    listAltRow();

    /* screenmode */
    var screenmode = getParameter("screenmode");
    if (screenmode != null && screenmode != "") {
        if (screenmode.toLowerCase() == "print") printPage2();
    }
    if (getParameter("screenmode") == "print") {
        $$('select').each(function(node) { $(node).disabled = true; });
        $$('input').each(function(node) { $(node).disabled = true; });
    }
    /* ie flash object focus */
    // ieupdate();
    fixPNG();

    ky_backTop_init();
});

function current_subnav_init() {
	setInterval('current_subnav();',50);
}
function current_subnav() {
	var current_subnav_ul = $$('#topnav .current ul');
	if($$("#topnav .active").length==0) {
		current_subnav_ul.each( function(node) { $(node).style.visibility = "visible"; } );
	} else {
		current_subnav_ul.each( function(node) { if(!$($(node).parentNode).hasClassName("active")) $(node).style.visibility = "hidden"; } );
	}
}



window.onresize = function() {
	resizewindow();
}
function resizewindow() {
	if(disableOverlay) disableOverlay.onresize();
}


var disableOverlay = {
	init: function() {
		var layer_disable_overlay = new Element('div', { 'id':'layer_disable_overlay' }).hide();
		$('page').insert({ 'before':layer_disable_overlay });
	},
	show: function(duration, delay) {
		disableOverlay.onresize();
		if(!duration) duration = 0.25;
		if(!delay) delay = 0;
		$$('select').each( function(node) { $(node).addClassName('invisibleSelect'); } );
		new Effect.Appear( $('layer_disable_overlay'), { duration: duration, delay: delay });
	},
	hide: function(duration, delay) {
		if(!duration) duration = 0.25;
		if(!delay) delay = 0;
		new Effect.Fade( $('layer_disable_overlay'), { duration: duration, delay: delay, afterFinish: function() { $$('select').each( function(node) { $(node).removeClassName('invisibleSelect'); } ); } });
	},
	onresize: function() {
		if($('layer_disable_overlay')) {
			var viewportWidth = document.viewport.getWidth();
			var bodyWidth = $$('body').first().getWidth();
			var width = viewportWidth;
			if(bodyWidth > viewportWidth) width = bodyWidth;
			var viewportHeight = document.viewport.getHeight();
			var bodyHeight = $$('body').first().getHeight();
			var height = viewportHeight;
			if(bodyHeight > viewportHeight) height = bodyHeight;
			$('layer_disable_overlay').setStyle({ 'width': width + 'px', 'height': height + 'px' });
		}
	}
};

