﻿$.fn.extend({     
   TrunAd2:function(options){
	var auto=null;
	var obj=$(this);
	count=$("a",obj).size();
	n=0;
	var settings={timer:5000,menu:"#play_text"};
	options = options || {};
        $.extend(settings, options);
	var ulcontent="<ul>";
	for(i=1;i<=count;i++){ulcontent=ulcontent+"<li>"+i+"</li>";}
	ulcontent=ulcontent+"</ul>";
	$(settings.menu).html(ulcontent);
    	$("a:not(:first-child)",this).hide();
	$(settings.menu+" li").eq(0).css({"background":"#5677ab","color":"#fff","font-weight":"normal"});
$(settings.menu+" li").mouseover(function() {
	i = $(this).text()-1;
	n=i;
	if (n >= count) return;
	$("a",obj).filter(":visible").fadeOut(200,function(){$(this).parent().children().eq(n).fadeIn(300);});
	$(this).css({"background":"#5677ab","color":"#fff","font-weight":"normal"}).siblings().css({"background":"#fff","color":"#5677ab","font-weight":"normal"});
	});
	auto = setInterval(showAuto, settings.timer);
	obj.hover(function(){clearInterval(auto)}, function(){auto = setInterval(showAuto, settings.timer);});
	function showAuto()
	{
		 n = n >= (count - 1) ? 0 : ++n;
		$(settings.menu+" li").eq(n).trigger('mouseover');
	}
}
});


//初始化
$(document).ready(function(){
	//播放速度
	var speed = 2000;
	//控制范围，符合jQuery路径即可
	var block = '#latestMsg li';
	//需要显示的内容条目数
	var eq = 5;
	var h = 0;
	if($(block).length > eq){//如果内容数目大于需要滚动的数目，开始滚动！
		//隐藏除了第一个的其它所有节点
		$(block).slice(eq).css('display','none');
		//播放开始
		h = setInterval('scrollContent("'+block+'",'+eq+',2)',speed);
		$('#siteBulletin').mouseout(function(){
			h = setInterval('scrollContent("'+block+'",'+eq+',2)',speed);
		});
		$('#siteBulletin').mouseover(function(){
			clearInterval(h);
		});
	}
	
})

//*********************************************************************************\
//	JS翻滚内容函数
//	基于jQuery内核开发，必须引入jQuery
//	初始化必须执行
//	block 制定控制对象
//	eq	页面显示数目
//	type 效果类型：1 - 为滑动，2 - 为渐变，3 - 滑动加渐变
//**********************************************************************************/
function scrollContent(block,eq,type){
		//获取第节点
	    var firstNode = $(block);
	    //动画效果
	    switch(type){
	    	case 1:
	    		animation_out = {height:'hide'};
	    		animation_in = {height:'show'};
	    		break;
	    	case 2:
	    		animation_out = {opacity:'hide'};
	    		animation_in = {opacity:'show'};
	    		break;
	    	case 3:
	    		animation_out = {height:'hide',opacity:'hide'};
	    		animation_in = {height:'show',opacity:'show'};
	    		break;
	    	default:'';
	    }
	    //开始动画
	    firstNode.eq(0).animate(animation_out,1000,function(){//隐藏
	    	//克隆.追加到最后.隐藏
	        $(this).clone().appendTo($(this).parent()).css('display','none');
	        //显示第二个节点内容
	    	firstNode.eq(eq).removeAttr('style').animate(animation_in,1000);
	    	//删除第一个节点内容
	        $(this).remove();
	    });
}
