var actual = 0;
var first = 0;
var time;


function change_rotate_forward()
{
	clearTimeout(time);
	if(actual >= rotator){
		actual = 0;
	}else{
		//actual = actual;
	}
	
	//alert(actual);
	start_rotate();

}



function change_rotate_backward()
{
	clearTimeout(time);
	
	if(actual == 1){
		actual = rotator-1;
	}else if(actual == 0){
		actual = rotator-2;
	}
	else{
		actual = actual-2;
	}
	
	start_rotate_backward();

}

function start_rotate()
{

		$('.image').hide();	
		$('.image').css('z-index', '1');
		$('.rotator_button').css('text-decoration', 'none');
		$('.rotator_button').css('color', '#fff');
		$('#image_'+actual).fadeIn('slow');
		$('#text_'+actual).fadeIn('slow');
		$('#button_'+actual).css('text-decoration', 'underline');
		$('#button_'+actual).css('color', 'black');
		$('.rot_text').fadeOut('slow');
		if(actual >= rotator)
		{
			$('#image_0').show();	
			$('#text_0').show();
			$('#image_0').fadeOut('slow');
			$('#text_0').fadeOut('slow');
		}else{
				if(actual == 0){
					if(first == 1)
					{
						$('#image_'+(rotator-1)).show();
						$('#text_'+(rotator-1)).show();
			
						$('#image_'+(rotator-1)).fadeOut('slow');
						$('#text_'+(rotator-1)).fadeOut('slow');
					}else
					{
						first = 1;
					}	
				}else{
				
					$('#image_'+(actual-1)).show();
					$('#text_'+(actual-1)).show();
			
					$('#image_'+(actual-1)).fadeOut('slow');
					$('#text_'+(actual-1)).fadeOut('slow');
				}

		}
	



	
	


	$('#image_'+(actual-1)).css('z-index', '10000');
	$('#text_'+(actual-1)).css('z-index', '10000');

	if(actual >= rotator)
	{
		$('#image_0').css('z-index', '9999');
		$('#text_0').css('z-index', '9999');
	}else
	{
		$('#image_'+actual).css('z-index', '9999');
		$('#text_'+actual).css('z-index', '9999');
	}
	
	actual++;
	if(actual >= rotator)
	{
		actual = 0;
	}

		
		
	
	
	time = setTimeout('start_rotate();', time_rotator*1000);

}


function start_rotate_backward()
{

		$('.image').hide();	
		$('.image').css('z-index', '1');
		$('.rotator_button').css('text-decoration', 'none');
		$('.rotator_button').css('color', '#fff');
		$('#image_'+actual).fadeIn('slow');
		$('#text_'+actual).fadeIn('slow');
		$('#button_'+actual).css('text-decoration', 'underline');
		$('#button_'+actual).css('color', 'black');
		//alert(actual);
		if(actual >= rotator)
		{
			$('#image_'+(rotator-1)).show();	
			$('#text_'+(rotator-1)).show();
			$('#image_'+(rotator-1)).fadeOut('slow');
			$('#text_'+(rotator-1)).fadeOut('slow');
		}else{
				if(actual == 0){
					
					
					$('#image_'+(actual+1)).show();
					$('#text_'+(actual+1)).show();
			
					$('#image_'+(actual+1)).fadeOut('slow');
					$('#text_'+(actual+1)).fadeOut('slow');
					
				}else if ( actual == (rotator-1)){
					$('#image_0').show();
					$('#text_0').show();
			
					$('#image_0').fadeOut('slow');
					$('#text_0').fadeOut('slow');
				}else{
				
					$('#image_'+(actual+1)).show();
					$('#text_'+(actual+1)).show();
			
					$('#image_'+(actual+1)).fadeOut('slow');
					$('#text_'+(actual+1)).fadeOut('slow');
				}

		}
	



	
	


	$('#image_'+(actual+1)).css('z-index', '10000');
	$('#text_'+(actual+1)).css('z-index', '10000');

	if(actual >= rotator)
	{
		$('#image_0').css('z-index', '9999');
		$('#text_0').css('z-index', '9999');
	}else
	{
		$('#image_'+actual).css('z-index', '9999');
		$('#text_'+actual).css('z-index', '9999');
	}
	
	actual++;
	if(actual >= rotator)
	{
		actual = 0;
	}

		
		
	
	
	time = setTimeout('start_rotate();', time_rotator*1000);

}

