(function(doc,math){

	var	IS_DOM3=(typeof(addEventListener)==="function")?true : false,
			FROM_ROLLOVER="_off",
			TO_ROLLOVER="_on",
			event_hash={};
	
	var	Event={},
			EventCache=[];
	
	if(IS_DOM3===false){
		Event.observe=function(e,t,f){
			var fn=function(){
				f.call(e,window.event)
			}
			if(t!=="unload"){
				EventCache.push({context:e,type:t,fn:fn})
			}
			e.attachEvent("on"+t,fn);
		}
		Event.detach=function(n,t,f){
			n.detachEvent("on"+t,f)
		}
	}else{
		Event.observe=function(e,t,f){
			if(t!=="unload"){
				EventCache.push({context:e,type:t,fn:f})
			}
			e.addEventListener(t,f,false);
		}
		Event.detach=function(n,t,f){
			n.removeEventListener(t,f,false)
		}
	}
	Event.runTimeCache=event_hash;
	var run=function(img){
		var	fn_on=function(){
					this.src=this.src.replace(FROM_ROLLOVER,TO_ROLLOVER)
				},
				fn_off=function(){
					this.src=this.src.replace(TO_ROLLOVER,FROM_ROLLOVER)
				}
		for(var i=0,len=img.length;i<len;i++){
			if(img[i].src.indexOf(FROM_ROLLOVER)>-1){
				var	nimg=new Image(),
						tmp=new Date();
				tmp=tmp.getTime();
				tmp=math.round(tmp*math.random()).toString(32);
				
				nimg.src=img[i].src;
				img[i].baseEvent=tmp;
				event_hash[tmp]={on:fn_on,off:fn_off};
				Event.observe(img[i],"mouseover",fn_on);
				Event.observe(img[i],"mouseout",fn_off);
			}
		}
		img=null;
	}
	Event.observe(this,"load",function(){
		Event.observe(this,"unload",function(){
			for(var i=0,len=EventCache.length;i<len;i++){
				Event.detach(EventCache[i].context,EventCache[i].type,EventCache[i].fn)
				EventCache[i].context=null;
				EventCache[i]=null;
			}
			Event.runTimeCache=null;
		})
	
		run(document.getElementsByTagName("img"));
		run(document.getElementsByTagName("input"));
	})
	this.baseEvent=Event;
}).call(window,document,Math)
