
$(function(){
	/**
	 *	滑鼠動作
	 */
	$(".JsMouseAction").mouseover(function(){
		$(this).removeClass('mouseout').addClass('mouseover');
	});
	$(".JsMouseAction").mouseout(function(){
		$(this).removeClass('mouseover').addClass('mouseout');
	});
	
	/**
	 *	簡繁切換
	 */
	if ($("#translateLink").size()>0) {
		var defaultEncoding = 1;
		var translateDelay = 0;
		var cookieDomain = $("#domainname").val();
		var msgToTraditionalChinese = "繁體";
		var msgToSimplifiedChinese = "簡體";
		var translateButtonId = "translateLink";
		translateInitilization();
	}
	
	/**
	 *	主功能標示
	 */
	//header
    var pathname=location.pathname.split('/');
	pathname=pathname[pathname.length-1];
	//alert(pathname);
	if(pathname == 'about_us.php' || pathname == 'liquid_titanium.php' || pathname == 'honours.php' || pathname == 'thank.php'){
		pathname = 'about_us.php';	
	}
	
	$(".jsddm > li").each(function(){
		var _href=$(this).find("a").attr("href").split('?');
		_href=_href[0];
		if (_href==pathname) {
			$(this).find("a").addClass("liched");
		}
		$(this).find("li").each(function(){
			var _href=$(this).find("a").attr("href").split('?');
			_href=_href[0];
			if (_href==pathname) {
				if(pathname == 'about_us.php'){
					$("#header_img").attr("src", "templates/tsv/images/layout/menu_02_2.gif");
				}else{
					if(pathname == 'product_list.php' || pathname == 'product.php'){
						$(this).parent().parent().find("a").addClass("liched");
					}else{
						$(this).parent().parent().find("a").addClass("liched");
					}
				}
			}
		});
	});
	
	/**
	 *	自動把字串多出來的字元變成... 用法:class="truncate" length="10"
	 */
	$(".truncate").each(function(){
		var _len=$(this).attr("length");
		var _txt=$(this).text();
		var _txt2=_txt.substring(0,_len);
		if (_txt!=_txt2)
			$(this).text(_txt2+'...');
	});
	
	/**
	 *	點圖放大 用法: 在外層加上 class="chpic" param="target:'product_picture'"
	 */
	$(".chpic a").click(function(){
		var param;
		eval("param={"+$(".chpic").attr("param")+'}');
		var src=$(this).attr("href");
		$("#"+param.target).attr({src:src});
		return false;
	});
	

	/**
	 *	Flash呼叫 需載入swfobject，用法：在外層加上 id="flash_banner" param="target:'{$templates_dir}/flash/index.swf',width:990,height:297"
	 */
	
	var param;
	if ($("#flash_banner").size()>0) {
		eval("param={"+$("#flash_banner").attr("param")+'}');
		var flashvars = '';
		var params=new Object();
		params.wmode="transparent";
		var attributes = ''; 
		swfobject.embedSWF(param.target, "flash_banner", param.width, param.height, "9.0.0", "js/swfobject/expressInstall.swf", flashvars, params, attributes);
	}
	

	/**
	 *	啟用png24
	 */
	
});

$(window).load(function(){
	if ($.browser.msie) {
		document.execCommand("BackgroundImageCache",false,true);
	}
	
	/**
	 *	自動縮小圖片到一定尺寸內 用法: class="AutoImgSize" autosize="width:80,height:50"
	 */
	$(".AutoImgSize").each(function(){
		var _width=$(this).css("width").replace("px","");
		var _height=$(this).css("height").replace("px","");
		
		var autosize;
		eval("autosize={"+$(this).attr("autosize")+'}');
		var x = autosize.width/_width*100;
		var y = autosize.height/_height*100;
		
		if (y>x) y=x;
		if (x>100 && y>100) y=100;
		$(this).css("width",Math.floor(_width*y/100));
		$(this).css("height",Math.floor(_height*y/100));
				
		/*var _width=$(this).attr("w");
		var _height=$(this).attr("h");
		
		var autosize;
		eval("autosize={"+$(this).attr("autosize")+'}');
		var x =_width/autosize.width;
		var y = _height/autosize.height;
		
		if(_width > _height){
			ww = _width/x;
			hh = _height/x;
		}else{
			ww = _width/y;
			hh = _height/y;	
		}

		$(this).css("width",Math.floor(ww));
		$(this).css("height", Math.floor(hh));
		
		$(this).css("_width",Math.floor(ww));
		$(this).css("_height", Math.floor(hh));*/
	});
	
	/**
	 *	判斷左邊安全購物應該距離多少高度
	 */
	var userAgent = window.navigator.userAgent.toLowerCase();
 
	$.browser.msie8 = $.browser.msie && /msie 8\.0/i.test(userAgent);
	$.browser.msie7 = $.browser.msie && /msie 7\.0/i.test(userAgent);
	$.browser.msie6 = !$.browser.msie8 && !$.browser.msie7 && $.browser.msie && /msie 6\.0/i.test(userAgent);
 
	var lh=$(".sf-menu").height();
	
	if ($(".indexy").size()<=0) {
		if (!$.browser.msie6)
			$(".safelogo").css("margin-top",lh+9+30);

	}
});


