/*Author: V.Seshagiri Rao @fissionlabs*/

var fade = {
            intervels:100,
            deg:100,
            _fade:null,
            onFade:null,
            flag:0,
            _pow : 1,
            s_steps : 60,
            init:function(_fade){
			               this.obj = _fade.obj; 
			               this.onFade = _fade.onFade;
			               this.s_steps = _fade.steps;
			               this._pow = _fade.pow;
			 },
			 fade:function(_obj,_obj2){
			 var _deg1 = 0;
			 var _deg2 = 100;              
             if(this._fade!=null){
              window.clearInterval(this._fade); 
              this._fade = null;
              
              }
             var _ssteps = 0; 
             this._fade = window.setInterval(function(){
                         
                           var _movement = Math.pow(((1 / fade.s_steps)*_ssteps),fade._pow) * fade.deg;
				           var movement = Math.ceil(_movement);
				           
				           _deg1+=movement;
                           _deg2-=movement;  
                           fade.crossBrowser(_obj,_deg1);
                           fade.crossBrowser(_obj2,_deg2); 
                           _ssteps++;
	                          if (_ssteps > fade.s_steps) {
	                            window.clearInterval(fade._fade); 
	                            fade._fade = null;
	                            fade.onFade(_obj2);
	                          } 
                          
                          },this.intervels);
 
			 },
			 doFade:function(obj1,obj2,url){
			  
			        if(this.flag == 0){
                     this.flag = 1;
                     this.crossBrowser(obj2,0);
                     obj2.src = url;
                     this.fade(obj2,obj1);
                    }
                    else {
                     this.flag = 0;
                     this.crossBrowser(obj1,0);
                     obj1.src = url;
                     this.fade(obj1,obj2); 
                    }
                                     
			 },
			 swap:function(obj1,obj2){
                 if(obj1.style.zIndex < obj2.style.zIndex) {
                    this.crossBrowser(obj1,0);
                    var temp =  obj2.style.zIndex;
                    obj2.style.zIndex =  obj1.style.zIndex;
                    obj1.style.zIndex = temp;
                    
                 }
                 else {
                    this.crossBrowser(obj2,0);
                    var temp =  obj1.style.zIndex;
                    obj1.style.zIndex = obj2.style.zIndex;
                    obj2.style.zIndex = temp;
                 }
                 
                 			 
			 },
			 crossBrowser:function(_obj,_deg){
			  
			 
                 if(_obj.filters && _obj.filters[0]){
                     if (typeof _obj.filters[0].opacity=="number"){ //if IE6+
					_obj.filters(0).opacity = _deg;
					
					}
					else{ //else if IE5.5-
					_obj.style.filter="alpha(opacity="+_deg+")";
					
					}
                 }
                 else if (_obj.style.MozOpacity){ 
				   _obj.style.MozOpacity=_deg/101;
				 
				 }
				 else if (_obj.style.KhtmlOpacity){
				 _obj.style.KhtmlOpacity=_deg/100;
				 
				 }
				 else if (_obj.style.opacity && !_obj.filters){
				 _obj.style.opacity=_deg/101;
				
				 }
			 }            
			              


}