var jsef = {};
jsef.o = new Array();
jsef.t = new Object();
jsef.rm = function(o){
	if( o.id ){
		id = o.id;
		jsef.o[id] = null;
	}
	o.parentNode.removeChild(o);
};

jsef.addEvent = function (id, evType, fn){
	
	if( typeof( id ) == 'object'){
		obj = id;
	}else{
		obj = document.getElementById( id );
		if( !obj ){
			return false;
		}
	}
		
 	if (obj.addEventListener){
    		obj.addEventListener(evType, fn, true);
    		return true;
 	} else if (obj.attachEvent){
    		var r = obj.attachEvent("on"+evType, fn);
    		return r;
 	} else {
    		return false;
 	}
}

jsef.cr = function(tg){
	return document.createElement(tg);
}
jsef.get = function(id){
	return document.getElementById(id);
}

jsef.fixE = function( e ){
	if (typeof e == 'undefined') e = window.event;
	if (typeof e.layerX == 'undefined') e.layerX = e.offsetX;
	if (typeof e.layerY == 'undefined') e.layerY = e.offsetY;
	return e;
}

jsef.check = function( o ){
	if( typeof(o) != 'object' ){
		return false;
	}
	if( !o.id ){
		o.id = (Math.round(Math.random()*(999-1)))+1;
	}
	if( !o.style ){
		o.style = new Object();
	}
	if( !o.style ){
		o.style = new Object();
	}
	
	id = o.id;
	if( jsef.o[id] ){
		return true;
	}
	jsef.o[id] = o;
	
	if( !o.style.height ){
		o.style.height = o.offsetHeight+'px';
	}
	if( !o.style.width ){
		o.style.width = o.offsetWidth+'px';
	}
	
	o.oW = parseInt(o.style.width);
	o.oH = parseInt(o.style.height);
	
	o.getW = function(){
		return parseInt( this.style.width );
	}
	o.getH = function(){
		return parseInt( this.style.height );
	}
	
	o.setOpac = function( opac ){
		
		if( opac < 0 ){
			return false;
		}
		if( opac > 100 ){
			return false;
		}
		
		opac = parseInt( opac );
		try{
			if( document.all ){
				this.style.filter = "alpha(opacity="+opac+")"
			}else{
				this.style.opacity = opac/100;
			}	

		}catch(e){
			
			if( opac < 5 ){
				this.style.visibility = 'hidden';
			}else{
				this.style.visibility = 'visible';
			}
		}

	}
	
	o.getOpac = function(){
		if( document.all ){
			try{
				if( typeof(this.filters) == 'undefined'){
					this.setOpac(100);
				}else if( typeof(this.filters.alpha) == 'undefined'){
					this.setOpac(100);
				}else if( typeof(this.filters.alpha.opacity) == 'undefined'){
					this.setOpac(100);
				}
				return this.filters.alpha.opacity;
			}catch(e){
				return 100;
			}
		}

		try{
			if( !this.style.opacity ){
				o.setOpac(100);
			}
			op = this.style.opacity;
			return (op*100);
		}catch(e){
				return 100;
		}
		
	}
	
	if( !o.getOpac() ){
		o.setOpac(100);
	}
	if( !o.onComplete ){
		o.onComplete = function(){};
	}
	return true;
};

jsef.setProp = function(o, att, v){
	if( att == 'opacity' ){
		o.setOpac(v);
	}else{
		try{
			o.style[att] = v+'px';
		}catch(e){
		}
	}
};

jsef.getProp = function(o, p){
	if( p == 'left' ||   p == 'top'){
		jsef.relativise(o, p);
	}
	if( p == 'opacity' ){
		return o.getOpac();
	}
	return parseInt(o.style[p]);
};

jsef.anim = function(){
};
jsef._set = function( id, att, v) {
	var o = jsef.o[id];
	if( !o ){
		return;
	}
	jsef.relativise(o, att);
	theMx = 0;
	theMx = theMx + v;
	jsef.setProp(o, att, v);
};

jsef._chng = function( id, att, v) {
	var o = jsef.o[id];
	if( !o ){
		return;
	}
	
	jsef.relativise(o, att);
	
	if( att == 'opacity' ){
		theMx = o.getOpac();
	}else{
		theMx = parseInt( o.style[att] );
	}
	
	theMx = theMx + v;	
	
	jsef.setProp(o, att, theMx);
};

jsef.inc = function( obj, att, v) {
	if( jsef.check( obj ) == false ){
		return false;
	}
	jsef._chng( obj.id, att, +v);
};
jsef.dec = function( obj, att, v) {
	if( jsef.check( obj ) == false ){
		return false;
	}
	jsef._chng( obj.id, att, -v);
};


jsef.anim._inc = function( id, att, mx, du, sp) {
		var du = du || 1;
		var sp = sp || 3;
		var o = jsef.o[id];
		if( !o ){
			return;
		}
		
		if( att == 'opacity' ){
			theMx = o.getOpac();
		}else{
			theMx = parseInt( o.style[att] );
		}

		if( (theMx+sp) >= mx ){
			sp = 1;
		}
		theMx = theMx+sp;
		if( theMx >= mx ){
			jsef.uncheck(o);
			o.onComplete();
			
			if( jsef.t[id] ){
				clearTimeout( jsef.t[id] );
			}
			return false;
		}
		
		jsef.setProp(o, att, theMx);
		
		jsef.t[id] = setTimeout("jsef.anim._inc('"+id+"', '"+att+"',"+mx+","+du+","+sp+")", du);
};

jsef.relativise = function(o, att){
	
	if( att !== 'top' &&  att !== 'left' ){
		return false;
	}
	
	if( !o.style.top ){
		o.style.top = o.offsetTop+'px';
	}
	
	if( !o.style.left ){
		o.style.left = o.offsetLeft+'px';
	}
	if( !o.style.position ){
		o.origPosition = o.style.position;
		o.style.position = 'absolute';
	}
};
jsef.uncheck = function(o){
	if( o.origPosition ){
		o.style.position = o.origPosition;
	}
};

jsef.anim._dec = function( id, att, mx, du, sp) {
		var du = du || 2;
		var sp = sp || 3;
		var o = jsef.o[id];
		if( !o ){
			return;
		}
		
		if( att == 'opacity' ){
			theMx = o.getOpac();
		}else{
			theMx = parseInt( o.style[att] );
		}
		if( theMx <= mx ){
			o.onComplete();
			jsef.uncheck(o);
			if( jsef.t[id]  ){
				clearTimeout(jsef.t[id] );
			}
			return false;
		}
		
		if( (theMx-sp) <= mx ){
			sp = 1;
		}
		
		theMx = theMx-sp;
		window.status = sp;
		jsef.setProp(o, att, theMx);
		jsef.t[id]  = setTimeout("jsef.anim._dec('"+id+"', '"+att+"',"+mx+","+du+","+sp+")", du);
		
};


jsef.toggleH = function( obj ){
	if( jsef.check( obj ) == false ){
		return false;
	}
	id = obj.id;
	if( obj.getH() == 0 ){
		mx = obj.oH;
		jsef.anim._inc(id,'height', mx, 1, 5);
	}else{
		mx = 0;
		jsef.anim._dec(id,'height', mx, 1, 5);
	}
};

jsef.toggleW = function( obj ){
	if( jsef.check( obj ) == false ){
		return false;
	}
	id = obj.id;
	if( obj.getW() == 0 ){
		mx = obj.oW;
		jsef.anim._inc(id,'width', mx, 1, 6);
	}else{
		mx = 0;
		jsef.anim._dec(id,'width', mx, 1, 6);
	}
};

jsef.toggleOpacity = function( obj ){
	if( jsef.check( obj ) == false ){
		return false;
	}
	id = obj.id;
	if( obj.getOpac() == 0 ){
		mx = 100;
		jsef.anim._inc(id,'opacity', mx, 1, 3);
	}else{
		mx = 0;
		jsef.anim._dec(id,'opacity', mx, 1, 3);
	}
};

jsef.growDisapear = function( obj ){
	if( jsef.check( obj ) == false ){
		return false;
	}
	id = obj.id;
	
	mxW = obj.oW+150; 
	jsef.anim._dec(id,'left', -100, 1, 2);
	jsef.anim._inc(id,'width', mxW, 1, 4);
	
	mxH = obj.oH+150; 
	jsef.anim._dec(id,'top', -100, 1, 2);
	jsef.anim._inc(id,'height', mxH, 1, 4);

	obj.onComplete = function(){
		this.parentNode.removeChild(this);
	}
	jsef.anim._dec(id,'opacity', 0, 1, 4);
};

jsef.growApear = function( obj ){
	if( jsef.check( obj ) == false ){
		
		return false;
	}
	id = obj.id;
	
	mxW = obj.oW
	mxH = obj.oH; 
	
	//obj.setOpac(70);
	//jsef.anim._inc(id,'opacity', 30, 1, 1);
	
	obj.style.left = mxW/2+'px';
	obj.style.top = mxH/2+'px';
	
	obj.style.width = 0+'px';
	obj.style.height = 0+'px';
	
	jsef.anim._dec(id,'left', 0 , 1, 2);
	jsef.anim._inc(id,'width', mxW, 1, 4);
	
	
	jsef.anim._dec(id,'top', 0 , 1, 2);
	jsef.anim._inc(id,'height', mxH, 1, 4);

	
};

jsef.anim.inc = function( obj, attr, mx, duration, speed ){
	if( jsef.check( obj ) == false ){
		return false;
	}
	jsef.relativise(obj, attr);

	var duration = duration || 2;
	var speed = speed || 3;


	id = obj.id;
	p = jsef.getProp(obj,attr);
	
	mx = p + mx;
	jsef.anim._inc(id,attr, mx , duration, speed);
};
jsef.anim.dec = function( obj, attr, mx,  duration, speed ){
	if( jsef.check( obj ) == false ){
		return false;
	}
	jsef.relativise(obj, attr);

	var duration = duration || 2;
	var speed = speed || 3;

	id = obj.id;
	
	jsef.anim._dec(id,attr, mx, duration, speed );
};
jsef.set = function( obj, attr, v ){
	if( jsef.check( obj ) == false ){
		return false;
	}
	id = obj.id;
	jsef._set(id,attr, v);
};