﻿function getYear(){
	var date=new Date();
	document.write(' 2008 - '+date.getFullYear()+' ');
}
function quickSort(arr) {
　　if (arr.length <= 1) { return arr; }
　　var pivotIndex = Math.floor(arr.length / 2);
　　var pivot = arr[pivotIndex];
　　var left = [];
　　var right = [];
　　for (var i = 0; i < arr.length; i++){
　　　　if (arr[i] < pivot) {
　　　　　　left.push(arr[i]);
　　　　} else if(arr[i] > pivot) {
　　　　　　right.push(arr[i]);
　　　　}
　　}
　　return quickSort(left).concat([pivot], quickSort(right));
};
var changeNewsIndex=0;
function changeNews(){
	var $obj=$('#mainNews ul');
	if(changeNewsIndex==$obj.find('li').length)
	changeNewsIndex=0;
	$obj.animate({top:changeNewsIndex*20*(-1)},function(){
		changeNewsIndex++;
		setTimeout(changeNews, 6000);
	})
}
/*复制文本链接方法*/
function copyToClipboard(txt) {
	if (window.clipboardData) {
		window.clipboardData.clearData();
		window.clipboardData.setData("Text", txt);
	} else if (navigator.userAgent.indexOf("Opera") != -1) {
		window.location = txt;
	} else if (window.netscape) {
		try {
			netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
		} catch (e) {
			//alert("Your current browser settings have been off this feature!\nPlease follow these steps to turn on this feature! to open a new browser in the browser address bar type 'about: config' and press ENTER. \nand then locate the 'signed.applets.codebase_principal_support' item is set to post double-click the 'true'. \nStatement: This feature will not be very hazardous to your computer or data security!")   
			alertM("您的当前浏览器设置已关闭此功能！请按以下步骤开启此功能！\n新开一个浏览器，在浏览器地址栏输入'about:config'并回车。\n然后找到'signed.applets.codebase_principal_support'项，双击后设置为'true'。\n声明：本功能不会危及您计算机或数据的安全！");
		}
		var clip = Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard);
		if (!clip) return;
		var trans = Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable);
		if (!trans) return;
		trans.addDataFlavor('text/unicode');
		var str = new Object();
		var len = new Object();
		var str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);
		var copytext = txt;
		str.data = copytext;
		trans.setTransferData("text/unicode", str, copytext.length * 2);
		var clipid = Components.interfaces.nsIClipboard;
		if (!clip) return false;
		clip.setData(trans, null, clipid.kGlobalClipboard);
	}
	alertM("已成功复制！");
	return true;
}
/*获取cookie方法*/
var Cookie = Cookie || {
	/* 
	函数名称： Cookie.Get([string name])  
	函数功能：得到Cookie  
	参数：name 可选项，要取得的Cookie名称  
	说明：name为空时将通过数组形式返回全部Cookie，name不为空时返回此Cookie名称的值，没有任何值时返回undefined  
	*/
	Get: function (name) {
		var cv = document.cookie.split("; "); //使用"; "分割Cookie   
		var cva = [], temp;
		/**//*循环的得到Cookie名称与值*/
		for (var i = 0; i < cv.length; i++) {
			temp = cv[i].split("="); //用"="分割Cookie的名称与值   
			cva[temp[0]] = decodeURIComponent(temp[1]);
		}
		if (name) return cva[name]; //如果有name则输出这个name的Cookie值   
		else return null;
		//else return cva; //如果没有name则输出以名称为key，值为Value的数组   
	},
	/*  
	函数名称： Cookie.Set(string name, string value[, int expires[, string path[, string domain[, string secure]]]])  
	函数功能：存入Cookie  
	参数：name 必要项，要存入的Cookie名称  
	value 必要项，要存入的Cookie名称对应的值  
	expires 可选项，Cookie的过期时间，可以填入以秒为单位的保存时间，也可以填入日期格式（wdy, DD-Mon-YYYY HH:MM:SS GMT）的到期时间  
	path 可选项，Cookie在服务器端的有效路径  
	domain 可选项，该Cookie的有效域名  
	secure 可选项， 指明Cookie 是否仅通过安全的 HTTPS 连接传送，0或false或空时为假  
	说明：保存成功则返回true，保存失败返回false  
	*/
	Set: function (name, value, expires, path, domain, secure) {
		if (!name || !value) return false; //如果没有name和value则返回false   
		if (name == "" || value == "") return false; //如果name和value为空则返回false   
		/**//*对于过期时间的处理*/
		if (expires) {
			/**//*如果是数字则换算成GMT时间，当前时间加上以秒为单位的expires*/
			if (/^[0-9]+$/.test(expires)) {
				var today = new Date();
				expires = new Date(today.getTime() + expires * 1000).toGMTString();
				/**//*判断expires格式是否正确，不正确则赋值为undefined*/
			} else if (!/^wed, d{2} w{3} d{4} d{2}:d{2}:d{2} GMT$/.test(expires)) {
				expires = undefined;
			}
		}
		/**//*合并cookie的相关值*/
		var cv = name + "=" + encodeURIComponent(value) + ";" + ((expires) ? " expires=" + expires + ";" : "") + ((path) ? "path=" + path + ";" : "") + ((domain) ? "domain=" + domain + ";" : "") + ((secure && secure != 0) ? "secure" : "");
		/**//*判断Cookie总长度是否大于4K*/
		if (cv.length < 4096) {
			document.cookie = cv; //写入cookie   
			return true;
		} else {
			return false;
		}
	},
	/**//*  
    函数名称： Cookie.Del(string name[, string path[, string domain]])  
    函数功能：删除Cookie  
    参数：name 必要项，要删除的Cookie名称  
    path 可选项，要删除的Cookie在服务器端的有效路径  
    domain 可选项，要删除的Cookie的有效域名  
    说明：删除成功返回true，删除失败返回false  
    */
	Del: function (name, path, domain) {
		if (!name) return false; //如果没有name则返回false   
		if (name == "") return false; //如果name为空则返回false   
		if (!this.Get(name)) return false; //如果要删除的name值不存在则返回false   
		/**//*合并Cookie的相关值*/
		document.cookie = name + "=;" + ((path) ? "path=" + path + ";" : "") + ((domain) ? "domain=" + domain + ";" : "") + "expires=Thu, 01-Jan-1970 00:00:01 GMT;";
		return true;
	}
}
//封装了url操作的类
var URLObject = function(url)
{
    //声明
    //对象
    var _parameterObject = function(key, value)
    {
        this.key = key == undefined ? "" : key;
        this.value = value == undefined ? "" : value;
    }
    //对象end
    //成员属性
    var _parameter = "";
    this._parameters = [];
    var _key = [];
    var _value = [];
    //成员属性end
    //为集合添加自定义方法
    this._parameters.constructor.prototype.getKey = function(value)
    {
        for (i = 0; i < this.length; i++)
        {
            if (this[i].value == value)
            {
                return this[i].key;
            }
        }
    };
    this._parameters.constructor.prototype.getValue = function(key)
    {
        for (i = 0; i < this.length; i++)
        {
            if (this[i].key == key)
            {
                return this[i].value;
            }
        }
    };
    //为集合添加自定义方法end

    //方法
    this.toString = function()
    {
        return url;
    };
    this.getParameterString = function()
    {
        return _parameter;
    };
    this.getParameter = function(name)
    {
        //return string
        if (_value != undefined)
            for (i = 0; i < _value.length; i++)
            if (_key[i] == name) return _value[i];
        return "";

    };
    this.getParameters = function()
    {
        //return array
        return this._parameters;
    };
    //方法end

    //构造
    if (url == undefined || url == null)
    {
        url = location.href == null || location.href == "" ? document.URL == null || document.URL == "" ? document.location : document.URL : location.href;
    }
    var index = url.split('?');
    if (index.length > 0)
    {
        _parameter = index[index.length-1];
        _parameters = _parameter.split('&');
        for (i = 0; i < _parameters.length; i++)
        {
            var _temp = _parameters[i].split('=');
            _key[i] = _temp[0];
            _value[i] = _temp[1];
            _parameters[i] = new _parameterObject(_temp[0], _temp[1]);
        }
    }
    //构造end
};
$.fn.drag=function(opt){
	opt=opt?opt:this;
	$(this).each(function(){
		this.onselectstart=function(){return false};
		if($.browser.mozilla)
			this.addEventListener('DOMMouseScroll',function(e){e.preventDefault()},false);
		else
			this.onmousewheel=function(){return false};
		var $drag=$(opt);
		var w=$(window).width()-$drag.width()-4;
		var c=$drag.offset().top-$(window).scrollTop();
		var scroll=function(){$drag.stop(true,false).animate({top:c+$(window).scrollTop()})};
		$(this).mousedown(function(e){
			var st=$(window).scrollTop();
			var t=st+4;
			var u=st+$(window).height()-$drag.height()-4;
			var x=e.pageX-$drag.fadeTo('fast',0.6).offset().left;
			var y=e.pageY-$drag.offset().top-st; 
			$(document).mousemove(function(e){
				var cx=e.clientX-x;
				var cy=e.clientY-y;
				c=$drag.css({left:cx<4?4:(cx>w?w:cx),top:cy>u?u:(cy<t?t:cy)}).offset().top-$(window).scrollTop();
			}).mouseup(function(){
				$drag.fadeTo('fast',1);
				$(this).unbind('mousemove').unbind('mouseup');
			});
			return false;
		})
		$(window).bind('scroll',scroll)
	});
	return $(this);
};
$.fn.showFriends=function(opt){
	opt=$.extend({
		width:400,
		height:400,
		left:0,
		top:0,
		url:'1.html'
	},opt||{});
	var $t=$(this);
	var i=0,l=0,t='';
	$t.attr('readonly','readonly').after('<a id="sFBtn" href="javascript:void(0)" style="width:71px;height:25px;display:inline-block;background:url(http://images.yuedutong.com/images/user/tianjia.png);margin:8px 0 -8px 9px;_position:relative;_margin:4px 0 -4px 9px"></a>');
	var $f=$('#friendsDl');
	$f.delegate('dt','click',function(){
		if($(this).attr('class')=="hover")
			$(this).removeClass('hover').next().slideUp();
		else
			$(this).addClass('hover').next().slideDown();
		return false;
	}).delegate('span','click',function(){
		if($(this).attr('class')=="check"){
			$(this).attr('class','checkIn');
		}else{
			$(this).attr('class','check');
		}
		var $fl=$('#friendsDl span.checkIn');
		l=$fl.length;
		t='';
		for(i=0;i<l;i++){
			t+=$fl.eq(i).text()+',';
		}
		$t.val(t);
		return false;
	}).click(function(){return false});
	$('#sFBtn').click(function(){
		$f.css({left:$t.offset().left,top:$t.offset().top+$t.height()+4}).slideDown();
		$('body').click(function(){
			$f.hide();
			$('body').unbind();
		});
		return false;
	});
}
var amrt=false;
function alertM(content,opt){
	opt= $.extend({
		time:4000,
		title:'提示',
		type:'text',
		width:400,
		height:'auto',
		btn:{
			Y:true,
			YT:'确定',
			N:false,
			NT:'取消'
		},
		cF:function(){},
		yF:function(){},
		nF:function(){},
		rF:function(){}
	},opt||{});
	var w={
		height: $(document).height(),
		left: $(window).width()/2-opt.width/2,
		top: $(window).height()/2+$(window).scrollTop()
	};
	opt.h=function(){
		$('<div id="hbg" style="height:'+w.height+'px;"></div>').appendTo('body').fadeTo('fast',0.6);
		return opt;
	}
	opt.s=function(){
		var str=['<div id="alertM" class="rightP" style="left:',w.left,'px;height:',opt.height,'px;width:',opt.width,'px;overflow:hidden"><h2 id="alertH" class="grayTitle"><span class="redTitleL"></span><span class="redTitleM">',opt.title,
			'</span><span class="redTitleR"></span></h2><a id="alertR" class="floatR ga" title="关闭" href="javascript:void(0)"><span class="gb"><span class="gc">&nbsp;</span><span class="gd">&times;</span></span></a><div id="alertP">'];
		if(opt.type!='html'){
			str.push('<p id="alertC" class="textCenter">',content,'</p>');
		}else{
			str.push(content);
		}
		if(opt.btn.Y||opt.btn.N){
			str.push('<div id="alertBtns">');
			if(opt.btn.Y){
				str.push('<a id="alertY" class="floatR ga" href="javascript:void(0)"><span class="gb"><span class="gc">&nbsp;</span><span class="gd">',opt.btn.YT,'</span></span></a>');
			}
			if(opt.btn.N){
				str.push('<a id="alertN" class="floatR ga" href="javascript:void(0)"><span class="gb"><span class="gc">&nbsp;</span><span class="gd">',opt.btn.NT,'</span></span></a>');
			}
			str.push('</div>');
		}
		str.push('</div></div>');
		w.top=w.top-$('#alertM').height()/2-200;
		$(str.join('')).appendTo('body').css('top',w.top);
		return opt;
	}
	opt.a=function(){
		$('#alertM').animate({top:w.top+50,opacity:'show'},'fast',opt.b)
	}
	opt.b=function(){
		$('#alertM').show().css('top',w.top+50);;
		$('#alertH').drag('#alertM');
		$('#alertR').click(function(){opt.r().cF()});
		$('#alertY').click(function(){
			if(opt.yF()!=false){
				opt.r();
			}
		});
		$('#alertN').click(function(){
			if(opt.nF()!=false){
				opt.r();
			}
		});
	}
	if($('#alertM').length>0){
		$('#alertM').remove();
		opt.s().b();
	}else{
		opt.h().s().a();
	}
	opt.r=function(){
		$('#alertM').animate({top:w.top+100,opacity:'hide'},'fast',function(){
			$('#hbg').fadeOut(function(){
				$(this).remove();
				opt.rF();
			});
			$(this).remove();
		});
		if(amrt);
		clearTimeout(amrt);
		amrt=false;
		return opt;
	}
	if (!isNaN(opt.time)) {
		if(amrt);
		clearTimeout(amrt);
		amrt=setTimeout(function(){opt.r().cF()}, opt.time);
	}
}
function alertAD(url){
	$.ajax({
		type:'POST',
		url:url,
		dataType:'json',
		timeout:8000,
		success:function(data){
			if(data.success=='1'){
				if($('#alertAD').length>0){
					$('#alertAD').remove();
				}
				$('body').append(data.str);
				var $ad=$('#alertAD');
				$ad.append('<a style="width:43px;height:20px;overflow:hidden;display:block;position:absolute;right:20px;bottom:20px;background:transparent url(http://images.yuedutong.com/images/close.jpg);border:1px #999 solid" href="javascript:void(0)" id="closeAD"></a>').css({left:($(window).scroll(function(){$ad.stop(true,false).animate({top:120+$(window).scrollTop()})}).width()-$ad.width())/2+'px',top:120+$(window).scrollTop()+'px'}).show();
				$('#closeAD').live('click',function(){$ad.remove()});
				setTimeout(function(){$ad.remove()}, data.time)
			}
		}
	})
}
$.fn.panel=function(text,show){
	if($('#panel').length>0)
			$('#panel').remove();
	var $t=$(this);
	var str='<div id="panel" style="width:200px;position:absolute;line-height:24px;padding:0 0 0 5px;"><div style="width:6px;height:10px;background:transparent url(\'http://images.yuedutong.com/images/login/panl.png\');position:absolute;left:0;top:6px;overflow:hidden"></div><div style="background:#fbfbf5;border:1px #ddddcd solid;padding:2px 8px;color:#f00;">'+text+'</div></div>';
	$t.unbind().focus(function(){
		if($('#panel').length>0)
			$('#panel').remove();
		$('body').append(str);
		$('#panel').offset({left:$t.offset().left+$t.width()+25,top:$t.offset().top});
		$(window).resize(function(){
			$('#panel').offset({left:$t.offset().left+$t.width()+25,top:$t.offset().top})
		});
	}).blur(function(){
		$('#panel').remove();
		$(window).unbind('resize');
	});
	if(show){
		if($('#panel').length>0)
			$('#panel').remove();
		$('body').append(str);
		$('#panel').offset({left:$t.offset().left+$t.width()+25,top:$t.offset().top});
		$(window).resize(function(){
			$('#panel').offset({left:$t.offset().left+$t.width()+25,top:$t.offset().top})
		});
	}	
	return $t;
}
function shareTo(m,u){
	switch(m){
	case "renren":
		void ((function(s, d, e) {
		if (/renren\.com/.test(d.location))
		return;
		var f = 'http://share.renren.com/share/buttonshare.do?link=', u =
		d.location, l = d.title, p = [
		e(u), '&title=', e(l) ].join('');
		function a() {
		if (!window.open([ f, p ].join(''),'xnshare',['toolbar=0,status=0,resizable=1,width=626,height=436,left=',(s.width - 626) / 2, ',top=',(s.height - 436) / 2 ].join('')))u.href = [ f, p ].join('');};
		if (/Firefox/.test(navigator.userAgent))
		setTimeout(a, 0);
		else
		a();
		})(screen, document, encodeURIComponent));
	break;
	case "qzone":
		window.open("http://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?url="+ encodeURIComponent(document.location), 'qzone','toolbar=0,status=0,width=900,height=760,left='+ (screen.width - 900) / 2 + ',top='+ (screen.height - 760) / 2);
	break;
	case "kaixin001":
		var kw = window.open('','kaixin001','toolbar=no,titlebar=no,status=no,menubar=no,scrollbars=no,location:no,directories:no,width=570,height=350,left='+ (screen.width - 570)/ 2+ ',top='+ (screen.height - 420) / 2);
		var tempForm = kw.document.createElement('form');
		function openPostWindow(url, data, name) {
			var tempForm = document.createElement('form');
			tempForm.id = 'tempForm1';
			tempForm.method = 'post';
			tempForm.action = url;
			tempForm.target = 'kaixin001';
			var hideInput = document.createElement('input');
			hideInput.type = 'hidden';
			hideInput.name = 'rcontent';
			hideInput.value = data;
			tempForm.appendChild(hideInput);
			document.body.appendChild(tempForm);
			tempForm.submit();
			document.body.removeChild(tempForm);
		}
		function add2Kaixin001() {
			var u = document.location.href;
			var t = document.title;
			var c=''+(document.getSelection?document.getSelection(): document.selection.createRange().text);
			var iframec='';
			var url = 'http://www.kaixin001.com/repaste/bshare.php?rtitle='+encodeURIComponent(t)+'&rurl='+encodeURIComponent(u)+'&from=maxthon';
			var data = encodeURIComponent(c);
			openPostWindow(url, c, '_blank')
		}
		add2Kaixin001();
    break;
    case "tsina":
		void ((function(s, d, e) {
			try {} catch (e) {}
			var f = 'http://v.t.sina.com.cn/share/share.php?', u = d.location.href, p = ['url=', e(u), '&title=', e(d.title), '&appkey=330242870' ].join('');
			function a() {
				if (!window.open([ f, p ].join(''),'mb',['toolbar=0,status=0,resizable=1,width=620,height=450,left=',(s.width - 620) / 2, ',top=',(s.height - 450) / 2 ].join('')))
					u.href = [ f, p ].join('');
			}
			if (/Firefox/.test(navigator.userAgent)) {setTimeout(a, 0)} else {a()}
		})(screen, document, encodeURIComponent));
	break;
	case "feixin":
		window.open('http://space.feixin.10086.cn/api/share?source=悦读通&url='+encodeURIComponent(document.location.href)+'&title='+encodeURIComponent(document.title),'feixin','toolbar=0,status=0,width=1000,height=560,left='+ (screen.width - 1000) / 2 + ',top='+ (screen.height - 600) / 2);
	break;
	case "t139":
		window.open('http://www.139.com/share/share.php?title='+ encodeURIComponent(document.title) + '&url='+ encodeURIComponent(location.href), 't139','width=490,height=340,left=' + (screen.width - 490) / 2+ ',top=' + (screen.height - 340) / 2);
	break;
	case "itieba":
		var sendT = {
		    getContent : function() {
		        var allPageTagss = document.getElementsByTagName("div");
		        for ( var i = 0; i < allPageTagss.length; i++) {
		            if (allPageTagss[i].className == 'articleContent') {
		                return allPageTagss[i].getElementsByTagName("P")[0].innerHTML?allPageTagss[i].getElementsByTagName("P")[0].innerHTML:'';
		            }
		        }
		    }
		}
		var itieba_share = 'http://tieba.baidu.com/i/sys/share?link='+ encodeURIComponent(window.location.href) + '&type='+ encodeURIComponent('text') + '&title='+ encodeURIComponent(document.title.substring(0, 76))+ '&content=' + encodeURIComponent(sendT.getContent());
		if (!window.open(itieba_share, 'itieba','toolbar=0,resizable=1,scrollbars=yes,status=1,width=626,height=436')) {
		    location.href = itieba_share;
		}
	break;
	case "t163":
		(function() {
			var url = 'link=http://www.shareto.com.cn/&source='+ encodeURIComponent('悦读通') + '&info='+ encodeURIComponent(document.title) + ' '+ encodeURIComponent(document.location.href);
			window.open('http://t.163.com/article/user/checkLogin.do?'+ url + '&' + new Date().getTime(),'t163','height=330,width=550,top='+ (screen.height - 280)/ 2+ ',left='+ (screen.width - 550)/ 2+ ', toolbar=no, menubar=no, scrollbars=no,resizable=yes,location=no, status=no');
		})()
	break;
	case "douban":
		 void (function() {
            var d = document, e = encodeURIComponent, s1 = window.getSelection, s2 = d.getSelection, s3 = d.selection, s = s1 ? s1(): s2 ? s2() : s3 ? s3.createRange().text : '', r = 'http://www.douban.com/recommend/?url='+ e(d.location.href)+ '&title='+ e(d.title)+ '&sel='+ e(s) + '&v=1', x = function() {
                if (!window.open(r, 'douban','toolbar=0,resizable=1,scrollbars=yes,status=1,width=450,height=355,left='+ (screen.width - 450) / 2 + ',top='+ (screen.height - 330) / 2))
                    location.href = r + '&r=1'
            };
            if (/Firefox/.test(navigator.userAgent)) {setTimeout(x, 0)} else {x()}
        })();
	break;
	case "tqq":
		window.open('http://v.t.qq.com/share/share.php?title='+encodeURIComponent(document.title)+'&url='+encodeURIComponent(document.location.href), 'tqq','toolbar=0,status=0,width=700,height=360,left='+ (screen.width - 700) / 2 + ',top='+ (screen.height - 600) / 2);
	}
	$.ajax({url:u+'&shareName='+m});
	return false;
}
$.fn.share=function(opt){
	opt = $.extend({
		showIndex:[0,1,2,3,4,5,6,7,8,9],
		margin:'0 auto',
		liMargin:15,
		text:'转贴到：',
		url:'1',
		imgUrl:"http://images.yuedutong.com/images/share.gif",
		share:[{title:'人人网',click:'renren'},{title:'Qzone',click:'qzone'},{title:'开心网',click:'kaixin001'},{title:'新浪微薄',click:'tsina'},{title:'飞信',click:'feixin'},{title:'139说客',click:'t139'},{title:'i贴吧',click:'itieba'},{title:'网易微博',click:'t163'},{title:'豆瓣',click:'douban'},{title:'qq微博',click:'tqq'}]
	}, opt||{});
	var $this = $(this);
	var str=['<li class="floatL" style="line-height:16px">'+opt.text+'</li>'];
	$this.css({listStyle:'none',margin:opt.margin,padding:'0',height:'16',width:(16+opt.liMargin)*(opt.showIndex.length)+50+'px',overflow:'hidden'});
	for(var li=0;li<opt.showIndex.length;li++){
		str.push('<li class="floatL"><a href="javascript:void(0)" style="width: 16px;overflow:hidden; height: 16px; display: block; margin:0 0 0 '+opt.liMargin+'px; padding: 0; background: transparent url(\''+opt.imgUrl+'\') no-repeat 0 -'+16*opt.showIndex[li]+'px" title="分享到'+opt.share[opt.showIndex[li]].title+'" onclick="shareTo(\''+opt.share[opt.showIndex[li]].click+'\',\''+opt.url+'\')"></a></li>');
	}
	$this.html(str.join(""));
	$this.find('a').hover(function(){
			$(this).css('backgroundPositionX','-18px')
		},function(){
			$(this).css('backgroundPositionX','0px')
		}
	);
	return $this;
}
$.fn.pagination = function(maxentries, opts){
	opts = $.extend({
		items_per_page:10,
		num_display_entries:5,
		current_page:0,
		num_edge_entries:1,
		link_to:"#",
		prev_text:"Prev",
		next_text:"Next",
		ellipse_text:"...",
		prev_show_always:false,
		next_show_always:false,
		callback:function(){return false;}
	},opts||{});
	return this.each(function() {
		function numPages() {
			return Math.ceil(maxentries/opts.items_per_page);
		}
		function getInterval()  {
			var ne_half = Math.ceil(opts.num_display_entries/2);
			var np = numPages();
			var upper_limit = np-opts.num_display_entries;
			var start = current_page>ne_half?Math.max(Math.min(current_page-ne_half, upper_limit), 0):0;
			var end = current_page>ne_half?Math.min(current_page+ne_half, np):Math.min(opts.num_display_entries, np);
			return [start,end];
		}
		function pageSelected(page_id, evt){
			current_page = page_id;
			drawLinks();
			var continuePropagation = opts.callback(page_id, panel);
			if (!continuePropagation) {
				if (evt.stopPropagation) {
					evt.stopPropagation();
				}
				else {
					evt.cancelBubble = true;
				}
			}
			return continuePropagation;
		}
		function drawLinks() {
			panel.empty();
			var interval = getInterval();
			var np = numPages();
			var getClickHandler = function(page_id) {
				return function(evt){ return pageSelected(page_id,evt); }
			}
			var appendItem = function(page_id, appendopts){
				page_id = page_id<0?0:(page_id<np?page_id:np-1); // Normalize page id to sane value
				appendopts = jQuery.extend({text:page_id+1, classes:""}, appendopts||{});
				if(page_id == current_page){
					var lnk = jQuery("<span class='red'>"+(appendopts.text)+"</span>");
				}
				else
				{
					var lnk = jQuery("<a href='javascript:void(0)'>"+(appendopts.text)+"</a>")
						.bind("click", getClickHandler(page_id));
						
						
				}
				if(appendopts.classes){lnk.addClass(appendopts.classes);}
				panel.append(lnk);
			}
			if(opts.prev_text && (current_page > 0 || opts.prev_show_always)){
				appendItem(current_page-1,{text:opts.prev_text, classes:"prev"});
			}
			if (interval[0] > 0 && opts.num_edge_entries > 0)
			{
				var end = Math.min(opts.num_edge_entries, interval[0]);
				for(var i=0; i<end; i++) {
					appendItem(i);
				}
				if(opts.num_edge_entries < interval[0] && opts.ellipse_text)
				{
					jQuery("<span>"+opts.ellipse_text+"</span>").appendTo(panel);
				}
			}
			for(var i=interval[0]; i<interval[1]; i++) {
				appendItem(i);
			}
			// Generate ending points
			if (interval[1] < np && opts.num_edge_entries > 0)
			{
				if(np-opts.num_edge_entries > interval[1]&& opts.ellipse_text)
				{
					jQuery("<span>"+opts.ellipse_text+"</span>").appendTo(panel);
				}
				var begin = Math.max(np-opts.num_edge_entries, interval[1]);
				for(var i=begin; i<np; i++) {
					appendItem(i);
				}
				
			}
			// Generate "Next"-Link
			if(opts.next_text && (current_page < np-1 || opts.next_show_always)){
				appendItem(current_page+1,{text:opts.next_text, classes:"next"});
			}
		}
		var current_page = opts.current_page;
		// Create a sane value for maxentries and items_per_page
		maxentries = (!maxentries || maxentries < 0)?1:maxentries;
		opts.items_per_page = (!opts.items_per_page || opts.items_per_page < 0)?1:opts.items_per_page;
		// Store DOM element for easy access from all inner functions
		var panel = jQuery(this);
		// Attach control functions to the DOM element 
		this.selectPage = function(page_id){ pageSelected(page_id);}
		this.prevPage = function(){ 
			if (current_page > 0) {
				pageSelected(current_page - 1);
				return true;
			}
			else {
				return false;
			}
		}
		this.nextPage = function(){ 
			if(current_page < numPages()-1) {
				pageSelected(current_page+1);
				return true;
			}
			else {
				return false;
			}
		}
		drawLinks();
        opts.callback(current_page, this);
	});
}
$.fn.autoPageComments=function(opt){
	opt = $.extend({
		searchCommentsUrl:'1.html',
		pageItems:5,
		prev_text:"上一页",
		next_text:"下一页",
		subCommentsUrl:'2.html',
		kind:'news',
		textAreaID:'contenteTextArea',
		comSizeID:'comSize',
		subCommentID:'subComment',
		pageNationID:'pageNation',
		noNameID:'noName',
		articleID:'1'
	},opt||{});
	var $this=$(this);
	var $pageNation=$('#'+opt.pageNationID).hide();
	var $subComment=$('#'+opt.subCommentID);
	var $textArea=$('#'+opt.textAreaID);
	var $comSize=$('#'+opt.comSizeID);
	var $noName=$('#'+opt.noNameID);	
	var json;
	$this.html('<li>评论加载中，请稍候...</li>');
	var pageCallback=function(page_id){
		var str=[];
		for(var i=0;i<json.length;i++){
			if(i>= 5*page_id&&i< 5*(page_id+1)){
				var j=json[json.length-i-1];
				var img='http://images.diku.com/'+j.imgSrc;
				if(j.name=='******'){
					img='http://images.diku.com/images/3.0/background_personal/0.jpg';
				}
				str.push("<li><img class=\"head\" src=\""+img+"\" onerror=\"this.src='http://images.diku.com/images/3.0/background_personal/0.jpg'\" alt=\"头像\"><span>【"+(i-0+1)+"】"+j.name+" "+j.date+"</span><p>"+j.content+"</p><div class=\"clear\"></div></li>")
			}
		}
		$this.html(str.join(""));
	}
	var page=function(index){
		$pageNation.hide();
		if(index==0){
			$this.html('<li>还没有评论，快来抢沙发！</li>');
		}else if(index<opt.pageItems+1){
			pageCallback(0);
		}else{
			$pageNation.show().empty().pagination(index, {
				prev_text:opt.prev_text,
				next_text:opt.next_text,
				items_per_page: 5,
				callback: pageCallback
			});
			pageCallback(0);
		}
	}
	$.ajax({
		url:opt.searchCommentsUrl,
		dataType:'json',
		timeout:8000,
		cache:false,
		data:{
			id:opt.articleID,
			kind:opt.kind
		},
		success:function(data){
			json=data;
			page(json.length);
		},
		error:function(){
			$this.html('<li>评论加载失败，请检查网络连接是否已断开...<a href="javascript:void(0)" title="重试" class="red">重试</a></li>').find('a').click(function(){
				$this.autoPageComments(opt);
			});
		}
	})
	$textArea.keyup(function(){
		$comSize.html('评论内容不得超过140个字符！当前已输入<span class="red">'+$textArea.text().length+'</span>个字符。');
	})
	$subComment.click(function(){
		if($textArea.text().length>140){
			alertM('评论内容不得超过140个字符！',{title:'错误！'});
			$textArea.focus();
		}else if($textArea.html()==''){
			alertM('评论内容不得为空！',{title:'错误！'});
			$textArea.focus();
		}else if($textArea.text().length<10){
			alertM('评论内容不得低于10个字符！',{title:'错误！'});
			$textArea.focus();
		}else{
			alertM('评论内容提交中,请稍候！',{time:'y',btn:{Y:false}});
			$.ajax({
				type:'POST',
				url:opt.subCommentsUrl,
				dataType:'json',
				timeout:8000,
				data:{
					content:$textArea.html(),
					noname:$noName[0].checked?'1':'0',
					id:opt.articleID,
					kind:opt.kind
				},
				success:function(data){
					if(data.isSuccess=='1'){
						alertM('评论发布成功！',{time:2000,rF:function(){$('html,body').stop(true,false).animate({scrollTop:$this.offset().top-100}, 800);return true;},title:'成功！'});
						json.push(data);
						page(json.length);
						$textArea.empty();
					}else{
						alertM('评论失败！'+data.isSuccess,{title:'错误！'});
					}
				},
				error:function(){
					alertM('评论失败！请检查网络连接是否已断开',{title:'错误！'});
					$('#alertR,#alertY').show();
				}
			})
		}
	})
	return $this;
}
function fncKeyStop(evt){
    if(!window.event)
    {
        var keycode = evt.keyCode; 
        var key = String.fromCharCode(keycode).toLowerCase();
        if(evt.ctrlKey && key == "v")
        {
          evt.preventDefault(); 
          evt.stopPropagation();
        }
    }
}
$.fn.autoTabs=function(opt){
	opt = $.extend({
		title:['月度','季度','年度'],
		tabsName:'ul',
		showIndex:0,
		noCss:false
	},opt||{});
	return $(this).each(function(){
		var $this=$(this);
		var str=[];
		for(var i=0;i<opt.title.length;i++){
			str.push('<span class="ga"><span class="gb"><span class="gc">&nbsp;</span><span class="gd">'+opt.title[opt.title.length-i-1]+'</span></span></span>');
		}
		$this.find('h2').after(str.join(""));
		var $ga=$this.find('span.ga').each(function(){
			$(this).css({width:$(this).find('.gd').width()+8});
		});
		if(opt.noCss){
			$ga.addClass('noga').mouseover(function(){
				$(this).attr('class','gahover ga');
				$ga.not(this).attr('class','noga ga');
				$this.find(opt.tabsName).eq($ga.length-$(this).index()).show().siblings(opt.tabsName).hide();
			}).eq($ga.length-opt.showIndex-1).mouseover();
		}else{
			$ga.mouseover(function(){
				$(this).addClass('gahover').siblings().removeClass('gahover');
				$this.find(opt.tabsName).eq($ga.length-$(this).index()).show().siblings(opt.tabsName).hide();
			}).eq($ga.length-opt.showIndex-1).mouseover();
		}
	})
}
$.fn.autoShare=function(u,i){
	var $this=$(this);
	var idS=Cookie.Get('shared')?Cookie.Get('shared'):'';
	i='/-'+i+'-/';
	if(idS.indexOf(i)>-1){
		$this.css('cursor','default').attr('title','您已分享').find('.gd').html('您已分享').css('cursor','default');
	}else{
		$this.click(function(){
			alertM('正在分享,请稍候')
			$.ajax({
				type:'POST',
				url:u,
				dataType:'json',
				timeout:8000,
				success:function(d){
					alertM(d.msg);
					if(d.msg=='分享成功'){
						$this.css('cursor','default').attr('title','您已分享').unbind().find('.gd').html('您已分享').css('cursor','default');
						idS+=i;
						while(idS.length>2000){
							idS=idS.substring(idS.indexOf('-/')+2)
						}
						Cookie.Set('shared',idS,259200000);
					}
				},
				error:function(){
					alertM('分享失败！请检查网络连接是否已断开',{title:'错误！'});
				}
			})
		})
	}
	return $this;
}
$.fn.listAnimate=function(opt){
	var str={
		imgWidth:0,
		imgHeight:0,
		height:0
	}
	opt=$.extend(str,opt);
	opt.imgWidth+=2;
	$(this).each(function(){
		var $this=$(this).height(opt.height).find('ul');
		var lisAPWidth=$(this).width()-80;
		var length=$this.find('li').length;
		var liIndex=Math.floor(lisAPWidth/(opt.imgWidth));
		var lipr=Math.floor((lisAPWidth-liIndex*(opt.imgWidth))/(liIndex-1));
		var liPage=Math.ceil(length/liIndex);
		var i=0;
		$this.width((opt.imgWidth+lipr)*length).parent().css({height:opt.height,width:lisAPWidth}).find('li').css({paddingRight:lipr,width:opt.imgWidth}).find('img').css({width:opt.imgWidth-2,height:opt.imgHeight});
		$(this).find('a.listAGoL').click(function(){
			i--;
			if(i==-1)
			i=liPage-1;
			$this.stop(true,false).animate({left:i*(-lipr-opt.imgWidth)*liIndex});
		}).css('top',opt.imgHeight/2+16+'px').next().click(function(){
			i++;
			if(i==liPage)
			i=0;
			$this.stop(true,false).animate({left:i*(-lipr-opt.imgWidth)*liIndex});
		}).css('top',opt.imgHeight/2+16+'px');
	})
	return $(this);
}
$.fn.showFace=function(opt){
	var str={
		sub:61,
		imgSrc:'',
		padding:'',
		clickTo:'contenteTextArea'
	}
	opt=$.extend(str,opt);
	var $this=$(this);
	var str=[];
	for(var i=0;i<opt.sub;i++){
		str.push('<li style="float:left;padding:'+opt.padding+'"><img src="http://images.yuedutong.com/images/face/'+i+'.gif" alt="表情" style="width:24px;height:24px;cursor:pointer"></li>');
	}
	$this.html(str.join("")).find('img').click(function(){
		var $img=$(this).clone().css({cursor:'auto'});
		$('#'+opt.clickTo).append($img);
	});
	return $this;
}
function showFen(num){
	$('body').append('<div id="fenShow" style="position:absolute;left:'+($(window).width()/2-90)+'px;top:'+($(window).height()/2-200+$(window).scrollTop())+'px;width:180px;height:150px;"><embed id="swf" width="100" height="150" quality="high" src="http://images.yuedutong.com/images/jinbi.swf" type="application/x-shockwave-flash" wmode="transparent"/><span style="position:absolute;left:90px;top:90px;font-size:32px;font-family:arial">'+num+'</span></div>')
	$('#fenShow').animate({top:$(window).height()/2-90+$(window).scrollTop()},900).fadeOut();
}
$(function(){
	//setTimeout(function(){$('#shareBanner').slideDown('1000').delay('4000').slideUp(600,function(){$('#shareBanner').css({height:'82px',background:'transparent url(http://images.yuedutong.com/images/add/jqtl.jpg) no-repeat 0 0'}).slideDown()})},1000);
	$('#forum').hover(function(){$('#menuSelect').stop(true,false).animate({left:663})},function(){$('#menuSelect').stop(true,false).animate({left:3})})
	$('#mainMenu li:not(:last):not(:first)').hover(function(){$('#menuSelect').stop(true,false).animate({left:$(this).position().left+8})},function(){$('#menuSelect').stop(true,false).animate({left:3})});
	$('#mainNews').html("<img src='http://www35.53kf.com/img/upload/yuedutong/zdytb/on_yuedutong1305772574.gif' border='0' onclick='window.open(\"http://www35.53kf.com/webCompany.php?arg=yuedutong&style=1&kflist=off&kf=&zdkf_type=1&language=cn&charset=gbk&lytype=0&referer=http%3A%2F%2Fimages.yuedutong.com%2Fdefault.html{hz6d_keyword}&tpl=crystal_blue\",\"_blank\",\"height=473,width=703,top=200,left=200,status=yes,toolbar=no,menubar=no,resizable=yes,scrollbars=no,location=no,titlebar=no\")' style='cursor:pointer'/>'").find('img').css({display:'block',margin:'0 0 0 110px'});
	//var oHead = document.getElementById("mainNews"); var oScript = document.createElement("script"); oScript.src = "http://chat.53kf.com/kf.php?arg=yuedutong&style=1"; oHead.appendChild(oScript);
	//changeNews();
})
function recommend(){
	$.ajax({
		url:'/do/recommend/view',
		cache:false,
		dataType:'json',
		timeout:8000,
		success:function(data){
			var r=confirm(data.msg);
			if(r==true){
				location.href='/do/login?from=http://www.yuedutong.com/do/recommend/view'
			}
		},
		error:function(){
			location.href='/do/recommend/view'
		}
	})
}
