document.write ('<script type="text/javascript" src="/common/scripts/jquery-gradient.js"></script>');
document.write ('<script type="text/javascript" src="/common/scripts/config.js"></script>');
document.write ('<script type="text/javascript" src="/common/scripts/gradient.js"></script>');
document.write ('<script type="text/javascript" src="/common/scripts/style-switcher.js"></script>');
document.write ('<script type="text/javascript" src="/common/scripts/jquery-facebox.js"></script>');
document.write ('<script type="text/javascript" src="/common/scripts/jquery-scrollto.js"></script>');
document.write ('<script type="text/javascript" src="/common/scripts/jquery-cookie.js"></script>');
document.write ('<script type="text/javascript" src="/common/scripts/jquery-easing.js"></script>');
document.write ('<script type="text/javascript" src="/common/scripts/jquery-easy-slider.js"></script>');
document.write ('<script type="text/javascript" src="/common/scripts/jquery-cycle.js"></script>');
document.write ('<script type="text/javascript" src="/common/scripts/jquery-backgroundposition.js"></script>');

$ (function () {
	if ($.browser.mozilla) {
		$ ("body").addClass ("mozilla");
	} else if ($.browser.msie) {
		$ ("body").addClass ("msie");
	} else if ($.browser.safari) {
		$ ("body").addClass ("safari");
	}

	$ ("ul.link-list-e-1 a[href$='.pdf']").after ("<img class='icon-a-1' src='/common/images/icon-08.gif' width='16' height='16' alt='PDF' />");
	$ ("ul.link-list-e-1 a[href$='.doc']").after ("<img class='icon-a-1' src='/common/images/icon-17.gif' width='16' height='16' alt='DOC' />");
	$ ("ul.link-list-e-1 a[href$='.xlsx']").after ("<img class='icon-a-1' src='/common/images/icon-27.gif' width='16' height='16' alt='XLSX' />");
	$ ("ul.link-list-e-1 a[href$='.jpg']").after ("<img class='icon-a-1' src='/common/images/icon-28.gif' width='16' height='16' alt='JPG' />");
	$ ("ul.link-list-e-2 a[href$='.EXE']").after ("<img class='icon-a-1' src='/common/images/icon-24.gif' width='16' height='16' alt='EXE' />");
	if ($.browser.msie) {
		$ ("div#content img.icon-a-1, div#content img.icon-a-2").each (function () {
			var margin = Math.max (0, (parseInt ($ (this).css ("line-height")) - $ (this).height ()) / 2);
			$ (this).css ({ marginBottom : Math.ceil (margin) + "px", marginTop : Math.floor (margin) + "px" });
		});
	}

	$ ("div#content span.marker").parent ().parent ().each (function () {
		var marker = $ (this).children ().children ("span.marker");
		var width = 0;
		marker.each (function () {
			width = Math.max (width, $ (this).css ("display", "inline").width ("auto").width () - parseInt ($ (this).css ("text-indent")));
		});
		$ (this).css ("margin-left", width);
		marker.width (width).css ("margin-left", "-" + width + "px");
	});

	$ ("div#content *[class*='w-']").each (function () {
		$ (this).css ("width", $ (this).attr ("class").match (/w-(\d+)/) [1] + "px");
	});

	if ($.browser.msie && $.browser.version <= 8) {
		$ ("div#content .button-a-1 a, div#content .button-a-2 a, div#content .button-a-3 a, div#content .button-b-1 a, div#content .border-a-1 .inner").each (function () {
			var position = $ (this).position ();
			var left = position.left - 1 + parseInt ($ (this).css ("margin-left")) - 2;
			var top = position.top - 1;
			var width = $ (this).outerWidth ();
			var height = $ (this).outerHeight ();
			$ ("<span class='shadow'></span>").insertAfter (this).css ({ left: left, top: top }).width (width).height (height);
		});
	}

	if ($.browser.msie && $.browser.version == 8) {
		$ ("div#content form div.field-a-1 input.checkbox, div#content form div.field-a-1 input.radio").css ("margin-top", "0");
	}

	$ ("div.grid.middle > div.column").addClass ("middle");
	$ ("div.grid.bottom > div.column").addClass ("bottom");
	$ ("div.grid div.column").filter (".middle, .bottom").each (function () {
		var height = 0;
		$ (this).siblings ().each (function () {
			height = Math.max (height, $ (this).height ());
		});
		var margin = Math.max (height - $ (this).height (), 0);
		$ (this).css ("margin-top", ($ (this).hasClass ("middle") ? Math.floor (margin / 2) : margin) + "px");
	});

	for (var i = 1; $ ("div#content .equal-bottom-" + i).length; i++) {
		var block = $ ("div#content .equal-bottom-" + i);
		var height = 0;
		block.each (function () {
			height = Math.max ($ (this).offset ().top + $ (this).height ("auto").height (), height);
		});
		block.each (function () {
			$ (this).css (($.browser.msie && ($.browser.version < 7)) ? "height" : "min-height", height - $ (this).offset ().top);
		});
	}

});

/* window */
window._close = window.close;
window.close = function () {
	(window.open ("", "_top").opener = top)._close ();
};

/* rollover */
$ (function () {
	$ ("img.rollover").each (function () {
		$ ("<img />").attr ("src", this.src.replace (/\.([^.]+)$/, "-hover." + "$1"));
	});
	$ ("a:has(img.rollover)").hover (function () {
		$ ("img.rollover", this).each (function () {
			this.src = this.src.replace (/\.([^.]+)$/, "-hover." + "$1");
		});
	}, function () {
		$ ("img.rollover", this).each (function () {
			this.src = this.src.replace (/-hover\.([^.]+)$/, "." + "$1");
		});
	});
	$ ("input.rollover").each (function () {
		$ ("<img />").attr ("src", this.src.replace (/\.([^.]+)$/, "-hover." + "$1"));
		$ (this).hover (function () {
			this.src = this.src.replace (/\.([^.]+)$/, "-hover." + "$1");
		}, function () {
			this.src = this.src.replace (/-hover\.([^.]+)$/, "." + "$1");
		});
	});
});

/* local-navigation */
$ (function () {
	$ ("div#local-navigation ul li.expanded span").live ("click", function () {
		$ (this).next ().slideUp (100, function () {
			$ (this).parent ().removeClass ("expanded").addClass ("collapsed");
		});
	});
	$ ("div#local-navigation ul li.collapsed span").live ("click", function () {
		$ (this).next ().slideDown (100);
		$ (this).parent ().removeClass ("collapsed").addClass ("expanded");
	});
});

/* return-navigation */
$ (function () {
	$ ("a[href^=#wrapper]").click (function () {
		$.scrollTo ($ (this).attr ("href"), 500);
		return false;
	});
});

/* lightbox */
$ (function () {
	$ ('a[rel*=facebox]').facebox ({
		opacity      : 0.75,
		loadingImage : "/common/images/facebox/image-loading.gif",
		closeImage   : "/common/images/facebox/button-close.gif"
	})
});

/* language-selector */
function printLanguageSelector () {
	var lang = String (window.location).match (/\/([a-z]{2}\/[a-z]{2})\//) [1].split ("/").join ("-");
	document.write (
		"<form class='language' action='__dummy__' method='post'>" +
		"<div><select onchange='location.href=this.options [this.selectedIndex].value'>" +
		"<option value='/ja/jp/index.html'" + (lang == "ja-jp" ? " selected='selected'" : "") + ">日本</option>" +
		"<option value='/zh/tw/index.html'" + (lang == "zh-tw" ? " selected='selected'" : "") + ">台灣</option>" +
		"<option value='/zh/hk/index.html'" + (lang == "zh-hk" ? " selected='selected'" : "") + ">香港</option>" +
		"<option value='/en/hk/index.html'" + (lang == "en-hk" ? " selected='selected'" : "") + ">HongKong (English)</option>" +
		"<option value='/en/sg/index.html'" + (lang == "en-sg" ? " selected='selected'" : "") + ">Singapore</option>" +
		"<option value='/en/my/index.html'" + (lang == "en-my" ? " selected='selected'" : "") + ">Malaysia</option>" +
		"<option value='/ko/kr/index.html'" + (lang == "ko-kr" ? " selected='selected'" : "") + ">대한민국</option>" +
		"<option value='/id/id/index.html'" + (lang == "id-id" ? " selected='selected'" : "") + ">Indonesia (Bahasa)</option>" +
		"</select></div>" +
		"</form>"
	);
}

/* visual */
$ (function () {
	$ ("div#visual").cycle ({
		cleartype:		true,
		cleartypeNoBg:	true,
		fx:				'fade',
		speed:			4000
	});
});

/* slider */
$ (function () {
	$ ("div#slider div.inner div.content").easySlider ({
		speed:		400,
		auto:		true,
		pause:		8000,
		continuous:	true
	});
});

/* weather */
$ (function () {
	$ ("div#alpha-1, div#alpha-2, div#alpha-3").css ({"background-position":"0 -500px","height":"800px"});
	$ ("div#global-navigation ul li.weather-toggle a").toggle(
		function (){
			$ ("div#weather").toggle (100);
			$ ("div#alpha-1, div#alpha-2, div#alpha-3").animate ({backgroundPosition: '0 0'},300);
			$ ("div#alpha-1, div#alpha-2, div#alpha-3, div#gradient div").css ({"height":"1300px"});
		},
		function (){
			$ ("div#weather").toggle (300);
			$ ("div#alpha-1, div#alpha-2, div#alpha-3").animate ({backgroundPosition: '0 -500'},300);
			$ ("div#alpha-1, div#alpha-2, div#alpha-3, div#gradient div").css ({"height":"800px"});
		}
	);
});
