var iRotatorLink = 1;
var iRotatorSecs = 5;
var iRotatorElements = 3;

function rotator(i)
{ 
	if(i > iRotatorElements )
		i = 1;
	
	jQuery('#rotatorDescription').find('p').fadeOut('slow');
	jQuery('#rotatorDescriptionMore').find('a').fadeOut('slow');
	var oRotatorHeadingImg = jQuery('#rotatorHeading > img');
	oRotatorHeadingImg.fadeOut('slow', function(){rotatorFadeIn(i);});
	iRotatorLink = i;
	iRotatorSecs = 5;
}

function rotatorFadeIn(i)
{
	var oRotatorHeadingImg = jQuery('#rotatorHeading > img');
	oRotatorHeadingImg.attr('src','/media/rotator/' + i + '_heading.png');
	oRotatorHeadingImg.fadeIn('slow');
	jQuery('#rotatorDescription_'+i).fadeIn('slow');
	jQuery('#rotatorDescriptionMore_'+i).fadeIn('slow');
	
	jQuery('#rotatorEnumeration').find('a').css('background-position','0 0');
	jQuery('#rotatorMenuAnchor_' + i).css('background-position','0 -20px');
}

function rotate()
{
	--iRotatorSecs;
	
	if( iRotatorSecs < 0 )
	{
		rotator(iRotatorLink+1);
	}
	
	setTimeout("rotate()",1000);
}

jQuery(document).ready(function(){
		
	//stworzenie enumeracji rotatora
	var oEnumerationContainer = jQuery('#rotatorEnumeration');
	var sHtml = '';
	
	for( var i = 0; i < iRotatorElements; i++ )
	{
		sHtml += '<li><a href="#" style="background-image:url(/media/rotator/'+(i+1)+'_button.png)"><img src="/media/rotator/blank.png" alt="" width="16" height="16" /></a></li>';
	}
	var i = 1;
	oEnumerationContainer.find('ul').html( sHtml );
	oEnumerationContainer.find('a:first').css('background-position','0 -20px');
	oEnumerationContainer.find('a').each( function(){
		eval('jQuery(this).click( function() {rotator('+i+')});jQuery(this).attr("id","rotatorMenuAnchor_'+i+'");i++;');
	});
	
	setTimeout("rotate()",1000);
	return;
	

	
});
