//
//	Rafał Kaminski
//	Copyright 2011
//

var opoznienie = false;
var bPauze = false;

function pauze(stan) {
	bPauze = stan;
	rotate();
	
	if(stan) {
		$('#play').attr('src', 'images/pauza.png');
	} else {
		$('#play').attr('src', 'images/play.png');
	}
}

function theRotator() {

		$('div#rotator ul li').css({opacity: 0.0});
		$('div#rotator ul li#id_1').css({opacity: 1.0});
		setInterval('rotate()',3000);	
}

function rotate(id) {	
	
	
	if(!bPauze) {
		if(id) {
			opoznienie = false;
		}
	
	
		if(!opoznienie) {
	
			var current = ($('div#rotator ul li.show')?  $('div#rotator ul li.show') : $('div#rotator ul li#id_1'));
			var next; 
		
			if(!id) {
				next = ((current.next().length) ? ((current.next().hasClass('show')) ? $('div#rotator ul li#id_1') :current.next()) : $('div#rotator ul li#id_1'));	
			}else{
				next = $('div#rotator ul li#id_'+id);
				opoznienie = true;
			}
		
			next.css({opacity: 0.0})
			.addClass('show')
			.animate({opacity: 1.0}, 800);
			current.animate({opacity: 0.0}, 800)
			.removeClass('show');
	
	
			//zaznaczenie odpowiedniego numeru
			$('div#rotator_navi span').removeClass('sel');
			$('div#rotator_navi span#n' + next.attr('id') ).addClass('sel');
		
	
		}else{
			opoznienie = false; //opoznienie jednego cyklu, zeby zaraz po recznej zmianie samo nie przelaczylo
		}
	}//pauze
};

