
/*
 * 从rediscache显示各数量 代替showNum 这个js
 * @uid 用户ID
 * @aid 文章ID
 * @act support,oppose,click,
 * @flag u a
 * @ifincr 0 1
 * @ids css中id的名字，从那个ID显示数量
 * 
 */ 
function getNum(uid, aid, act, flag, ifincr, ids){
	$.ajax({
			type:"POST",
			url:'index.php?c=Article&a=getNum',			
			data:"uid="+uid+"&aid="+aid+"&act="+act+"&flag="+flag+"&ifincr="+ifincr,			
			error:function(){
				$("#"+ids).text(0);
			},
			success:function(data){	
				if(act=="support"){
					$("#support_"+aid).text(data);	
					$("#supportnum_"+aid).text(data);
				}else{
					$("#"+ids).text(data);
				}
				//$("#"+ids).text(data);
				
			}
			
		})		
}

function getCommentNum(aid, commentNum){
	$.ajax({
			type:"POST",
			url:'index.php?c=Article&a=getCommentNum',			
			data:"aid="+aid+"&commentNum="+commentNum,			
			error:function(){
				
			},
			success:function(data){			
			
			}
			
		})		
}
$(function(){	
	
	
	
	$(".swichNew").switchable(".swichNewCon");
	$(".switch48").switchable(".switch48Con");
	
	/*显示标题*************************************************************
	var blogchinaTitle = $("#blogchinatitle").html();
	document.title= blogchinaTitle;
	*/
	
	
	/*显示各数量redis**************************************************************/
	$('#flower').text(getNum($("#uid").val(), $("#aid").val(), 'support', 'a', 0, 'flower'));
	$('#eggs').text(getNum($("#uid").val(), $("#aid").val(), 'oppose', 'a', 0, 'eggs'));
	$('#click').text(getNum($("#uid").val(), $("#aid").val(), 'click', 'a', 1, 'click'));
	
	
	$('#supportnum').text(getNum($("#uid").val(), $("#aid").val(), 'support', 'a', 0, 'supportnum'));
	$('#opposenum').text(getNum($("#uid").val(), $("#aid").val(), 'oppose', 'a', 0, 'opposenum'));
	
	
	/*显示配图**************************************************************/
	$('#imgpic').load('index.php?c=Article&a=getArticlePic&aid='+$("#articleid").val());	
	
	//判断评论数字的大小
	$(".floor").each(function(){
		var num = $(this).html();
		if( num > 999){
			$(this).css("fontSize","20px");
			};
		if( num > 9999){
			$(this).css("fontSize","16px");
			};
	})
	$(".big").each(function(){
		var num = $(this).html();
		if( num > 999999){
			$(this).css("fontSize","18px");
			};
	})
	
	
	
	/*选择字号**************************************************************/	
	$(".choose a").click(function(){
		$(".choose a").removeClass("current");
		$(this).addClass("current");
		var fonsize = $(this).attr("id");
		if(fonsize == "small"){$("#mainArticalBox p").attr("style","font-size:12px;line-height:20px")};		
		if(fonsize == "mid"){$("#mainArticalBox p").attr("style","font-size:14px;line-height:24px")};
		if(fonsize == "big"){$("#mainArticalBox p").attr("style","font-size:16px;line-height:32px")};

	})
	
	/*归档**************************************************************/	
	$(".fenBox span:first").addClass("current");
	$(".fenBox span").each(function(){
		var o = $(this).parents(".fenBox").find("ul");	
		if($(this).hasClass("current")){o.css("display","block")}	
		}).click(function(){
			var o = $(this).parents(".fenBox").find("ul");	
			if($(this).hasClass("current")){o.css("display","none");$(this).removeClass("current")}	
			else {$(this).addClass("current");o.css("display","block");}
		})
	
	/*相关阅读**************************************************************/		
	if($(".picList").length <= 7){
		$(".popBtn").hide()
	};
	$("#trigger").switchable(".picList", {
		triggerType: "click",
		effect: "scroll",
		steps: 1,
		visible: 7
	}).carousel();
	
	var api2 = $("#trigger").switchable();
	$("#next2").click(function(){
		api2.next();
	});
	$("#prev2").click(function(){
		api2.prev();
	});	
	
	
	
	/*历史阅读********************************************************/
	var histories = new Histories();
	//添加历史数据列表
	histories.appendTo('#histories');	
	var id = $("#aid").val();
	//点击追加测试数据按钮	
	var dataHistory = {'id':id, 'title':''+$("#blogchinatitle").text()+'', 'url':'http://'+$("#username").val()+'.blogchina.com/'+id+'.html'};
	//保存数据
	histories.save(dataHistory);
	//清空列表
	$('#histories').html('');
	//添加历史数据列表
	histories.appendTo('#histories');
	
	
	/*阅读器**************************************************************/	
	var uid=$("#uid").val();
	var title=$("#blogchinatitle").text();
	var username=$("#username").val();
	$(".print").click(function(){
		$("#reader").wBox({
			noTitle:true,
			requestType: "ajax",
			show : true,
			target : "index.php?c=Article&a=read&aid="+$("#aid").val()+"&title="+title+"&username="+username,
			wBoxURL : "images/index/skin/skin_green_default/images/wbox"
		});
	});
	
	
	//加载评论************************************************************/
	if($("#allowcomment").val()==1){
		$.ajax({
			 url:'libraries/comment/commentview1.php',
			 data:"aid="+$("#aid").val()+"&uid="+uid,
			 dataType:'html',
			 type:'post',
			 success:function(data){
				 $("#loadComment").html(data);
			 }
		});
		
	}
	//左右高度一样*********************************************************/
	$(document).ajaxStop(function(evt, request, settings){  
		 heightL();
		 
		 
	}); 
	
	//头部登陆******************************************************************/
	$.ajax({
		 url:'index.php?c=User&a=logintitle',
		 dataType:'html',
		 type:'post',
		 data:"username="+username,
		 success:function(data){
			 $("#loading").html(data);
		 }
	});
	
	
	//滚动加载****************************************************************/
	$(".scrollLoading").scrollLoading();

	//文末加入图标******************************************************************/
	(function(){
		var obj = null;
		if(document.getElementById('arctTailMark')) {
		obj = document.getElementById('arctTailMark');
		}
		if(obj!=null) {
		var str = ' <a href="http://www.blogchina.com" target="_blank" title="返回主页"  class="returnIndex"></a>';
		try
		{
			var oo = obj.previousSibling;
		while(oo.nodeType!=1 || oo.innerHTML.replace(/\s|\u3000/g,'').length==0) {
		   oo = oo.previousSibling;
		}
		if(oo.nodeType==1 && oo.tagName.toLowerCase()=='p') {
		  var span = document.createElement('span');
		  span.innerHTML =str;
		  oo.appendChild(span);
		 }
		}
		catch (e){}
		}
		})();
		
})





/*收藏************************************************************/
function addFavorite(){  
    if (document.all){  
        try{  
            window.external.addFavorite(window.location.href,document.title);  
        }catch(e){  
            alert( "您的浏览器不支持收藏，请使用Ctrl+D进行添加" );  
        }  
 
    }else if (window.sidebar){  
        window.sidebar.addPanel(document.title, window.location.href, "");  
     }else{  
        alert( "您的浏览器不支持收藏，请使用Ctrl+D进行添加" );  
    }  
}

/*设为首页***********************************************************/
function setHomepage(){  
    if (document.all){  
        document.body.style.behavior='url(#default#homepage)';  
          document.body.setHomePage(window.location.href);  
    }else if (window.sidebar){  
        if(window.netscape){  
            try{  
                netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");  
            }catch (e){  
                alert( "该操作被浏览器拒绝，如果想启用该功能，请在地址栏内输入 about:config,然后将项 signed.applets.codebase_principal_support 值该为true" );  
            }  
        }  
        var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components. interfaces.nsIPrefBranch);  
        prefs.setCharPref('browser.startup.homepage',window.location.href);  
    }else{  
        alert('您的浏览器不支持自动设置首页, 请使用浏览器手动设置!');  
    }  
}




/*左右高度调控********************************************************************/
function heightL(){
	var leftHeight = $(".conBox").outerHeight(true); 
	var rightHeight = $(".rightBox").outerHeight(true);
	if(leftHeight <= rightHeight){
		$(".mainBox").height(rightHeight);
	}else{
		$(".mainBox").height(leftHeight);
	}
}


//图片等缩放***********************************************************************/
function resizeimg(ImgD,iwidth,iheight) { 
    var image=new Image(); 
    image.src=ImgD.src; 
    if(image.width>0 && image.height>0){ 
       if(image.width/image.height>= iwidth/iheight){ 
          if(image.width>iwidth){ 
              ImgD.width=iwidth; 
              ImgD.height=(image.height*iwidth)/image.width; 
          }else{ 
                 ImgD.width=image.width; 
                 ImgD.height=image.height; 
               } 
              ImgD.alt=image.width+"×"+image.height; 
       } 
       else{ 
               if(image.height>iheight){ 
                      ImgD.height=iheight; 
                      ImgD.width=(image.width*iheight)/image.height; 
               }else{ 
                       ImgD.width=image.width; 
                       ImgD.height=image.height; 
                    } 
               ImgD.alt=image.width+"×"+image.height; 
           } 
　　　　ImgD.style.cursor= "pointer"; //改变鼠标指针 
　　　　ImgD.onclick = function() { window.open(this.src);} //点击打开大图片 
　　　if (navigator.userAgent.toLowerCase().indexOf("ie") > -1) { //判断浏览器，如果是IE 
　　　　　//ImgD.title = "请使用鼠标滚轮缩放图片，点击图片可在新窗口打开"; 
　　　　　ImgD.onmousewheel = function img_zoom() //滚轮缩放 
　　　　 { 
　　　　　　　　　var zoom = parseInt(this.style.zoom, 10) || 100; 
　　　　　　　　　zoom += event.wheelDelta / 12; 
　　　　　　　　　if (zoom> 0)　this.style.zoom = zoom + "%"; 
　　　　　　　　　return false; 
　　　　 } 
　　  } else { //如果不是IE 
　　　　　　     //ImgD.title = "点击图片可在新窗口打开"; 
　　　　　   } 
   } 
}

//qq一键转播接口
function postToWb(){
	var _url = encodeURIComponent(location.href);
	var _pic = encodeURI('');//（例如：var _pic='图片url1|图片url2|图片url3....）
	var _t = '';//标题和描述信息
	var metainfo = document.getElementsByTagName("meta");
	for(var metai = 0;metai < metainfo.length;metai++){
		if((new RegExp('description','gi')).test(metainfo[metai].getAttribute("name"))){
			_t = metainfo[metai].attributes["content"].value;
		}
	}
	_t =  document.title+_t;//请在这里添加你自定义的分享内容
	if(_t.length > 120){
		_t= _t.substr(0,117)+'...';
	}
	_t = encodeURI(_t);
	var _u = 'http://share.v.t.qq.com/index.php?c=share&a=index&url='+_url+'&appkey=801069760&pic='+_pic+'&assname=博客中国&title='+_t;
	window.open( _u,'', 'width=700, height=680, top=0, left=0, toolbar=no, menubar=no, scrollbars=no, location=yes, resizable=no, status=no' );
}
		


