/* *******************************************************
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 2008.09.30
******************************************************* */

function bodyOnLoader(currentSection, currentNav,currentSubnav,currentSidenav) {
	if($('preloadImages')) $('preloadImages').setStyle( {
		top: '-1000px',
		right: 'auto',
		bottom: 'auto',
		left: '-1000px'
	} );
	$$('#header h1').each( function(node) { $(node).addClassName('show'); } );
	$$('#header #language').each( function(node) { $(node).addClassName('show'); } );
	if($('section_'+currentSection)) $('section_'+currentSection).addClassName('current');
	if($('nav_'+currentNav)) $('nav_'+currentNav).addClassName('current');
	if($('subnav_'+currentSubnav)) $('subnav_'+currentSubnav).addClassName('current');
	if(!currentSidenav) currentSidenav = currentSubnav;
	if($('sidenav_'+currentSidenav)) $('sidenav_'+currentSidenav).addClassName('current');
	
	current_subnav_init();
	printbar_init();
	tableAltRow();
	
	// init flash font after init "current" nav, to apply "current" style
	Sifr_init();
	
	/* 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();
}
/*
document.observe('dom:loaded', domLoaded = function() {
	$$('ul').each( function(node) {
		var li = $(node).firstDescendant();
		if(li) li.addClassName('first');
	} );
	/*
	var arial2 = new Font('arial.swf', { tags: 'span', classFilter: 'sideSifr', textalign: 'left' } );
	arial2.replace();
	///
	var topSifr = new Font('arial.swf', { tags: 'span', classFilter: 'topSifr', textalign: 'center' } );
	topSifr.replace();
	
} );
*/
function Sifr_init() {
	$$('ul').each( function(node) {
		var li = $(node).firstDescendant();
		if(li) li.addClassName('first');
		var lis = $(node).select("li");
		li = lis[lis.length - 1];
		if(li) li.addClassName('last');
	} );
	var topSifr = new Font('arial.swf', { tags: 'span', classFilter: 'topSifr', textalign: 'center' } );
	topSifr.replace();
}


var current_subnav_ul;
function current_subnav_init() {
	current_subnav_ul = $$('#topnav .current ul');
	setInterval('current_subnav();',50);
}
function current_subnav() {
	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"; } );
	}
}



/* *** Layers Overlay *** */
var bool_layer_shown = new Array();
var array_layer_list = ['loginLayer'];
function toggle_layer(layer_id, param_close) {
	var layer_id_index;
	var temp_layer_area = new Array();
	for(var index=0; index<array_layer_list.length; index++) {
		if(array_layer_list[index]==layer_id) layer_id_index = index;
		temp_layer_area[index] = $(array_layer_list[index]);
	}
	if(temp_layer_area[layer_id_index]) {
		if(bool_layer_shown[layer_id_index] || param_close=='close') {
			bool_layer_shown[layer_id_index] = false;
			if($('layer_disable_overlay')) $('layer_disable_overlay').style.display = "none";
			for(var index=0; index<temp_layer_area.length; index++) {
				temp_layer_area[index].style.display = "none";
			}
		} else {
			bool_layer_shown[layer_id_index] = true;
			if($('layer_disable_overlay')) {
				$('layer_disable_overlay').style.display = "block";
				var temp_height = parseInt(getElementStyle2($$('body')[0],'height','height')) + 10;
				if(temp_height < displaySize('height')+10) temp_height = displaySize('height')+10;
				$('layer_disable_overlay').style.height = temp_height + 'px';
			}
			temp_layer_area[layer_id_index].style.display = "block";
			var temp_top = ( displaySize('height') - parseInt(getElementStyle2(temp_layer_area[layer_id_index],'height','height')) ) / 2;
			if(temp_top < 10) temp_top = 10;
			temp_layer_area[layer_id_index].style.top = temp_top + 'px';
			temp_layer_area[layer_id_index].style.left = (displaySize('width') - temp_layer_area[layer_id_index].getWidth()) / 2 - parseInt($('page').cumulativeOffset()[0]) + 'px';
		}
	}
}
window.onresize = function() {
	resizewindow();
}
function resizewindow() {
	var temp_height = parseInt(getElementStyle2($$('body')[0],'height','height')) + 10;
	if(temp_height < displaySize('height')+10) temp_height = displaySize('height')+10;
	// $('disable_overlay').style.height = displaySize('height')+10+'px';
	if($('layer_disable_overlay')) $('layer_disable_overlay').style.height = temp_height + 'px';
}
