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

	//開啟隱藏統計區塊
	function showit(){
		$("#statbox").toggle(location.search=="?show");
	}
	
	
	var count = 3 - 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();
	}
	
	$("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 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:0});
	
	function showmsg(){
		ads.eq(img).slideUp(500, function(){
			$(this).css({top: _h+1, zIndex: 10}).show();
		});
		img = img+1<ads.length?img+1:0;
		ads.eq(img).animate({top: 0}, 1000);		
		timer = setTimeout(showmsg, speed);
	}
	
	
	//留言 ---------------------------------------------------------------------------------------------------------------------------------
	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();
	});

	
	/* 回到文章頂部 Top ================================================================== */	
	$('a.minwt_gotoheader').click(function(){
		// 讓捲軸用動畫的方式移動到 0 的位置
		$('html, body').animate({
			scrollTop: 0
		}, 600);
 
		return false;
	});	

	/* 開始Menu===================================================================== */
	$(document).click(function(){
		$("#mainMenu").css('display','none');
	});
	
	$("#mainMenu li").each(function(){
			var $this = $(this);
			//找尋#mainMenu li中的ul標籤是否>0
			if($this.find("ul").length>0){
				$(this).children("a").append("<img src=http://photo.minwt.com/img/icon/arrow.png class=img>");
			}
	});
				
	$("#startBtn a").click(function(){
			if($("#mainMenu").is(":visible")){
				$("#mainMenu").slideUp();
			}else{
				$("#mainMenu").slideDown();
				$("#mainMenu ul").hide();
			}	
		
			return false;
	});
		
	$("#mainMenu li a").click(function(){				
			var $this= $(this),
				$parent = $this.parent(),
				$next = $this.next("ul"),
				_idx = $parent.index();
			
			if($next.length>0){
				if($next.is(":visible")){
					$next.slideUp();
				}else{
					//先將父層兄弟的ul標籤關閉
					$parent.siblings().find("ul").slideUp();
					if($.browser.msie){
						$next.css('top',50*(_idx + 1)-_idx*5).slideDown();					
					}else{
						$next.css('top',50*_idx).slideDown();
					}
				}
				//關閉連結
				return false;
			}
	});	
	
	//滾動時顯示上下版頭bar ---------------------------------------------------------------------------------------------------------------------------------
	$(window).load(function(){
			$("#footer2").css({
			top: $(document).height()
		});
		$(window).bind('scroll resize', function(){
			var $this = $(this);
			var $this_Top=$this.scrollTop();
				
			if($this_Top<=60){
				//$('#head2, #footer2').css('display','none');
				$('#footer2').css('display','none');
				}
			if($this_Top>60){
				if($.browser.msie){
					$('#footer2').css('display','block');
				}else{
					$('#footer2').css('display','block').css('opacity', .95);
				}
				$('#footer2').css('top',$(window).height()-$("#footer2").height());
						
			}
		}).scroll();
	});
	
	// 消除連結虛線框 ---------------------------------------------------------------------------------------------------------------------------------
	$("a").focus( function(){
			$(this).blur();
	});		
	showmsg();	
	showit();
});
