// themes/Dreamy/dreamy.js 
//-------------------------------------------------------------------------
//Site:    http://leotheme.cn/
//Version: 3.0
//Date:    2009/11/28
//Author:  Await(等待)
//Email:   yltfy2008@gmail.com
//-------------------------------------------------------------------------
//侧边栏收缩
//-------------------------------------------------------------------------
function togsidebar() {
	$(".sidebar li:first").parent().append("<div class=liborderbottom></div>");
	if(togglesidebar == true) {
		$(".sidebar li h2").append("<span class=sidebarup title=展开收起>展开收起</span>");
		$(".sidebar li h2 span").click(function () {
			$(this).parent().next().slideToggle();
			$(this).parent().parent().css("paddingBottom","10px");
			$(this).toggleClass("sidebardown");
		});
	}
}
//-------------------------------------------------------------------------
//控制滚动条滚动插件
//-------------------------------------------------------------------------
jQuery.fn.scrollTo = function(speed) {
	var targetOffset = $(this).offset().top;
	$('html,body').stop().animate({scrollTop: targetOffset}, speed);
	return this;
}; 
//-------------------------------------------------------------------------
//Tab切换
//-------------------------------------------------------------------------
 $(".tabContent div:not(:first)").hide();
 $(".tabnavi li").each(function(index){
	$(this).click(function(){
		$(".tabnavi li.current").removeClass("current");
		$(this).addClass("current");
		$(".tabContent > div:visible").hide();
		$(".tabContent div:eq(" + index + ")").show();
	 })
})
//---------------------------------------------------------------------------
//表单验证
///*-------------------------------------------------------------------------
function Validator() {
	var Msg = new Array(
				"用户名不能为空",
				"昵称不能少于3个字符",
				"E-mail地址不能为空",
				"请输入正确的E-Mail地址",
				"url地址不正确",
				"评论内容不能少于5个字符",
				"输入正确"
			);
	$("#commentform :input").blur(function(){
		//验证用户名
		if( $(this).is('#author') ){
			$(this).next().remove();
			if( this.value==""){
				$('<span class="formtips onError">'+Msg[0]+'</span>').insertAfter(this);
			}
			else if(this.value.length < 3 ){
				$('<span class="formtips onError">'+Msg[1]+'</span>').insertAfter(this);
			}
			else {
				$('<span class="formtips onok">'+Msg[6]+'</span>').insertAfter(this);
			}
		}
		//验证邮件
		if( $(this).is('#email') ){
			$(this).next().remove();
			if( this.value==""){
				$('<span class="formtips onError">'+Msg[2]+'</span>').insertAfter(this);
			}
			else if( this.value!="" && !/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/.test(this.value)){
				$('<span class="formtips onError">'+Msg[3]+'</span>').insertAfter(this);
			}
			else {
				$('<span class="formtips onok">'+Msg[6]+'</span>').insertAfter(this);
			}
		}
		//验证url
		if( $(this).is('#url') ){
			$(this).next().remove();
			if( this.value!="" && !/^http:\/\/[A-Za-z0-9]+\.[A-Za-z0-9]+[\/=\?%\-&_~`@[\]\':+!]*([^<>\"\"])*$/.test(this.value)){
				$('<span class="formtips onok">'+Msg[4]+'</span>').insertAfter(this);
			}
		}
	});
	//提交，最终验证
    $('#submit').click(function(){
		$("#commentform :input").trigger('blur');
		//验证评论内容
		if( $("textarea").val() == ""|| $("textarea").val().length < 5){
			tipsWindown("提示","text:评论内容不能为空或少于5个字符!","250","150","false","2000","false","msg");
			return false;
		}
		var numError = $('form .onError').length;
		if(numError){
			tipsWindown("提示","text:请正确填写表单内容","250","150","false","2000","false","msg");
			return false;
		}else{
			tipsWindown("提示","text:正在提交评论...","250","150","false","2000","false","msg");
			$(".formtips").remove();
		}
	});

}
//-------------------------------------------------------------------------
//图片缩放
//-------------------------------------------------------------------------
function AutoImgSize(obj){
	var n=$(obj).length;
	for(i=0;i<n;i++){
		var objt=$(obj).eq(i);
		if ($(objt).width() > Img_Maxwidth){
			var height=Img_Maxwidth/($(objt).width()/$(objt).height());
			$(objt).width(Img_Maxwidth+'px');
			$(objt).height(height+'px');
			$(objt).parent("a").attr("target","_blank");
			if (typeof($(objt).parent().attr('href'))!='' && typeof($(objt).parent().attr('href'))!='undefined'){objt=$(objt).parent()};
			$(objt).wrap("<div class='entryimgbox'></div>");
			$('<a href="'+$(obj).eq(i).attr('src')+'" rel="inlinks" style="position:absolute;left:0;bottom:0px;width:100%;height:20px;line-height:20px;padding:0 0 3px 5px;background:#fff;" class="showimgbtn">查看大图</a>').insertAfter($(objt));
			$('.entryimgbox').height(height+24+'px');
			$('.showimgbtn').click(function() {
				var Img_src = $(this).attr('href');
				//alert("src="+Img_src+"alt="+Img_alt);
				var Img='<img src="'+Img_src+'" alt="" class="theImg" style="display: none;" />';
				$("body").append(Img);
				var Img_width = $(".theImg").width();
				var Img_height = $(".theImg").height();
				var Img_name = $(".theImg").attr('alt');
				$(".theImg").remove();
				tipsWindown("图片："+Img_name,"img:"+Img_src,Img_width,Img_height,"true","","true");
				return false;
			});
		}
	}
}
///-------------------------------------------------------------------------
//jQuery弹出窗口 By Await [2009-11-22]
//--------------------------------------------------------------------------
/*参数：[可选参数在调用时可写可不写,其他为必写]
----------------------------------------------------------------------------
    title:	窗口标题
  content:  内容(可选内容为){ text | id | img | url | iframe }
    width:	内容宽度
   height:	内容高度
	 drag:  是否可以拖动(ture为是,false为否)
     time:	自动关闭等待的时间，为空是则不自动关闭
   showbg:	[可选参数]设置是否显示遮罩层(0为不显示,1为显示)
  cssName:  [可选参数]附加class名称
------------------------------------------------------------------------*/
//示例:
//simpleWindown("例子","text:例子","500","400","true","3000","0","exa")
//------------------------------------------------------------------------
//
function tipsWindown(title,content,width,height,drag,time,showbg,cssName) {
	$("#windown-box").remove(); //请除内容
	var width = width>= 950?this.width=950:this.width=width;	    //设置最大窗口宽度
	var height = height>= 527?this.height=527:this.height=height;  //设置最大窗口高度
	if(showWindown == true) {
		var simpleWindown_html = new String;
			simpleWindown_html = "<div id=\"windownbg\" style=\"height:"+$(document).height()+"px;filter:alpha(opacity=0);opacity:0;z-index: 999901\"></div>";
			simpleWindown_html += "<div id=\"windown-box\">";
			simpleWindown_html += "<div id=\"windown-title\"><h2></h2><span id=\"windown-close\">关闭</span></div>";
			simpleWindown_html += "<div id=\"windown-content-border\"><div id=\"windown-content\"></div></div>"; 
			simpleWindown_html += "</div>";
			$("body").append(simpleWindown_html);
			show = false;
	}
	contentType = content.substring(0,content.indexOf(":"));
	content = content.substring(content.indexOf(":")+1,content.length);
	switch(contentType) {
		case "text":
		$("#windown-content").html(content);
		break;
		case "id":
		$("#windown-content").html($("#"+content+"").html());
		break;
		case "img":
		$("#windown-content").ajaxStart(function() {
			$(this).html("<img src='"+templateSrc+"/images/loading.gif' class='loading' />");
		});
		$.ajax({
			error:function(){
				$("#windown-content").html("<p class='windown-error'>加载数据出错...</p>");
			},
			success:function(html){
				$("#windown-content").html("<img src="+content+" alt='' />");
			}
		});
		break;
		case "url":
		var content_array=content.split("?");
		$("#windown-content").ajaxStart(function(){
			$(this).html("<img src='"+templateSrc+"/images/loading.gif' class='loading' />");
		});
		$.ajax({
			type:content_array[0],
			url:content_array[1],
			data:content_array[2],
			error:function(){
				$("#windown-content").html("<p class='windown-error'>加载数据出错...</p>");
			},
			success:function(html){
				$("#windown-content").html(html);
			}
		});
		break;
		case "iframe":
		$("#windown-content").ajaxStart(function(){
			$(this).html("<img src='"+templateSrc+"/images/loading.gif' class='loading' />");
		});
		$.ajax({
			error:function(){
				$("#windown-content").html("<p class='windown-error'>加载数据出错...</p>");
			},
			success:function(html){
				$("#windown-content").html("<iframe src=\""+content+"\" width=\"100%\" height=\""+parseInt(height)+"px"+"\" scrolling=\"auto\" frameborder=\"0\" marginheight=\"0\" marginwidth=\"0\"></iframe>");
			}
		});
	}
	$("#windown-title h2").html(title);
	if(showbg == "true") {$("#windownbg").show();}else {$("#windownbg").remove();};
	$("#windownbg").animate({opacity:"0.5"},"normal");//设置透明度
	$("#windown-box").show();
	if( height >= 527 ) {
		$("#windown-title").css({width:(parseInt(width)+22)+"px"});
		$("#windown-content").css({width:(parseInt(width)+17)+"px",height:height+"px"});
	}else {
		$("#windown-title").css({width:(parseInt(width)+10)+"px"});
		$("#windown-content").css({width:width+"px",height:height+"px"});
	}
	var	cw = document.documentElement.clientWidth,ch = document.documentElement.clientHeight,est = document.documentElement.scrollTop; 
	var _version = $.browser.version;
	if ( _version == 6.0 ) {
		$("#windown-box").css({left:"50%",top:(parseInt((ch)/2)+est)+"px",marginTop: -((parseInt(height)+53)/2)+"px",marginLeft:-((parseInt(width)+32)/2)+"px",zIndex: "999999"});
	}else {
		$("#windown-box").css({left:"50%",top:"50%",marginTop:-((parseInt(height)+53)/2)+"px",marginLeft:-((parseInt(width)+32)/2)+"px",zIndex: "999999"});
	};
	var Drag_ID = document.getElementById("windown-box"),DragHead = document.getElementById("windown-title");
		
	var moveX = 0,moveY = 0,moveTop,moveLeft = 0,moveable = false;
		if ( _version == 6.0 ) {
			moveTop = est;
		}else {
			moveTop = 0;
		}
	var	sw = Drag_ID.scrollWidth,sh = Drag_ID.scrollHeight;
		DragHead.onmouseover = function(e) {
			if(drag == "true"){DragHead.style.cursor = "move";}else{DragHead.style.cursor = "default";}
		};
		DragHead.onmousedown = function(e) {
		if(drag == "true"){moveable = true;}else{moveable = false;}
		e = window.event?window.event:e;
		var ol = Drag_ID.offsetLeft, ot = Drag_ID.offsetTop-moveTop;
		moveX = e.clientX-ol;
		moveY = e.clientY-ot;
		document.onmousemove = function(e) {
				if (moveable) {
				e = window.event?window.event:e;
				var x = e.clientX - moveX;
				var y = e.clientY - moveY;
					if ( x > 0 &&( x + sw < cw) && y > 0 && (y + sh < ch) ) {
						Drag_ID.style.left = x + "px";
						Drag_ID.style.top = parseInt(y+moveTop) + "px";
						Drag_ID.style.margin = "auto";
						}
					}
				}
		document.onmouseup = function () {moveable = false;};
		Drag_ID.onselectstart = function(e){return false;}
	}
	$("#windown-content").attr("class","windown-"+cssName);
	var closeWindown = function() {
		$("#windownbg").remove();
		$("#windown-box").fadeOut("slow",function(){$(this).remove();});
	}
	if( time == "" || typeof(time) == "undefined") {
		$("#windown-close").click(function() {
			$("#windownbg").remove();
			$("#windown-box").fadeOut("slow",function(){$(this).remove();});
		});
	}else { 
		setTimeout(closeWindown,time);
	}
}


//-------------------------------------------------------------------------
//文章内容加载
//-------------------------------------------------------------------------
var objTag= $(".post");
var num= objTag.length;
var _cache=new Object;
function closentry(n){
	$(objTag[n]).children(".details").animate({height: 'toggle'}, "slow",function(){$(this).remove()}); 
	$(objTag[n]).children(".archive-arrow").remove();
	$('<div class="archive-arrow"><span title="阅读全文" class="show" onclick="loadentry(&quot;'+n+'&quot;);">阅读全文↓</span></div>').insertAfter($(objTag[n]).children(".archive-post-title").children("p"));
}
function loadentry(n){
	var _url=$(objTag[n]).children(".archive-post-title").children("h2").children("a").attr("href");
	$('<div class="details"><div style="width:160px;margin-top:8px;padding:0 2px;font-size:12px;background: #01E343; color:#FFF;">正在加载文章内容，请稍等！</div></div>').insertBefore($(objTag[n]).children(".singledata"));
	if(_cache[_url]==null){
		$(objTag[n]).children(".details").load(_url+" .post .entry",function(){
			_cache[_url]=$(objTag[n]).children(".details").html();
			imgobj=$(".entry img");
			AutoImgSize(imgobj);
			$('<span class="archive-arrow"><span title="收起全文" class="hide fRight" onclick="closentry(&quot;'+n+'&quot;);">收起全文↑</span></span>').insertAfter($(objTag[n]).children(".details"));
		});
	}else{
		$(objTag[n]).children(".archive-post-title").children(".archive-arrow").remove();
		$(objTag[n]).children(".details").html(_cache[_url]);
		$('<span class="archive-arrow"><span title="收起全文" class="hide fRight" onclick="closentry(&quot;'+n+'&quot;);">收起全文↑</span></span>').insertAfter($(objTag[n]).children(".details"));
	}
	$(objTag[n]).children(".archive-post-title").children(".archive-arrow").remove();
}

$(document).ready(function(){
	for(a=0;a<num;a++){
		$(objTag[a]).children(".archive-post-title").children(".archive-arrow").append('<span class="show" title="阅读全文" onclick="loadentry(&quot;'+a+'&quot;);">阅读全文↓</span>');
	}
});


//-------------------------------------------------------------------------
//焦点图切换
//-------------------------------------------------------------------------
var t = n = 0, count = $("#ifocus_list a").size();
function ifocusImg() {
	$("#ifocus_list a:not(:first-child)").hide();
	$("<div id='ifocus_info'></div>").insertAfter("#ifocus_list").html($("#ifocus_list a:first-child").find("img").attr('alt'));
	$("#ifocus_control li:first-child").addClass("current");
	$("#ifocus_info").click(function(){window.open($("#ifocus_list a:first-child").attr('href'), "_blank")});
	$("#ifocus_control li").click(function() {
		var i = $(this).text() - 1;
			n = i;
		if (i >= count) return;
			$("#ifocus_info").html($("#ifocus_list a").eq(i).find("img").attr('alt'));
			$("#ifocus_info").unbind().click(function(){window.open($("#ifocus_list a").eq(i).attr('href'), "_blank")})
			$("#ifocus_list a").filter(":visible").fadeOut().parent().children().eq(i).fadeIn(1000);
			$(this).addClass("current").siblings().removeClass("current");
		});
		t = setInterval("showAuto()", 3500);
		$("#ifocus").hover(function(){clearInterval(t)}, function(){t = setInterval("showAuto()", 3500);});		
}
function showAuto(){
	n = n >= (count - 1) ? 0 : ++n;
	$("#ifocus_control li").eq(n).trigger('click');
}

//-------------------------------------------------------------------------
//风格切换
//-------------------------------------------------------------------------
/*
function getstyleCookie(N){
	var c=document.cookie.split("; ");
	for(var i=0;i<c.length;i++){
		var d=c[i].split("=");
		if(d[0]==N)return unescape(d[1]);
	}
	return '';
}
function setstyleCookie(Q){
	var now=new Date();  
	var end=10;
	now.setTime(now.getTime()+end*24*3600*1000);
	document.cookie="css="+Q+";path=/;expires="+now.toGMTString()+";";
}
function setcss(){
	var mycss=getstyleCookie('css');
	if(mycss=="1"){
		document.getElementById("style").setAttribute("href","http://i2.sinaimg.cn/ty/nba/nba2009/style/lal.css");
	}else if(mycss=="2"){
		document.getElementById("style").setAttribute("href","http://i1.sinaimg.cn/ty/nba/nba2009/style/hou.css");
	}else if(mycss=="3"){
		document.getElementById("style").setAttribute("href","http://i1.sinaimg.cn/ty/nba/nba2009/style/bos.css");
	}else if(mycss=="4"){
		document.getElementById("style").setAttribute("href","http://i1.sinaimg.cn/ty/nba/nba2009/style/phx.css");
	}else if(mycss=="5"){
		document.getElementById("style").setAttribute("href","http://i3.sinaimg.cn/ty/nba/nba2009/style/njn.css");
	}else if(mycss=="6"){
		document.getElementById("style").setAttribute("href","http://i0.sinaimg.cn/ty/nba/nba2009/style/sas.css");				
	}else{
		document.getElementById("style").setAttribute("href","http://i1.sinaimg.cn/ty/nba/nba2009/style/blue.css");	
	}
	jQuery(function() {jQuery('.skin>ul>li').eq(mycss).addClass('skinse');});	
}
setcss();
*/
// ----------------------------------------------------------------------------
// markItUp!
// ----------------------------------------------------------------------------
// Copyright (C) 2008 Jay Salvat
// http://markitup.jaysalvat.com/
// ----------------------------------------------------------------------------
// Html tags
// http://en.wikipedia.org/wiki/html
// ----------------------------------------------------------------------------
// Basic set. Feel free to add more tags
// ----------------------------------------------------------------------------
mySettings = {	
	onShiftEnter:  	{keepDefault:false, replaceWith:'<br />\n'},
	onCtrlEnter:  	{keepDefault:false, openWith:'\n<p>', closeWith:'</p>'},
	onTab:    		{keepDefault:false, replaceWith:'    '},
	markupSet:  [ 	
		{name:'Bold', key:'B', openWith:'(!(<strong>|!|<b>)!)', closeWith:'(!(</strong>|!|</b>)!)' },
		{name:'Italic', key:'I', openWith:'(!(<em>|!|<i>)!)', closeWith:'(!(</em>|!|</i>)!)'  },
		{name:'Stroke through', key:'S', openWith:'<del>', closeWith:'</del>' },
		{separator:'---------------' },
		{name:'Picture', key:'P', replaceWith:'<img src="[![Source:!:http://]!]" alt="[![Alternative text]!]" />' },
		{name:'Link', key:'L', openWith:'<a href="[![Link:!:http://]!]"(!( title="[![Title]!]")!)>', closeWith:'</a>', placeHolder:'Your text to link...' },
		{separator:'---------------' },
		{name:'Quotes', openWith:'<quote>', closeWith:'</quote>'}, 
		{name:'Code', openWith:'<code>', closeWith:'</code>'}, 
		{separator:'---------------' },
		{name:'Clean', className:'clean', replaceWith:function(markitup) { return markitup.selection.replace(/<(.*?)>/g, "") } }		
	]
}
//All End