__rootPath=__rootPath.replace(/\\/gi,"/");
__langPath=__langPath.replace(/\\/gi,"/");
document.write([
 '<script src="'+__rootPath+'/Scripts/jquery.bgiframe.js" type="text/javascript"></script>'
,'<script src="'+__rootPath+'/Scripts/jquery.mousewheel.js" type="text/javascript"></script>'
,'<script src="'+__rootPath+'/Scripts/jScrollPane.js" type="text/javascript"></script>'
,'<link rel="stylesheet" type="text/css" media="all" href="'+__rootPath+'/Scripts/jScrollPane.css" />'
,'<!--[if IE 6]><script src="'+__rootPath+'/Scripts/DD_belatedPNG.js" type="text/javascript"></script><script type="text/javascript">$(function(){DD_belatedPNG.fix("div");});</script><![endif]-->'
].join(''));
$(function(){
	var actions = {
		"x-lang-switch":function(_this){
			var opt=_this.attr("opt");
			if(typeof(opt)=="string"&&$.trim(opt)!=""){
				opt=eval("("+opt+")");
				$(".lang-switch").click(function(){
					var rel=$(this).attr("rel");
					window.location.href=opt[rel];
					return false;
				});
			}else{
				$(".lang-switch").click(function(){
					var rel=$(this).attr("rel");
					(function(l){
						window.location.href=window.location.href.replace(/\/(th|en)\//gi,"/"+l+"/");
					})(rel);
					return false;
				});
			}
		},
		"x-main-menu":function(_this){
			var opt=_this.attr("opt");
			$(">table:gt(0)",_this).hide();
			if(typeof(opt)=="string"&&$.trim(opt)!=""){
				var opts=opt.split(",");
				var a=opts[0];
				var b=opts[1];
				var c=opts[2];
				var p=null;
				if(typeof(a)=="string"&&$.trim(a)!=""){
					var a=a.split("=");
					var img=$("a>img",_this)[parseInt(a[0])-1];
					if(img!=null){
						img=$(img);
						img.attr("src",img.attr("src").toLowerCase().replace("x.",a[1]+".")).parent().removeAttr("onmouseout").removeAttr("onmouseover");
						p=$(">table#menu-"+parseInt(a[0]),_this).show();
					}
				}
				if(typeof(b)=="string"&&$.trim(b)!=""&&p!=null&&p[0]!=null){
					var b=b.split("=");
					var img=$(".menu-ct>a>img",p)[parseInt(b[0])-1];
					if(img!=null){
						img=$(img);
						img.attr("src",img.attr("src").toLowerCase().replace("x.",b[1]+".")).parent().removeAttr("onmouseout").removeAttr("onmouseover");
						p=$(".sub-menu",img.parent().parent());
					}else
						p=null;
				}
				if(typeof(c)=="string"&&$.trim(c)!=""&&p!=null&&p[0]!=null){
					var c=c.split("=");
					var img=$("a>img",p)[parseInt(c[0])-1];
					if(img!=null){
						img=$(img);
						img.attr("src",img.attr("src").toLowerCase().replace("x.",c[1]+".")).parent().removeAttr("onmouseout").removeAttr("onmouseover");
					}
				}
			}
			$(".menu-ct>table").hide().css("position","absolute");
			$(".menu-ct").mouseover(function(){
				var offset = $(this).addClass("menu-over").offset();
				var el=$(">table",$(this));
				var left = 182;//$(this).width();
				el.css({
					left:(offset.left+left)+"px",
					top:(offset.top-25)+"px"
				}).bgiframe({width:el.width(),height:el.height()}).show();
			}).mouseout(function(){
				var _this=this;
				$(this).removeClass("menu-over");
				setTimeout(function(){
					if(!$(_this).is(".menu-over"))
						$(">table",$(_this)).hide();
				},100);
			});
		},
		"x-popup-over":function(_this){
			var el=_this;
			var ul=$("ul",$(el));
			if($("li",ul).length>4){
				var w=ul.width();
				ul.height("88px").css({"border":"none"}).jScrollPane({
					dragMinHeight : 26,
					dragMaxHeight : 26,
					scrollbarWidth : 9
				}).width(w+"px");
				ul=ul.parent().css({"border":"1px solid #a487b7"});
			}
			ul.css("position","absolute").hide();
			$(el).mouseover(function(){
				var offset = $(el).addClass("menu-over").offset();
				ul.css({
					left:offset.left+"px",
					top:(offset.top+$(el).height())+"px"
				}).bgiframe({width:ul.width(),height:ul.height()}).show();
			}).mouseout(function(){
				$(el).removeClass("menu-over");
				setTimeout(function(){
					if(!$(el).is(".menu-over"))
						ul.hide();
				},100);
			});
		},
		"x-popup-click":function(_this){
			var el=_this;
			var ul=$("ul",$(el));
			if($("li",ul).length>4){
				var w=ul.width();
				ul.height("88px").css({"border":"none"}).jScrollPane({
					dragMinHeight : 26,
					dragMaxHeight : 26,
					scrollbarWidth : 9
				}).width(w+"px");
				ul=ul.parent().css({"border":"1px solid #a487b7"});
			}
			ul.css("position","absolute").hide();
			$(el).click(function(){
				var offset = $(el).addClass("menu-over").offset();
				ul.css({
					left:offset.left+"px",
					top:(offset.top+$(el).height())+"px"
				}).bgiframe({width:ul.width(),height:ul.height()}).show();
			}).mouseover(function(){
				$(el).addClass("menu-over");
			}).mouseout(function(){
				$(el).removeClass("menu-over");
				setTimeout(function(){
					if(!$(el).is(".menu-over"))
						ul.hide();
				},100);
			});
		}
	};
	var dynItems = $(".dyn-include");
	var dynCount = 0;
	dynItems.each(function(){
		var o=$(this);
		var url = o.attr("id");
		var rd=Math.round(Math.random()*10000);
		url = (url.toLowerCase().indexOf(".html")!=-1)?url:url+".html?_rd="+rd;
		$.get(__langPath+"/"+url,function(html){
			o.append(html.replace(/_root_/gi,__rootPath));
			var act=o.attr("act");
			if(typeof(act)=="string"&&$.trim(act)!=""){
				if(typeof(actions[act])=="function"){
					actions[act](o);
				}
			}
			dynCount++;
		});
	});
});