/**
* CRIOSWEB Content Animation 0.1
* javascript class for animating HTML DIVs
* requires jquery
*
* Copyright (c) 2009-2010 Lucian SABO (luciansabo@gmail.com);
* http://luci.criosweb.ro
*
* Licensed under CreativeCommons LGPL http://creativecommons.org/licenses/LGPL/2.1/
* For commercial use please contact me.
==============================================================================================
*/
var globalScope = {currentId:0, getRandomId:function(){return this.currentId++;}};

function CriosContentAnimation(BaseId, Count)
{
   //properties
   this.Count = Count;                          // how many boxes do you want to animate
   this.BaseId = BaseId;                        // the class starts with BaseId (ex: "c" having c1, c2, c3...)
   this.Delay = 4000;                           // time in milisecond to wait between frames
   this.FadeInSpeed = 1000;                     // fade in speed
   this.uniqueId = globalScope.getRandomId();   // updated automatically (needed for method recursion hack under IE)

   //public methods
   CriosContentAnimation.prototype.Start = Start;


   //hide all boxes besides the first
   for(i = 2; i <= this.Count; i++ )
   	document.getElementById(this.BaseId + i).style.display = 'none';	

//-------------------------------------------------------------------
function Start(calup) {	

	// condition to exit the recursive function or start over
	if(calup > this.Count) {
	  calup = 1;
      $("div#" + this.BaseId + "3").fadeOut("slow");
	}	
			
	// hide the previous box (only if it is not the first)
	if(calup != 1) {
      $("div#" + this.BaseId + (calup - 1)).fadeOut("slow");
	}
   else
      //otherwise, (the we reached the end) hide the last element to start over
      $("div#" + this.BaseId + this.Count).fadeOut("slow");
   	

   $("div#" + this.BaseId + calup).fadeIn(this.FadeInSpeed);
	calup++;
		
	// call this function recursivelly
   if( document.all ) {
   	// this is a hack for IE by Alexander Reintzsch, inspired from an alexle.net article
      /* make a reference to the current object and saved in the global scope array
      * to use later to correct the scope.
      */
      globalScope[ this.uniqueId ] = this;
      setTimeout( 'globalScope["' + this.uniqueId + '"]["Start"]('+ calup + ');', this.Delay );
   }
   else
      setTimeout(function(thisObj) { thisObj.Start(calup); }, this.Delay, this);
}
//-------------------------------------------------------------------
}
