
$(function(){
	/**
	 *	滑鼠動作
	 */
	$(".JsMouseAction").mouseover(function(){
		$(this).removeClass('mouseout').addClass('mouseover');
	});
	$(".JsMouseAction").mouseout(function(){
		$(this).removeClass('mouseover').addClass('mouseout');
	});
	
	$('ul.sf-menu').superfish();
	
	/**
	 *	簡繁切換
	 */
	if ($("#translateLink").size()>0) {
		var defaultEncoding = 1;
		var translateDelay = 0;
		var cookieDomain = $("#domainname").val();
		var msgToTraditionalChinese = "繁體";
		var msgToSimplifiedChinese = "簡體";
		var translateButtonId = "translateLink";
		translateInitilization();
	}
	
	/**
	 *	主功能標示
	 */
    var pathname=location.pathname.split('/');
	pathname=pathname[pathname.length-1];
	$(".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) {
				$(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;
	});
	
	/**
	 *	t2版型
	 */
	if ($(".body_l").css("position")=="absolute") {
		var _height=$(".body_l").height()
		+($(".body_l").css("padding-top").replace("px","")-0)
		+($(".body_l").css("padding-bottom").replace("px","")-0)
		+($(".body_l").css("margin-top").replace("px","")-0)
		+($(".body_l").css("margin-bottom").replace("px","")-0)
		-65
		-20;
		
		if ($(".body_r").height()<=_height)
			$(".body").css("height",_height);
	}
	
	/*內頁動畫*/
	var target=$("#flash_banner").attr("target");
	var flashvars = '';
	var params=new Object();
	params.wmode="transparent";
	var attributes = ''; 
	swfobject.embedSWF(target, "flash_banner", "930", "140", "9.0.0", "js/swfobject/expressInstall.swf", flashvars, params, attributes);
	
	/*首頁動畫*/
	var flashvars = '';
	var params=new Object();
	params.wmode="transparent";
	var attributes = ''; 
	swfobject.embedSWF("templates/chienhsiang_tw/flash/index.swf", "index_banner", "930", "420", "9.0.0", "js/swfobject/expressInstall.swf", flashvars, params, attributes);
	
	/*LOGO動畫*/
	var flashvars = '';
	var params=new Object();
	params.wmode="transparent";
	var attributes = ''; 
	swfobject.embedSWF("templates/chienhsiang_tw/flash/logo.swf", "header_logo", "66", "70", "9.0.0", "js/swfobject/expressInstall.swf", flashvars, params, attributes);

	$("#topgo").click(function(){
		var userAgent = window.navigator.userAgent.toLowerCase();
		if (!($.browser.msie && (/msie 7\.0/i.test(userAgent) || /msie 6\.0/i.test(userAgent))))
			$(".index_back a").attr("href","javascript:history.go(-2)");
	});
});

$(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));
	});
	
	
	
});

/*圖片點擊放大*/
	function uploadPic(txt){
		var putItThere = null;
		var chasm = screen.availWidth;
		var mount = screen.availHeight;
		var w = 720;//ãw&#6842;&#51533;
		var h = 550;//ãw&#6842;&#2701;
		putItThere = window.open(txt,'posB','width=' + w + ',height=' + h + ',left=' + ((chasm - w - 10) * .5) + ',top=' + ((mount - h - 30) * .5));
		if (putItThere.blur) putItThere.focus();
}
