//script for bbs.cctv.com
//author: qinming 09-10-26

//由右到左文字滚动
function Mod24hRoller(_fontId){
	this.emId   	= _fontId + "_rock";
	this.btmId   	= _fontId + "_btms";
	var
		  obj		= jQuery("#" + this.emId),
		  objBtm	= jQuery("#" + this.btmId),
		  btmPlay	= objBtm.find(".play"),
		  btmPause  = objBtm.find(".pause"),
		  objW		= obj.width(),
		  timerid	= -1;

	this.inits		= function(){
		try{

			for(var a=0;a<3;a++){
				obj.append("　<li>"+jQuery(obj.find("li")[a]).html()+"</li>");
			}
			btmPlay.bind("click",function(){funPlay()});
			btmPause.bind("click",function(){funPause()});

			obj.find("li a").bind("mouseover",function(){funPause()}).bind("mouseout",function(){funPlay()});
			funPlay();
		}catch(ex){}
	}

	function funPlay(){
		clearInterval(timerid);
		timerid = setInterval(moveli,70);
	}
	function moveli(){
		var t= obj.css("left");
		t = parseInt(t)-1;
		if(t<=-objW) t =0;
		obj.css("left",t+"px")
	}
	function funPause(){
		clearInterval(timerid);
	}
}


//网站导航模块
var MapNav = function(){
	this.curIndex = 1;
	this.lastIndex = 0;
	this.navbtns = $('.mapLeft ul li');
	this.c = $('.mapRight div');
}

MapNav.prototype = {
	init: function(){
		_this = this;
		this.navbtns.each(function(){
			$(this).bind("click", function(){
				var n = $(this).attr("mapnid");
				_this.curIndex = n;
				_this.clearClass();
				_this.show();
				return false;
			});

			$(this).mouseover(function(){
				if($(this).attr("mapnid") != _this.curIndex){
					$(this).addClass("cc");
				}
			});

			$(this).mouseout(function(){
				if($(this).attr("mapnid") != _this.curIndex){
					$(this).removeClass("cc");
				}
			});
		});

		if(this.lastIndex == 0){
			this.lastIndex = 1;
			this.curIndex = 1;
			this.show();
		}
	},

	clearClass: function(index){
		this.navbtns.each(function(){
			$(this).removeClass("cc");
		});
		this.c.each(function(){
			$(this).hide();
		});
	},

	show: function(){
		$('.mapLeft ul').find('li[mapnid='+this.curIndex+']').addClass("cc");
		$('#mapcid_' + this.curIndex).show();
	}
}


var $picshow = function(){
	this.list = [];
	this.max = 0;//picshowlist.length;
	this.curIndex = 0;
	this.btnPrevId = "#sliderPrev";
	this.btnNextId = "#sliderNext";
	this.displayN = 4; //显示图片数
	this.UL = $(".c2list2 ul");
}

$picshow.prototype = {
	init: function(){
		var othis = this;
		this.initdata();
		$(this.btnPrevId).bind("click", function(){
			othis.prev();
			return false;
		});
		$(this.btnNextId).bind("click", function(){
			othis.next();
			return false;
		});
		this.display();
	},

	initdata: function(){
		var othis = this;
		jQuery.each($(".c2list2 ul li"), function(){
			var item = new Object;
			item.title = $(this).find("h3 a").text();
			item.link = $(this).find("a").attr("href");
			item.src = $(this).find("img").attr("src");
			othis.list.push(item);
		});
		this.max = this.list.length;
	},

	next: function(){
		this.curIndex++;
		this.display();
	},

	prev: function(){
		if(this.curIndex == 0)
			this.curIndex += 10 * this.displayN;
		this.curIndex--;
		this.display();
	},

	display: function(){
		$(".c2list2 ul").empty();
		var data = this.getData();
		for(var i = 0; i < this.displayN; i++){
			try{
				$(".c2list2 ul").append("<li><p><a href=\""+data[i].link+"\" target=\"_blank\"><img src=\""+data[i].src+"\"></a></p><h3><a href=\""+data[i].link+"\" target=\"_blank\">"+data[i].title+"</a></h3></li>");
			}catch(e){
				//alert(i);
			}
		}
	},

	getData: function(){
		var tdata = new Array();
		for(var i = 0; i < this.displayN; i++){
			tdata.push(this.list[( this.curIndex + i ) % this.max]);
		}
		return tdata;
	}
}
