sapiAni={
	fadeIn:function(obj,onDone){
		sapiAni.fade(obj,1,0.1,onDone);		
	},
	fadeOut:function(obj,onDone){
		sapiAni.fade(obj,0,-0.1,onDone);		
	},
	fade:function(obj,final,step,onDone){
		if(!sapiAni.setOpacity)
			sapiAni.setOpacityFunc();

		var current=sapiAni.getOpacity(obj);
		sapiAni.register({obj:obj,callback:sapiAni.changeOpacity,current:current,final:final,step:step,onDone:onDone});		
	},
	scaleSlideStart:function(obj,scalepersec){
		sapiAni.register({obj:obj,callback:sapiAni.chageImgSizePermanent,current:0,step:scalepersec/100/40});		
	},
	scaleSlideStop:function(obj){
		obj.scalestop=true;
	},
	wait:function(obj,nsec,onDone){
		var nticks=nsec*1000/50;
		sapiAni.register({obj:obj,callback:sapiAni.checkWait,current:0,final:nticks,step:1,onDone:onDone});		
	},
	register:function(fxObj){
		var me=sapiAni;
		if(!me.queue) me.queue=new Array();
//dputs("register:"+fxObj.obj.d2wslide.pic+":"+fxObj.current+":"+me.queue.length);
		for(var cnt=0;cnt<me.queue.length;cnt++){
			var o=me.queue[cnt];	
			if(o.obj==fxObj.obj && o.callback==fxObj.callback){
//dputs("register:matched?");
				me.queue[cnt].final=fxObj.final;
				me.queue[cnt].step=fxObj.step;
				me.queue[cnt].onDone=fxObj.onDone;
				return;
			}
		};
		me.queue.push(fxObj);
//dputs("register:"+fxObj.obj.d2wslide.pic+":"+me.queue.length);
		if(!me.timer)
			me.timer=setTimeout(me.tick,50);
	},
	tick:function(){
		var me=sapiAni;
		var bufA=me.queue;
		var arr=new Array();
		for(var cnt=0;cnt<bufA.length;cnt++){
			var o=bufA[cnt].callback(bufA[cnt])
			if(o)	arr.push(o);
		};
		if(arr.length!=bufA.length){
			for(var cnt=0;cnt<bufA.length;cnt++)
				delete bufA[cnt];
			delete bufA;
			me.queue=arr;
		} else {
			delete arr;
		};
		if(!me.queue.length){
			me.timer=0;
		} else {
			me.timer=setTimeout(me.tick,50);
		}
	},
	checkWait:function(fxObj){
		var me=sapiAni;
		fxObj.current+=fxObj.step;
		if(fxObj.current>=fxObj.final){
			sapiAni.delayCall(fxObj.onDone,fxObj.obj,20);
			for(var o in fxObj) fxObj[o]="";
			fxObj="";
			return null;
		};
		return fxObj;
	},
	changeOpacity:function(fxObj){
		var me=sapiAni;
		fxObj.current+=fxObj.step;
		if(fxObj.step>0 && fxObj.current>fxObj.final){
			fxObj.current=fxObj.final;
		} else if(fxObj.step<0 && fxObj.current<fxObj.final){
			fxObj.current=fxObj.final;
		};
		me.setOpacity(fxObj);
		if(fxObj.current==0){
			fxObj.obj.style.display="none";
		} else if(fxObj.obj.style.display=="none"){
			fxObj.obj.style.display="block";
		};
		if(fxObj.obj.jslidecallback)
			try {
				fxObj.obj.jslidecallback(fxObj.current);	
			} catch (e){
			};

//dputs("changeOpacity:"+fxObj.obj.d2wslide.pic+":"+fxObj.current);

		if(fxObj.current==fxObj.final){
//dputs("changeOpacity:"+fxObj.obj.d2wslide.pic+": final reached");
			sapiAni.delayCall(fxObj.onDone,fxObj.obj,20);
			for(var o in fxObj) fxObj[o]="";
			fxObj="";
			return null;
		};
		return fxObj;
	},
	chageImgSizePermanent:function(fxObj){
		var me=sapiAni;
		if(fxObj.obj.scalestop) return false;
		if(!fxObj.inited){
			fxObj.startW=fxObj.obj.parentNode.offsetWidth;
			fxObj.startH=fxObj.obj.parentNode.offsetHeight;
			fxObj.dW=fxObj.startW*fxObj.step;
			fxObj.dH=fxObj.startH*fxObj.step;
			if(fxObj.startH && fxObj.startW)
				fxObj.inited=true;
		} else {
			var w=fxObj.dW*fxObj.current;
			var h=fxObj.dH*fxObj.current;
			fxObj.obj.firstChild.style.width=(w+fxObj.startW)+"px";
			fxObj.obj.firstChild.style.height=(h+fxObj.startH)+"px";
			fxObj.obj.style.top=-(h/2)+"px";
			fxObj.obj.style.left=-(w/2)+"px";
			fxObj.current++;
		};
		return fxObj;
	},
	delayCall:function(func,param,t){
		if(!func) return;
		var me=sapiAni;
		if(!me.cid) me.cid=1;
		me.cid++;
		if(!me.callbacks) me.callbacks={};
		me.callbacks[me.cid]={obj:param,onDone:func,timer:0};
		me.callbacks[me.cid].timer=setTimeout("sapiAni.doDelayCall("+me.cid+")",t);
		return me.cid;
	},
	doDelayCall:function(cid){
		var me=sapiAni;
		if(!me.callbacks) return;
		if(!me.callbacks[cid]) return;
		me.callbacks[cid].onDone(me.callbacks[cid].obj);
		me.callbacks[cid].onDone="";		
		me.callbacks[cid].obj="";
		me.callbacks[cid].timer="";
		delete me.callbacks[cid];
	},
	abandonDelayCall:function(cid){
		var me=sapiAni;
		if(!me.callbacks) return;
		if(!me.callbacks[cid]) return;
		if(me.callbacks[cid].timer){
			clearTimeout(me.callbacks[cid].timer);
			me.callbacks[cid].timer=0;
		};
	},
	getOpacity:function(obj){
		if (typeof document.body.style.opacity == 'string'){ 
			if(obj.style.opacity==="") obj.style.opacity=1;
			if(obj.style.display=="none") obj.style.opacity=0;
			return parseFloat(obj.style.opacity);
		} else if (typeof document.body.style.MozOpacity == 'string'){
			if(obj.style.MozOpacity==="") obj.style.MozOpacity=1;
			if(obj.style.display=="none") obj.style.MozOpacity=0;
			return parseFloat(obj.style.MozOpacity);
		} else if (typeof document.body.style.KhtmlOpacity == 'string'){
			if(obj.style.KhtmlOpacity==="") obj.style.KhtmlOpacity=1;
			if(obj.style.display=="none") obj.style.KhtmlOpacity=0;
			return parseFloat(obj.style.KhtmlOpacity);
		} else if (document.body.filters && navigator.appVersion.match(/MSIE ([\d.]+);/)[1]>=5.5){
			var nO=100;
		      if(obj.style.display=="none") nO=0;
			
			var oAlpha=null;
			if(obj.filters)
				if(obj.filters['DXImageTransform.Microsoft.alpha']){
					oAlpha=obj.filters['DXImageTransform.Microsoft.alpha'];
				} else if(obj.filters.alpha){
					oAlpha = obj.filters.alpha;
				}

			if(!oAlpha){
 				obj.style.filter += "progid:DXImageTransform.Microsoft.Alpha(opacity="+nO+")"; 
				return nO/100;
			} else if (oAlpha){
				return oAlpha.opacity/100;
			};
			return 1;
		} else {
			return null;
		};
	},

	setOpacityFunc:function(){
		if (typeof document.body.style.opacity == 'string'){ 
			sapiAni.setOpacity=function(fxObj){
				fxObj.obj.style.opacity=fxObj.current;
			};
		} else if (typeof document.body.style.MozOpacity == 'string'){
			sapiAni.setOpacity=function(fxObj){
				fxObj.obj.style.MozOpacity=fxObj.current;
			};
		} else if (typeof document.body.style.KhtmlOpacity == 'string'){
			sapiAni.setOpacity=function(fxObj){
				fxObj.obj.style.KhtmlOpacity=fxObj.current;
			};
		} else if (document.body.filters && navigator.appVersion.match(/MSIE ([\d.]+);/)[1]>=5.5){
			sapiAni.setOpacity=function(fxObj){
				var nO=Math.floor(fxObj.current*100);
				var obj=fxObj.obj;
				var oAlpha=null;
				if(obj.filters)
					if(obj.filters['DXImageTransform.Microsoft.alpha']){
						oAlpha=obj.filters['DXImageTransform.Microsoft.alpha'];
					} else if(obj.filters.alpha){
						oAlpha = obj.filters.alpha;
					}
				if (oAlpha){
					oAlpha.opacity = nO;
				} else {
					obj.style.filter += "progid:DXImageTransform.Microsoft.Alpha(opacity="+nO+")"; 
				};
			};
		} else {
			sapiAni.setOpacity=function(){};
		};
	}
}
