﻿//開啟隱藏統計區塊
function showit(){
	$("#statbox").toggle(location.search=="?show");
}	
$(function(){
	//自動切換語系---start
	/*	var lang = window.navigator.userLanguage || window.navigator.language ;		
		var autolang=lang.toLowerCase();
		var geturl = location.href;	
		
		var url = "";
		switch (autolang){
			//簡中
			case "zh-cn":		
				url = "http://translate.google.com/translate?hl=zh-TW&sl=zh-CN&tl=zh-CN&u="+geturl;
				break;
			//英文
			case "en-us":	
				url = "http://translate.google.com/translate?hl=zh-TW&sl=zh-CN&tl=en&u="+geturl;	
				break;
			//日文
			case "ja-jp":	
				url = "http://translate.google.com/translate?hl=zh-TW&sl=zh-CN&tl=ja&u="+geturl;
				break;
			//韓國
			case "ko":		
				url = "http://translate.google.com/translate?hl=zh-TW&sl=zh-CN&tl=ko&u="+geturl;	
				break;
			//法國	
			case "fr":	
				url = "http://translate.google.com/translate?hl=zh-TW&sl=zh-CN&tl=fr&u="+geturl;
				break;
			//泰國
			case "th":		
				url = "http://translate.google.com/translate?hl=zh-TW&sl=zh-CN&tl=th&u="+geturl;
				break;		
		}
		if(url!="" && location.href.indexOf("tl="+autolang)<=-1) location.replace(url);*/
	//自動切換語系---end
	
	//右側多國語系選單--start
		/*var searchurl=location.search;
		if(reTransUrl != null && reTransUrl!= ""){
		searchurlArr=searchurl.split("&");	
		var reTransUrl=searchurlArr[3].replace("u=http://","");
			$("#tw a").attr("href",reTransUrl);
			$("#cn a").attr("href","http://translate.google.com/translate?hl=zh-TW&sl=zh-CN&tl=zh-CN&u="+reTransUrl);
			$("#en a").attr("href","http://translate.google.com/translate?hl=zh-TW&sl=zh-CN&tl=en&u="+reTransUrl);
			$("#ja a").attr("href","http://translate.google.com/translate?hl=zh-TW&sl=zh-CN&tl=ja&u="+reTransUrl);
			$("#fr a").attr("href","http://translate.google.com/translate?hl=zh-TW&sl=zh-CN&tl=fr&u="+reTransUrl);
			$("#ko a").attr("href","http://translate.google.com/translate?hl=zh-TW&sl=zh-CN&tl=ko&u="+reTransUrl);
			$("#th a").attr("href","http://translate.google.com/translate?hl=zh-TW&sl=zh-CN&tl=th&u="+reTransUrl);
		}else{
			$("#tw a").attr("href",geturl);
			$("#cn a").attr("href","http://translate.google.com/translate?hl=zh-TW&sl=zh-CN&tl=zh-CN&u="+geturl);
			$("#en a").attr("href","http://translate.google.com/translate?hl=zh-TW&sl=zh-CN&tl=en&u="+geturl);
			$("#ja a").attr("href","http://translate.google.com/translate?hl=zh-TW&sl=zh-CN&tl=ja&u="+geturl);
			$("#fr a").attr("href","http://translate.google.com/translate?hl=zh-TW&sl=zh-CN&tl=fr&u="+geturl);
			$("#ko a").attr("href","http://translate.google.com/translate?hl=zh-TW&sl=zh-CN&tl=ko&u="+geturl);
			$("#th a").attr("href","http://translate.google.com/translate?hl=zh-TW&sl=zh-CN&tl=th&u="+geturl);
		}
		
		$("#tw a").attr("href",geturl);
		$("#cn a").attr("href","http://translate.google.com/translate?hl=zh-TW&sl=zh-CN&tl=zh-CN&u="+geturl);
		$("#en a").attr("href","http://translate.google.com/translate?hl=zh-TW&sl=zh-CN&tl=en&u="+geturl);
		$("#ja a").attr("href","http://translate.google.com/translate?hl=zh-TW&sl=zh-CN&tl=ja&u="+geturl);
		$("#fr a").attr("href","http://translate.google.com/translate?hl=zh-TW&sl=zh-CN&tl=fr&u="+geturl);
		$("#ko a").attr("href","http://translate.google.com/translate?hl=zh-TW&sl=zh-CN&tl=ko&u="+geturl);
		$("#th a").attr("href","http://translate.google.com/translate?hl=zh-TW&sl=zh-CN&tl=th&u="+geturl);*/
		
	//右側多國語系選單--end
	

	var count = 5 - 1;
	var _h3 = $("h3:contains(梅朋友), h3:contains(梅幫交), h3:contains(梅推薦), h3:contains(梅連結)");
		
	_h3.each(function(){
		var _ = $(this).next(".textwidget");
		if(_.find("li").length>count){
			var _click = $("<span class='h3_span'>[+]展開</span>");
			_.find("li:gt("+count+")").hide();
			$(this).append("&nbsp;", _click).click(opennofriend);
		}
	});

	function opennofriend(){
		$(this).unbind().click(closenofriend).children(".h3_span").html("[-]收合").parent().next().find("li").slideDown();
	}
	function closenofriend(){
		$(this).unbind().click(opennofriend).children(".h3_span").html("[+]展開").parent().next().find("li:gt("+count+")").slideUp();
	}
	

	var img = 0;
	var _w = parseInt($("#myad").css("width"));
	var _h = parseInt($("#myad").css("height"));
	var ads = $("#myad ul li a");
	var timer;
	var speed = 4000;

	$("#myad").find("ul").remove().end()
		.append(ads)
		.find("a").css({position: "absolute", top: _h+1})
		.hover(function(){
			clearTimeout(timer);
		}, function(){
			timer = setTimeout(_showMsg, speed);
		})
		.eq(img).css({top: "0px"});
		
	function _showMsg(){
		ads.eq(img).slideUp(500, function(){
			$(this).css({top: _h+1, "z-index": 10}).show();
		});
		img = img+1<ads.length?img+1:0;
		ads.eq(img).animate({top: 0, "z-index": 9}, 1000);
		
		timer = setTimeout(_showMsg, speed);
	};
	
	_showMsg();
	showit();

	$("li.cat-item-3 a:first").after("<a href='http://www.minwt.com/doclist/photoshop.php'  class='addlist' title='依列表方式顯示'> - [ 列表 ]</a>");
	$("li.cat-item-6 a:first").after("<a href='http://www.minwt.com/doclist/flash.php'  class='addlist' title='依列表方式顯示'> - [ 列表 ]</a>");
	$("li.cat-item-9 a:first").after("<a href='http://www.minwt.com/doclist/flex.php'  class='addlist' title='依列表方式顯示'> - [ 列表 ]</a>");

	/* ============================================ 留   言============================================  */
	var _author = $.cookie('author');
	if(_author!=null){
		var _email = $.cookie('email');
		var _url = $.cookie('url');

		$("#author").val(_author);
		$("#email").val(_email);
		$("#url").val(_url);
		
		$("#inputtxt").css("display","none");
		$("#cookieinfo").css("display","block");
		$("#author_id").html(_author);

		$("#author_info").toggle(function(){	
			$("#inputtxt").slideDown();
			$("#author_info").html("取消變更 &raquo;");	
		}, function(){
			$("#inputtxt").slideUp();
			$("#author_info").html("變更身分 &raquo;");
		});
	}else{
		$("#cookieinfo").css("display","none");
	}
	
	$("#commentform :button[name=送出]").click(function(){
		var _authorValue = $("#author").val();
		if(_authorValue!=""){
			$.cookie('author', _authorValue);
		}
		var _emailValue = $("#email").val();
		if(_emailValue!=""){
			$.cookie('email', _emailValue);
		}
		var _urlValue = $("#url").val();
		if(_urlValue!=""){
			$.cookie('url', _urlValue);
		}
		$("#commentform").submit();
	});
});