//
// Rotate Items class
//
function RotateItemsclass()
{
	var firstTime = true;
	var actual = 0;
	var speed = 6;
	var size = 4;
	var pe;
	var diapos;
	var linked;
	var prefix;
	var IE = false;
	var effectDurationAppear = 1.0;
	var effectDurationFade = 2.0;
	
    this.Initialize = _initialize;
	
	// initialize
	function _initialize(indexParam, speedParam, sizeParam, prefixParam)
	{
		/* Detect IE < 7 */
		if ( typeof document.body.style.maxHeight == 'undefined')
			IE = true;

		if(typeof indexParam != 'undefined')
			actual = indexParam;

		if(typeof speedParam != 'undefined')
			speed = speedParam;

		if(typeof sizeParam != 'undefined')
			size = sizeParam;
		
		if(typeof prefixParam != 'undefined')
			prefix = prefixParam + '_';
		else
			prefix = '';

		diapos = $$("." + prefix + "rotationDiapo");

		$(prefix + 'rotationDiapo1').style.backgroundImage = 'url('+ diapos[actual].src +')';
		Element.hide($(prefix + 'rotationDiapo2'));
		Element.show($(prefix + 'rotationDiapo1'));
		
		periodical();
	}

	// periodical
	function periodical()
	{
		pe = new PeriodicalExecuter(changePhoto, speed);
	}
	
	// changePhoto
	function changePhoto()
	{
		index  = actual + 1;
			
		if (index > (size - 1) ) index = 0;
			
		if ($(prefix + 'rotationDiapo1').style.display == 'none')
		{
			$(prefix + 'rotationDiapo1').style.backgroundImage = 'url('+ diapos[index].src +')';
				
			IE ? Element.hide($(prefix + 'rotationDiapo2')) : Effect.Fade($(prefix + 'rotationDiapo2'), { duration: effectDurationFade });
			IE ? Element.show($(prefix + 'rotationDiapo1')) : Effect.Appear($(prefix + 'rotationDiapo1'), { duration: effectDurationAppear });
		}
		else
		{
			$(prefix + 'rotationDiapo2').style.backgroundImage = 'url('+ diapos[index].src +')';
				
			IE ? Element.hide($(prefix + 'rotationDiapo1')) : Effect.Fade($(prefix + 'rotationDiapo1'), { duration: effectDurationFade });
			IE ? Element.show($(prefix + 'rotationDiapo2')) : Effect.Appear($(prefix + 'rotationDiapo2'), { duration: effectDurationAppear });
		}
		
		actual = index;
	}
}

