/**
hdtv焦点图
*/
var MDChdtvFocus=function(){
	this.id=jQuery(arguments[0].id);
	this.bigImgW=arguments[0].bigImgW;
	this.bigImgH=arguments[0].bigImgH;
	this.smallImgW=arguments[0].smallImgW;
	this.smallImgH=arguments[0].smallImgH;
	this.speed=arguments[0].speed||5000;
	this.focusData=arguments;
	this.autoPlay;
	this.autoPlay2;
};
MDChdtvFocus.prototype={
	init:function(){
		var that=this;
		this.id.addClass("MDChdtvFocus");		
		var	go=function(){					
			that.id.css("backgroundImage","none");					
			var _bigImg=jQuery('<div class="l" style="width:'+that.bigImgW+'px;height:'+that.bigImgH+'px"><img style="display:none;width:100%;height:100%" /><span></span><div class="bg"></div><div style="width:'+that.bigImgW+'px"><h1></h1><p></p></div></div>');
			var _tab=jQuery('<div class="r"><span class="up"></span><span class="down"></span><div><dl></dl></div></div><div class="s"></div>');			
			that.id.html(_bigImg).append(_tab);
			for(var i=1;i<that.focusData.length;i++){				
				that.id.find("> div:eq(1) dl").append('<dd><h2>'+that.focusData[i][5]+'</h2><p>'+that.focusData[i][6]+'</p><img src="'+that.focusData[i][1]+'" width="'+that.smallImgW+'" height="'+that.smallImgH+'" /></dd>');
			};			
			that.a()
		};
		go();
	},
	a:function(){
		var _tab=this.id.find("> div:eq(1)"),that=this;
		var _num=this.id.find(".r dl").height()-360;
		var gogo=function(i){
			that.b(i);
		};
		gogo();
		this.id.find(".r a").click(function(){
			return false;
		});
		this.id.find(".r > .up").mousedown(function(){
			if(that.id.find(".r > div dl").position().top<0){
				if(!that.id.find(".r > div dl").is(":animated")){
					that.id.find(".r > div dl").stop().animate({top:"+=90"},200);
				}
			}
		});
		this.id.find(".r > .down").mousedown(function(){
			if(that.id.find(".r > div dl").position().top>-_num){
				if(!that.id.find(".r > div dl").is(":animated")){
					that.id.find(".r > div dl").stop().animate({top:"-=90"},200);
				}
			}	
		});
		this.id.find(".l").hover(function(){
			that.id.find(".l span").addClass("now");
		},function(){
			that.id.find(".l span").removeClass("now");
		}).click(function(){
			
		});
		_tab.find("dd").each(function(i){
			(function(i){
				_tab.find("dd").eq(i).bind("mouseenter",function(){
					if(jQuery(this)[0].className!="now"){
						clearTimeout(that.autoPlay);
						clearTimeout(that.autoPlay2);	
						gogo(i+1);
						clearTimeout(that.autoPlay);
						clearTimeout(that.autoPlay2);
					}else{
						clearTimeout(that.autoPlay);
						clearTimeout(that.autoPlay2);
					}
				}).bind("mouseleave",function(){
					clearTimeout(that.autoPlay);					
					that.autoPlay2=setTimeout(function(){
						var s=i+2;
						s>that.focusData.length-1?s=1:s;
						gogo(s);
					},that.speed);
				}).click(function(){
					
				});
			})(i)
		})
	},
	b:function(i){
		var _index=i||1,that=this;
		this.id.find("img:eq(0)").attr("src",that.focusData[_index][0]).parent().attr("href",that.focusData[_index][2]).end().css({"display":"block"});
		this.id.find("dd").removeClass("now").eq(_index-1).addClass("now");
		this.id.find(".l > div > h1").html(that.focusData[_index][3]);
		this.id.find(".l > div > p").html(that.focusData[_index][4]);
		var _w=this.id.find(".l > div:eq(1)").width();
		this.id.find(".l > div:eq(0)").css("width",0).stop().animate({width:_w},200);
		var _num1=this.id.find(".r dl dd.now").prevAll().length*90;
		var _num2=this.id.find(".r dl").height()-360;
		var _num3=_num1-270;
		if(!that.id.find(".r > div dl").is(":animated")){
			if(that.id.find(".r > div dl").position().top > -(_num1-270)){
				that.id.find(".r > div dl").stop().animate({top:-_num3},200);
			};
			if(that.id.find(".r > div dl").position().top < (-_num1)){				
				that.id.find(".r > div dl").stop().animate({top:-_num1},200);
			}
		}
		if(that.id.find(".r > div dd").eq(0)[0].className=="now"){			
			if(!that.id.find(".r > div dl").is(":animated")){				
				that.id.find(".r > div dl").stop().animate({top:0},200);
			}
		};
		this.autoPlay=setTimeout(function(){
			that.b(_index==that.focusData.length-1?_index=1:++_index);
		},that.speed);
	}
}
