/* *******************************************************
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.06.26
******************************************************* */

function bodyOnLoader(currentNav,currentSubnav,currentSubnav2) {
	if($('nav-'+currentNav)) $('nav-'+currentNav).addClassName('current');
	if($('subnav-'+currentSubnav)) $('subnav-'+currentSubnav).addClassName('current');
	if($('sidenav-'+currentSubnav)) $('sidenav-'+currentSubnav).addClassName('current');
	if($('sidenav-'+currentSubnav2)) $('sidenav-'+currentSubnav2).addClassName('current');
	current_subnav_init();
	if($$('body#homepage #side').length > 0) $$('body#homepage #side')[0].absolutize().setStyle({'top':'auto','bottom':'0'});

	if($('selectLangTogglePromotion')) {
		$('selectLangTogglePromotion').onchange = function(e) {
			var lang = $F('selectLangTogglePromotion');
			window.location = '/' + lang + '/Promotion.aspx';
		}
	}
	if($('selectLangToggleSubscribe')) {
		$('selectLangToggleSubscribe').onchange = function(e) {
			var lang = $F('selectLangToggleSubscribe');
			window.location = '/' + lang + '/Subscribe.aspx';
		}
	}
}

document.observe('dom:loaded', domLoaded = function() {
	$$('.slide').each( function(node) {
		$(node).hide();
		$(node).previous('a').writeAttribute({'href':'javascript:Prototype.emptyFunction();', 'onclick':'return false'}).addClassName('slideLink').setStyle({'cursor':'pointer'}).observe('click', function() { new Effect.toggle($(node), 'blind', { duration: 1.0 }); return false; });
	} );
	if($('loginLayer')) $('loginLayer').hide();
	kyMenu.init('blind');
	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' });
		}
	}
};
