//平滑转跳
jQuery.fn.anchorGoWhere = function(options){
     var obj = jQuery(this);
     var defaults = {target:0, timer:1000};
     var o = jQuery.extend(defaults,options);
     obj.each(function(i){
         jQuery(obj[i]).click(function(){
             var _rel = jQuery(this).attr("href").substr(1);
             switch(o.target){
                 case 1: 
                     var _targetTop = jQuery("#"+_rel).offset().top;
                     jQuery("html,body").animate({scrollTop:_targetTop},o.timer);
                     break;
                 case 2:
                     var _targetLeft = jQuery("#"+_rel).offset().left;
                     jQuery("html,body").animate({scrollLeft:_targetLeft},o.timer);
                     break;
             }
            return false;
         });                  
     });
 };

$(function(){
	function G(id){
	  return document.getElementById(id);
	}
	function isEmail(strEmail) {
		if (strEmail.search(/^w+((-w+)|(.w+))*@[A-Za-z0-9]+((.|-)[A-Za-z0-9]+)*.[A-Za-z0-9]+$/) != -1){
		return true;}
		else{
		return false;
		}
	}
	
	//双击自动滚屏
	var autoscroll=0;
	$("#autoscroll").click(function(){	 
		autoscroll=setInterval('scrollBy(0,2)',50);
		return false;
    });
	$("body").mousedown(function(){	 
		clearInterval(autoscroll);
    });
	
	//字体放大缩小
	$("#font_b").click(function(){	   
        $("#post").css({"font-size":'16px'});
		return false;
    });
	$("#font_m").click(function(){	   
        $("#post").css({"font-size":'14px'});
		return false;
    });
	$("#font_s").click(function(){	   
        $("#post").css({"font-size":'12px'});
		return false;
    });
	
	
	//发表评论
	$(".addcomment").anchorGoWhere({target:1});

	$("#addfav").click(function(){
			window.external.addFavorite('http://'+document.location.host,'陈庆华的博客');
			return false;
		});
	
	$("#postfav").click(function(){
		window.external.addFavorite(window.location.href,document.title);return false;												
    });
	
	//链接
	$(".mylink").mouseover(function(){
		if(this.href.indexOf("http://www.chenqinghua.com/e/go/") == 0 ){   
          this.href=this.href.replace("http://www.chenqinghua.com/e/go/?url=","");
		  this.rel=this.href;
        } 
						  				 
	});
	$(".mylink").click(function(){
		if(this.rel.length > 0 ){ 
		  this.href="http://www.chenqinghua.com/e/go/?url="+this.href; 	
		}
	});



var isIE=!!window.ActiveXObject; 
var isIE6=isIE&&!window.XMLHttpRequest; 
if(isIE6){
		$("#tips").html('<h3>温馨提示</h3><div class="textwidget">　　我们检测到你正在使用<font color="red">漏洞超多</font>、<font color="red">BUG超多</font>、<font color="red">性能超低</font>而且<font color="red">不符合标准</font>的<font color="red">IE6</font>浏览器。<br>建议你将你的浏览器升级到IE7、IE8或者火狐和Google Chrome浏览器，点击<a style="color:green;" href="http://www.chenqinghua.com/post/kill-ie6.html" class="green" title="点击查看详情">这里</a>查看详情。</div>');
		$("#tips").hide();
		$("#tips").show(500);

}
	
	var myurl = window.location.href;
	var myenurl = encodeURIComponent(myurl);
	var title = document.title;
	var entitle = encodeURI(document.title);
	
	$("#add_fav").click(function(){window.external.addFavorite('http://'+document.location.host,'陈庆华的博客'); return false;});
	$("#add_sina").click(function(){window.open('http://v.t.sina.com.cn/share/share.php?title='+entitle+myurl);return false;});
	$("#add_163").click(function(){window.open('http://t.163.com/article/user/checkLogin.do?info='+entitle+myenurl);return false;});
	$("#add_sohu").click(function(){window.open('http://t.sohu.com/third/post.jsp?&url='+myenurl+'&title='+entitle+'&content=utf-8&pic=');return false;});
	$("#add_qq").click(function(){window.open('http://v.t.qq.com/share/share.php?title='+entitle+'&url='+myenurl);return false;});
	$("#add_qqbook").click(function(){window.open('http://shuqian.qq.com/post?from=3&jumpback=2&noui=1&uri='+myenurl+'&title='+entitle);return false;});
	$("#add_kaixin").click(function(){window.open('http://www.kaixin001.com/repaste/share.php?rtitle='+entitle+'&rurl='+myenurl);return false;});
	$("#add_renren").click(function(){window.open('http://share.renren.com/share/buttonshare.do?link='+myenurl+'&title='+entitle);return false;});
	$("#add_baiducang").click(function(){window.open('http://cang.baidu.com/do/add?it='+entitle+'&iu='+myenurl);return false;});
	$("#add_google").click(function(){window.open('http://www.google.com/bookmarks/mark?op=add&hl=zh-cn&bkmk='+myenurl+'&title='+entitle);return false;});
	$("#add_douban").click(function(){window.open('http://www.douban.com/recommend/?url='+myenurl+'&title='+entitle);return false;});
	
	$("#tab1").click(function(){
		$("#con1").show(); 
		$("#con2").hide();
		$("#con3").hide();
		$("#tab1").addClass("this");
		$("#tab2").removeClass("this");
		$("#tab3").removeClass("this");					
								
    });
	$("#tab2").click(function(){
		
		$("#con1").hide();
		$("#con2").show(); 
		$("#con3").hide();
		$("#tab1").removeClass("this");
		$("#tab2").addClass("this");
		$("#tab3").removeClass("this");
   });
   $("#tab3").click(function(){
		
		$("#con1").hide();
		$("#con2").hide();
		$("#con3").show(); 
		$("#tab1").removeClass("this");
		$("#tab2").removeClass("this");
		$("#tab3").addClass("this");
   });
   
   $("#comment_form input").mouseover(function(){
		$(this).css("border","1px solid #F90"); 
       
   });
   $("#comment_form input").mouseout(function(){
		$(this).css("border","1px solid #7F9DB9"); 
       
   });
   
   $("#comment_content").mouseover(function(){
		$(this).css("border","1px solid #F90"); 
       
   });
   $("#comment_content").mouseout(function(){
		$(this).css("border","1px solid #7F9DB9"); 
   });
   

    //加版权
	document.body.oncopy = function () {
	setTimeout(function(){
	   var text = clipboardData.getData("text");
	   if (text) {
	   text = text + "\r\n本文来自: http://www.chenqinghua.com 详细出处参考："+location.href;
	   clipboardData.setData("text", text);
	   }
	}, 100 )
	}
	//平滑导航
	$('#go_top').click(function(){$('html,body').animate({scrollTop: '0px'}, 800);}); 
	//点击id="shang"对象时，滑动至相对浏览器滚动条为0px（即顶部），时间为800毫秒
	$('#go_comm').click(function(){$('html,body').animate({scrollTop:$('#comment_box').offset().top}, 800);});
	//点击id="comt"对象时，滑动至id="comment"相对浏览器滚动条的距离，时间为800毫秒
	$('#go_bottom').click(function(){$('html,body').animate({scrollTop:$('#footer').offset().top}, 800);});

});
