var MDCyuleFocus=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;
};
MDCyuleFocus.prototype={
	init:function(){
		var that=this;
		var _imgLoad=new Image();
		this.id.css({"width":that.bigImgW+"px","height":that.bigImgH+"px","position":"relative","overflow":"hidden","background":"url(images/loading.gif) 50% 50%"});
		_imgLoad.onload=function(){
			that.id.css("background","none");
			var _bigImg=jQuery('<a target="_blank"><img  border="0" style="display:none;width:100%;height:100%" /></a>'),_tab=jQuery('<div style="height:'+that.smallImgH+'px;position:absolute;bottom:-'+that.smallImgH+'px;left:0;background:#000"></div>');			
			that.id.html(_bigImg).append(_tab);
			for(var i=1;i<that.focusData.length;i++){
				that.id.find("div").append('<span style="width:'+that.smallImgW+'px;height:100%;float:left;margin:0 1px;display:inline;cursor:pointer"><img width="100%" height="100%"  border="0" style="display:block" src="'+that.focusData[i][0]+'" /></span>').find("span").css("opacity",.5);
			};
			that.a()
		};
		_imgLoad.src=this.focusData[1][0];
	},
	a:function(){
		var _tab=this.id.find("div"),that=this;
		var gogo=function(i){
			that.b(i);
		};
		gogo();
		this.id.hover(function(){
			_tab.stop();
			if(!_tab.is(":animated")){
				_tab.animate({bottom:0},300);
			}
		},function(){
			_tab.stop();
			if(!_tab.is(":animated")){
				_tab.animate({"bottom":-that.smallImgH},300);
			}
		});		
		_tab.find("span").each(function(i){						
			(function(i){
				_tab.find("span").eq(i).click(function(){
					clearTimeout(that.autoPlay);						
					gogo(i+1);
				})
			})(i)				
		})
	},
	b:function(i){
		var _index=i||1;
		var that=this;
		this.id.find("img:eq(0)").attr("src",this.focusData[_index][0]).parent().attr("href",this.focusData[_index][1]).end().css({"display":"block","opacity":0}).stop().animate({opacity:1},1000);
		this.id.find("div span.now").stop().animate({opacity:.5},200).removeClass();
		this.id.find("div span").eq(_index-1).stop().animate({opacity:1},200).addClass("now");			
		this.autoPlay=setTimeout(function(){
			that.b(_index==that.focusData.length-1?_index=1:++_index);
		},that.speed);
	}
}
