//修复ie6背景
try{document.execCommand("BackgroundImageCache", false, true);}catch(e){}

//分享
var share = {
	t : encodeURI(document.title),
	u : encodeURIComponent(document.location),
	
	goto :function(h){
		window.open( h,'', 'width=700, height=500, top=0, left=0, toolbar=no, menubar=no, scrollbars=no, location=yes, resizable=no, status=no' );
	},
	
	qzone :function(){
		var h = 'http://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?url='+share.u+'&title='+share.t;
		share.goto(h);
	},
	
	tqq :function(){
		var h = 'http://v.t.qq.com/share/share.php?url='+share.u+'&title='+share.t;
		share.goto(h);
	},
	
	tsina :function(){
		var h = 'http://service.weibo.com/share/share.php?url='+share.u+'&title='+share.t;
		share.goto(h);
	},
	
	tsohu :function(){
		var h = 'http://t.sohu.com/third/post.jsp?url='+share.u+'&title='+escape(share.t);
		share.goto(h);
	},
	
	renren :function(){
		var h = 'http://www.connect.renren.com/share/sharer?url='+share.u+'&title='+share.t;
		share.goto(h);
	},
	
	kaixin :function(){
		var h = 'http://www.kaixin001.com/repaste/bshare.php?rtitle='+share.t+'&rcontent='+share.u+'&rurl='+share.u;
		share.goto(h);
	},
	
	douban :function(){
		var h = 'http://shuo.douban.com/!service/share?image=&href'+share.u+'&name='+share.t;
		share.goto(h);
	}
};

var Jz = {
	get : function(el) {
		if(typeof el == "string") {
			return $("#"+el);	
		}
		else{
			return el;
		}
	},
	refresh :function (id,url,isFocus){
		if(url.indexOf("?") == -1) {
		  Jz.get(id).attr({src:url +"?t="+ Math.random()});
	    }else{
		  Jz.get(id).attr({src:url +"&t="+ Math.random()});
	    }
	    if(!isFocus) {
	    	$("#jzf_bcaptcha").val("").focus();	
	    } else {
	    	$("#jzf_bcaptcha").val("");
	    }
	},
	addBookMark :function(el,title,url){
		if(!el){return;}
 		title = title || document.title;
 		url = url || window.location.href;
	    url= url||location.href;
	    title= title||document.title;
	    
	    var isMac,message,external=window.external,sidebar=window.sidebar;
	 	
	    if(external&&(typeof external.AddFavorite != 'undefined' ||	(navigator.userAgent.indexOf('Maxthon')>-1&&parseInt(external.max_version)==2))){	 
	        	external.AddFavorite(url,title);	 
	    }else if((sidebar&&sidebar.addPanel)||window.opera){
	        //opera,ff
	        el.href=url;
	        el.title=title;
	    }else{
	        //webkit,other not supported browers
	        isMac = navigator.appVersion.indexOf("Mac")>-1,
	        message = "您的浏览器不支持自动添加收藏夹功能\n请手动将本页添加到收藏夹（快捷键："+(isMac?'Cmd':'Ctrl')+'+D)',
	        alert(message);
	    }
	},
	copy :function(){
		var url=document.URL;
			if(window.clipboardData){
				window.clipboardData.setData('text',url);
				alert("复制成功，现在您可以粘贴(Ctrl+V)到你想要的地方中了。");
			}else{
				alert("您的浏览器不支持剪贴板操作，请自行复制。");
			}
	}
};

//幻灯片
var picloop = {
	init :function(){
		var n = 1;
		var eyes=$("#player img");
		
		var clickHandler = function(n){
			eyes.animate({opacity:'hide'},{duration:1500});
			eyes.eq(n).animate({opacity:'show'},{duration:1500});
		}
		
		function loop(){
			n=(n<eyes.length)?n:0;
			clickHandler(n);
			n++;
		}
		
		var t=0;
		eyes.hover(function(){
			if(t){
				clearInterval(t);
			}
		},function(){
			t=setInterval(loop,4000);
		});	
		t=setInterval(loop,4000);
	}
}

//滚动新闻
var scrollNews = {
	init :function(){
		var hotnews = $("#hotnews").find("div");
		var alist = hotnews.find("a");
		var news_length = alist.length;
		var timer = null;
		if(news_length == 1) {
			return;
		}else if(news_length >=1){
			hotnews.append(alist.eq(0).clone(true));
		}
		var scrollVal =  alist.eq(0).height();
		var scroll_fn = function(){
			var curr_scroll_val = hotnews.get(0).scrollTop;
			if(curr_scroll_val == scrollVal*news_length){
				hotnews.get(0).scrollTop = 0;
				curr_scroll_val = 0;
			}
			hotnews.animate({"scrollTop":curr_scroll_val+scrollVal},function(){
				timer = setTimeout(scroll_fn,8000);          				
			});
		}
		
		hotnews.hover(function(){
			if(timer){
				clearTimeout(timer);
			}
		},function(){
			if(timer){
				clearTimeout(timer);
			}
			timer = setTimeout(scroll_fn,8000);             		
		});
	
		timer = setTimeout(scroll_fn,8000);
	}
}
