/******************************************************** 
  
  Page change scripts for pages Fade in/out animation 
  Done by  Sasa Jovanovic.
  Due to a bug in IE for div content other than image, fade in/out is not trivial as it is sopose to be. 
  The trick is  to position a screen above fade in/out div and then fade in/out that screen.
  Side effect: can't be combined with other Fade in/out at the same time and the same place...
               If you are using graphics as background this is more complicated since screen must be at 
			   fixed position with matching background
  How to do it: Simply make instance of fade class with:
                fadeDivID - the tricky screen ID 
				ajaxDivID - your div id that goes Fade In/Out (ajax I presume it is going to be fatched after \
                            page is loaded, but not neccessery)

*********************************************************/


function fade(fadeDivID,ajaxDivID) {

   var animationInProgress=false; // Animation in progress flag
   var fadeID=fadeDivID;
   var ajaxID=ajaxDivID;
   var fadeDIV;

   InIt();
   
   function InIt() {
	   fadeDIV=document.getElementById(fadeID)   // Set fade object
	   if (ajaxID!="") ajaxDIV=document.getElementById(ajaxID)   // Set ajax object
   }
   
   function setItUp(fadeOpacity) {
	   animationInProgress=true;                 // Falg it
	   setOpacity(fadeID,fadeOpacity)	         // Set start opacity 
 	   if (ajaxID!="") setOpacity(ajaxID,100)
	   fadeDIV.style.display=""                  // Make them displayed
	   fadeDIV.style.visibility="visible"        // Make them displayed
	   if (ajaxID!="") ajaxDIV.style.display=""
	   if (ajaxID!="") ajaxDIV.style.visibility="visible"
   }
   
   this.fadeIn=function(evalOnFinish,fadeInInterval) {
	  if (animationInProgress) return;
	  setItUp(100)
      var OTT = new OpacityTween(fadeDIV,Tween.regularEaseIn,100,0,fadeInInterval);    // Prepare animation     
      OTT.onMotionFinished = function(){
	     fadeDIV.style.display="none"    // set it invisible
		 eval(evalOnFinish)              // Do this on finish
  	     animationInProgress=false;      // Unflag it
      };
      OTT.start();                       // Do anim
   }
   
   this.fadeOut=function(evalOnFinish,fadeOutInterval) {
	  if (animationInProgress) return;
	  setItUp(0)
      var OTT = new OpacityTween(fadeDIV,Tween.regularEaseIn,0,100,fadeOutInterval);    // Prepare animation      
      OTT.onMotionFinished = function(){
	     if (ajaxID!="") ajaxDIV.style.display="none"
   	     animationInProgress=false;      // Unflag it
		 eval(evalOnFinish)              // Do this on finish
	     fadeDIV.style.display="none"    // set it invisible
     };
      OTT.start();                       // DO anim
   }

   /* sets opacity of element */
   function setOpacity(ID,v) {
	   var t=document.getElementById(ID)
	   t.style['opacity'] = v / 100;
	   t.style['-moz-opacity'] = v / 100;
	   if(t.filters) t.filters.alpha['opacity'] = v;
   }
}



