﻿//開啟隱藏統計區塊
function showit(){
	$("#statbox").toggle(location.search=="?show");
}	
$(function(){
	//切換圖床
	/*$("body").html(function(index, html){
		//js正規表示法
		//i：忽略大小寫，g：全域比對，ig：忽略大小寫並全域比對
		return html.replace(/photo.minwt.com/ig, "photo2.minwt.com");
	});*/

	//$("#content, #sidebar").equalHeight();
	$(document).pngFix(); 
	
	//jqZoom
	$(".jqzoom").jqueryzoom({
		xzoom: 400,
		yzoom: 300
	});
	
	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();
	});
});