var $ = function (){
  var ele,Str;
  if(arguments.length<2){
	  if(typeof arguments[0] != 'string'){
		  ele = arguments[0];
		  ele.$ADD = function (fn){CLS.add(this,fn)};
		  return $.fn.call(ele);
	  }
	  Str = arguments[0];
	  ele = document;
  }else{
	  if(typeof arguments[0] != 'string')ele = arguments[0];
	  else ele = $(arguments[0]);
	  Str = arguments[1] ;
  }
  Str=Str.replace(/\s+/g," ").split(" ");
  for(i=0;i<Str.length;i++){
	  ele = G(Str[i]);
  }
    function G(str){
         if(str.indexOf('#')!=-1){return document.getElementById(str.split("#")[1])}
         if(str.indexOf('.')!=-1){
	         if(ele.length)return ele;
			 str = str.split(".");
			 var tagname = str[0]==""?'*':str[0];
			 str1 = str[1].split(":");
             var elems =ele.getElementsByTagName(tagname);
             var elemList=[],_n = 0;
			 str1[1] = str1[1].toUpperCase();
               for(var i=0,j;j=elems[i];i++){
                     var att=j["className"]||j.getAttribute("class");
	                 if (att==str1[0]){
						 if(str1[1]!=""){
							 if(str1[1]=="FIRST")return j;
							 else if(parseInt(str1[1])==_n)return j;
						 }
						 elemList.push(j);
						 _n++;
					 }
               }
			  if(str1[1]=="LAST")return j;
			  else if (str1[1]!="")return null;
	          return elemList;
          }
       if(str.indexOf(':')!=-1){
		   if(ele == document)ele = document.body;
		   str = str.split(":");
		   eles = str[0]==""?ele.childNodes:ele.getElementsByTagName(str[0]);
		   var i=0,endi = str[1].toUpperCase(),lastEle;
		   if(endi=='*')var allEle = [];
		   for(var n=0,__ele;__ele=eles[n];n++){
			   if(__ele.nodeType != 3 ){
				   if(endi=='FIRST')return __ele;
				   else if(i==parseInt(endi))return __ele;
				   lastEle = __ele;
				   if(endi=='*')allEle.push(__ele);
				   i++;
			   }
			   __ele = __ele.nextSibling;
		   }
		   if(endi=='LAST')return lastEle;
		   if(endi=='*')return allEle;
		   return null;
	   }
		    return ele.getElementsByTagName(str);
      }
	return $.fn.call(ele);
};
$.fn = function (){
	this.$ADD = function (fn){CLS.add(this,fn)};
	this.addEvent = function (sEventType,fnHandler){
		if (this.addEventListener) {this.addEventListener(sEventType, fnHandler, false);} 
	    else if (this.attachEvent) {this.attachEvent("on" + sEventType, fnHandler);} 
	    else {this["on" + sEventType] = fnHandler;}
	}
	this.removeEvent = function (sEventType,fnHandler){
		if (this.removeEventListener) {this.removeEventListener(sEventType, fnHandler, false);} 
	    else if (this.detachEvent) {this.detachEvent("on" + sEventType, fnHandler);} 
	    else { this["on" + sEventType] = null;}
	}
	return this;
}
var isIE = (document.all) ? true : false;
var Bind = function (obj,fun,arr){return function() {return fun.apply(obj,arr);}};
var CLS={//¶¨Òåcls
   create: function() {
	  return function() {
		this.$ADD = function (fn){CLS.add(this,fn)};
	    this.init.apply(this, arguments);
	  }
   },
   add:function (obj,fn){
	   fn.apply(obj,arguments);
   },
   enterFrame:function (){
	    this.onEnterFrame=function (){};
		this.$PLAY = function (g){
			this.enterFrameP = this.enterFrameP || 10;
			this.CLStimeIndex = CLS.ontimes.length;
			CLS.ontimes.push(this);
			window.clearTimeout(this.enterFrameTimeout);
			window.clearInterval(this.enterFrameInterval);
			if(g)this.enterFrameTimeout = window.setTimeout('CLS.ontimes['+this.CLStimeIndex+'].enterFrameInterval=window.setInterval("CLS.ontimes['+this.CLStimeIndex+'].onEnterFrame()",'+this.enterFrameP+')',parseInt(g*500));
			else this.enterFrameInterval = window.setInterval("CLS.ontimes["+this.CLStimeIndex+"].onEnterFrame()",this.enterFrameP);
		}
		this.$STOP = function (){
			window.clearInterval(this.enterFrameInterval);
		}
		this.$SET = function (p){
			this.enterFrameP = p;
		}
   },
   alpha:function(){
	   if(!this.$PLAY)CLS.add(this,CLS.enterFrame);
	   this.$I = 0;
	   this.$SHOW = function (p){
		   if(isIE){
			   if(this.style.filter==""){this.$I = 0;}
			   else{
			      var Match = /(\d+)/.exec(this.style.filter);
				  this.$I = parseInt(Match[1]);
			   }
		   }else{
			   this.$I = this.style.opacity==""?0:this.style.opacity*100;
		   }
		   this.$SPEED = p || 1;
		   this.onEnterFrame = this.sfn;
		   this.$PLAY();
	   };
	   this.$HIDE = function (p){
		   if(isIE){
			   if(this.style.filter==""){this.$I = 100;}
			   else{
			      var Match = /(\d+)/.exec(this.style.filter);
				  this.$I = parseInt(Match[1]);
			   }
		   }else{
			   this.$I = this.style.opacity==""?100:this.style.opacity*100;
		   }
		   this.$SPEED = p || 5;
		   this.onEnterFrame = this.hfn;
		   this.$PLAY();
	   }
	   this.sfn = function (){
		   this.$I += this.$SPEED;
		   if(this.$I>=100){
			   this.$STOP();
			   if(isIE)this.style.filter="Alpha(Opacity=100)";
	           else this.style.opacity = 1; 
			   
		   }
		  if(isIE)this.style.filter="Alpha(Opacity="+this.$I+")";
	      else this.style.opacity = this.$I/100; 
	   };
	   this.hfn = function (){
		   this.$I -= this.$SPEED;
		   if(this.$I<=0){
			   this.$STOP();
			   if(isIE)this.style.filter="Alpha(Opacity=0)";
	           else this.style.opacity = 0; 
		   }
		  if(isIE)this.style.filter="Alpha(Opacity="+this.$I+")";
	      else this.style.opacity = this.$I/100; 
	   }
   },
   ontimes:new Array()
};
CLS.ImgFlash = CLS.create();
CLS.ImgFlash.prototype = {
	init:function (box,ge){
		this.box = $(box,'dl');
		this.ge = ge;
		this.menu = [];
		this.zIndex = this.box.length;
		var _div = document.createElement('div');
		this.dang = 0;
		for(i=0;i<this.zIndex;i++){
			this.box[i].style.zIndex = this.zIndex-i;
			var _em = $(document.createElement('em')),_span = document.createElement('span');
			var _dt = this.box[i].getElementsByTagName("dt")[0];
			_dt.appendChild(_span);
			//_em = _em;
			_em.addEvent('mouseover',Bind(this,this.emEvent,[this.zIndex-i-1,true]));
			_div.appendChild(_em);
			this.menu.push(_em);
			if(this.zIndex-i==1){
				_em.className = 'd';
			}
		}
		box = $(box);
		box.appendChild(_div);
		box.addEvent('mouseover',Bind(this,function(){this.$STOP()},[]));
		box.addEvent('mouseout',Bind(this,function(){this.$PLAY()},[]));
		this.$ADD(CLS.enterFrame);
		this.$SET(this.ge*1000);
		this.onEnterFrame = function (){
			var ddd = this.dang==3?0:this.dang+1;
			this.emEvent(ddd);	
		}
		this.$PLAY();
	},
	emEvent:function (index,b){
		if(b)this.$STOP();
		if(index == this.dang)return;
		this.menu[this.menu.length-1-this.dang].className="";
		var odl = this.box[this.dang];
		this.zIndex++;
		this.dang = index;
		this.menu[this.menu.length-1-this.dang].className="d";
		var ndl = this.box[this.dang];
		var img = $(ndl,'img:first')
		ndl.style.zIndex = this.zIndex;
		if(isIE)img.style.filter="Alpha(Opacity=0)";
	    else img.style.opacity = 0; 
		img.$ADD(CLS.alpha);
		img.$SHOW();
	}
}
$(window).addEvent('load',function (){
    
});