//===================================================================
//
//	***  browser CSS  ***
//
//===================================================================

//-----------------------------------------------------
//ie b.g. cache fix
//-----------------------------------------------------
try {
	document.execCommand("BackgroundImageCache", false, true);
} catch(err) {}

//-----------------------------------------------------
//magical lines for ie
//-----------------------------------------------------
/*@cc_on _d=document;eval('var document=_d')@*/


//-----------------------------------------------------
//easy getelementbyid
//-----------------------------------------------------
function $(id) {
	e = document.getElementById(id);
	return e;
}

//-----------------------------------------------------
//variable definition
//-----------------------------------------------------

//OS
var mac = (navigator.appVersion.indexOf("Mac") != -1)? true : false;

//browser
var nn = (navigator.appName.indexOf("Netscape",0) != -1)? true : false;
var nn4 = (document.layers)? true : false;
var nn6 = (navigator.userAgent.indexOf("Netscape6") != -1)? true : false;
var opera = (navigator.userAgent.indexOf("Opera") != -1)? true : false;
var opera5 = (navigator.userAgent.indexOf("Opera/5") != -1)? true : false;
var opera6 = (navigator.userAgent.indexOf("Opera/6") != -1)? true : false;
var icab = (navigator.userAgent.indexOf("iCab") != -1)? true : false;
var ie5 = (navigator.userAgent.indexOf("MSIE 5") != -1)? true : false;
var safari = (navigator.userAgent.indexOf("Safari") != -1)? true : false;
var cssFile;

//-----------------------------------------------------
//set CSS
//-----------------------------------------------------

if(opera){
	cssFile = "/common/css/fix_all_opera.css";
}
if(mac){
	if(safari){
		cssFile = "/common/css/fix_mac_safari.css";
	} else if(ie5){
		cssFile = "/common/css/fix_mac_ie.css";
	}
} else {
	if(nn6){
		cssFile = "/common/css/fix_win_nn6.css";
	}
}

if(cssFile){
	document.open();
	document.write('<link rel="stylesheet" href="' + cssFile + '" type="text/css">');
	document.close();
}

//-----------------------------------------------------
//attach load event
//-----------------------------------------------------
function attachLoadEvent() {

	// set default
	$('contentBox').style.position = "absolute";
	$('bgCurtain').style.position = "absolute";
	if ( document.getElementsByTagName('ul')[0] != null ) {
		document.getElementsByTagName('ul')[0].style.textIndent ="-9999px";
	}
	$('bgCurtain').onmouseover = function() {
		leaveAllCountry();
	}
	$('hideSwitch').onmouseover = function() {
		leaveAllCountry();
	}
	document.body.style.backgroundPosition ="center center";

	// hide all sub menus
	var obj = document.getElementsByTagName('ul');
	for ( i = 0, objLength = obj.length ; i < objLength ; i ++ ) {
		obj[i].style.textIndent = "-9999px";
	}
	// set function
	var obj = document.getElementsByTagName('a');
	for ( i = 0, objLength = obj.length ; i < objLength ; i ++ ) {
		cn = obj[i].className.toLowerCase().split(' ');
		for ( j = 0, varCnt = cn.length ; j < varCnt ; j ++ ) {
			if ( cn[j] == 'countryname' ) {
				obj[i].onmouseover = function() {
					visitCountry(this);
				}
			}
		}
	}
}

//-----------------------------------------------------
// visit Country function
// rollover / out function collections
//-----------------------------------------------------
function visitCountry(country) {
	cn = country.parentNode.parentNode.getAttribute("id");
	$('hilight').className = "png " + cn;
	if (country.parentNode.parentNode.innerHTML.toLowerCase().indexOf('<ul') != -1) {
		country.parentNode.parentNode.getElementsByTagName('ul')[0].style.textIndent ="0";
	}
	thisID = country.parentNode.parentNode.getAttribute("id");
	wholeCountries = country.parentNode.parentNode.parentNode.getElementsByTagName("div");
	for ( i = 0, countriesNum = wholeCountries.length ; i < countriesNum ; i ++ ) {
		if ( wholeCountries[i].innerHTML.indexOf("innerPadder") != -1 ) {
			wholeCountries[i].onmouseover = function() {
				if ( thisID != this.getAttribute("id" )) {
					leaveCountry(this);
				}
			}
		}
	}
}

function leaveCountry(country) {
	$('hilight').className = "png out";
	ulObj = country.parentNode.getElementsByTagName("ul");
	cnt = ulObj.length;
	for ( i = 0 ; i < cnt ; i ++ ) {
		ulObj[i].style.textIndent = "-9999px";
	}
}

function leaveAllCountry() {
	$('hilight').className = "png out";
	ulObj = document.getElementsByTagName("ul");
	cnt = ulObj.length;
	for ( i = 0 ; i < cnt ; i ++ ) {
		ulObj[i].style.textIndent = "-9999px";
	}
}

//-----------------------------------------------------
//attach events when loaded
//-----------------------------------------------------
if (window.addEventListener) {
	window.addEventListener("load", chkSize, false);
	window.addEventListener("load", attachLoadEvent, false);
} else if (window.attachEvent) {
	window.attachEvent("onload", chkSize);
	window.attachEvent("onload", attachLoadEvent);
} else {
	window.onload = chkSize();
	window.onload = attachLoadEvent();
}

function chkSize() {
	if ( document.body.clientWidth > 980 && document.body.clientHeight > 500 ) {
		$('contentBox').style.margin ="-250px 0 0 -490px";
		$('contentBox').style.top ="50%";
		$('contentBox').style.left ="50%";
		$('bgCurtain').style.marginLeft ="-490px";
		$('bgCurtain').style.left ="50%";
		document.body.style.backgroundPosition ="center center";
	} else if ( document.body.clientWidth > 980 && document.body.clientHeight < 500 ) {
		$('contentBox').style.top ="0";
		$('contentBox').style.left ="50%";
		$('contentBox').style.margin ="0 0 0 -490px";
		$('bgCurtain').style.marginLeft ="-490px";
		$('bgCurtain').style.left ="50%";
		document.body.style.backgroundPosition ="center 0";
	} else if ( document.body.clientWidth < 980 && document.body.clientHeight > 500 ) {
		$('contentBox').style.marginLeft ="0";
		$('contentBox').style.marginTop ="-250px";
		$('contentBox').style.top ="50%";
		$('contentBox').style.left ="0";
		$('bgCurtain').style.marginLeft ="0";
		$('bgCurtain').style.left ="0";
		document.body.style.backgroundPosition ="0 center";
	} else if ( document.body.clientWidth < 980 && document.body.clientHeight < 500 ) {
		$('contentBox').style.margin ="0";
		$('contentBox').style.top ="0";
		$('contentBox').style.left ="0";
		$('bgCurtain').style.margin ="0";
		$('bgCurtain').style.left ="0";
		$('bgCurtain').style.top ="0";
		document.body.style.backgroundPosition ="0 0";
	}
}

window.onresize = function() {
	chkSize();
}