(function($){
$.fn.extend({
	tabonflash:function(opt,callback){
		if(!opt) var opt={};
		var _this=this;
		var intervalProcess;
		var playstate=1;
		opt.total = $('li',this).size();
		function rplks(str,keywords,newkey) {
			var patt=new RegExp(eval("/"+keywords+"/g"));
			//var patt=new RegExp(keywords,'g');
			if(patt.exec(str)!= null){
				var str=str.replace(patt,newkey);
			}
			return str;
			alert(str);
		}
		function toint(str){
			if(str=='auto'){
				str=0;
			}else{
				str=parseInt(str);
			}
			return str;
		}
		function curh(obj){
			for(i=1;i<=opt.total;i++){
				var domel=document.getElementById(opt.tabname+i);
					$(domel).removeClass(opt.hoverclass);
			}
			$(obj).addClass(opt.hoverclass);
		}
		function statutepage(str){
			
			// curh(document.getElementById(opt.tabname+str));
			for (i=1;i<=opt.total;i++){
				if(i!=str){
					$(document.getElementById(opt.tabpagename+i)).hide();
				}
			}
			var tpobj=$(document.getElementById(opt.tabpagename+str));
			var wh = tpobj.width();
			tpobj.show();
			tpobj.width(wh);

			playstate=str;
		}
		for (i=1;i<=opt.total;i++){
				var curobj=document.getElementById(opt.tabpagename+i).getElementsByTagName('img')[0];
				curobj.onmouseover=function(e) {
					clearInterval(intervalProcess);
				}
				curobj.onmouseout=function(e) {
					intervalProcess = setInterval(checkplaystate, 3000);
				}
			}
		function checkplaystate(){
			statutepage(playstate);
			if(playstate<opt.total){
				playstate++;
			}else{
				playstate=1;
			}
		}
		function pre(){
			statutepage(playstate);
			if(playstate>1){
				playstate--;
			}else{
				playstate=opt.total;
			}
		}
		function autoplay(str){
			if(str=="play"){
				intervalProcess = setInterval(checkplaystate, 3000);
			}else{
				clearInterval(intervalProcess);
			}
		}
		for (i=1;i<=opt.total;i++){
			$(document.getElementById(opt.tabpagename+i))
				.css({'overflow':'hidden','display':'block','width':'69px','height':'50px','background':'#fff'})
				var curobj1=document.getElementById(opt.tabpagename+i).getElementsByTagName('img')[0];
				if(curobj1){
					intervalProcess = setInterval(checkplaystate, 3000);
					//alert(opt.total);
					}
					statutepage(playstate);
				   // curobj1.onmouseover=function(e) {
					//intervalProcess = setInterval(checkplaystate, 4000);
				//}
				// curobj1.onmouseout=function(e) {
					//intervalProcess = setInterval(checkplaystate, 4000);
				//}
		}
		if(opt.playbtn&&opt.playbtn.length>0){
			$(opt.playbtn).click(function (){
			 	autoplay("play");
				return false;
			});
		};
		if(opt.stopbtn&&opt.stopbtn.length>0){
			$(opt.stopbtn).click(function (){
			 	autoplay("stop");
				return false;
			});
		};
		if(opt.nextbtn&&opt.nextbtn.length>0){
			$(opt.nextbtn).click(function (){
			 	checkplaystate();
				return false;
			});
		};
		if(opt.prebtn&&opt.prebtn.length>0){
			$(opt.prebtn).click(function (){
			 	pre();
				return false;
			});
		};
		if(opt.prebtn&&opt.prebtn.length>0){
			autoplay(opt.play);
		};
		$('.tabflclose').click(function (){
			statutepage(0);
			$(this).hide();
		});
		$('#maintabnote').click(function(e){
			$(this).fadeOut("fast");
		});
		//statutepage(playstate);
		statutepage(1);
		//this.hover(function (){},function (){statutepage(0);$('#tabflclose').hide();});
	}
})
})(jQuery);
