var slajdy = 5;
var current = 1;
var autoslajd = "";

function nastepny() {
  
	if ( current == slajdy )
		current=1;
	else if ( current < slajdy )
		current++;

	wczytajSlajd();
}

function poprzedni() {
	if ( current == 1 )
		current = slajdy;
	else if ( current > 1 )
		current--;
	wczytajSlajd();
}

function ustaw(strona) {
	current = strona;
	wczytajSlajd();
	stopSlideshow();
}


function wczytajSlajd() {

  $('#rotator_image').fadeOut("fast",function(){$('#rotator_image').css({"background":"url('http://afilo.pl/webapps/front/html/img/images/rotator" + current + ".jpg') no-repeat left top"})});
  
  $('#rotator_image').fadeIn("slow",wczytajSlajdTeksty());
  
//	$("#rotator_image" + " img").attr("src", "http://afilo.pl/webapps/front/html/img/images/rotator" + current + ".jpg");

}

function wczytajSlajdTeksty(){

	for (i=1;i<=slajdy;i++)
	{
		if ( current != i) {
			$("#rotator_text"+i).hide();
			$("#rotator_navi"+i).removeClass('rotator_selected');
		} else {
			$("#rotator_text"+i).show();
			$("#rotator_navi"+i).addClass('rotator_selected');    
		}
	}	


}

function runSlideshow(){

      autoslajd = setInterval("nastepny();", 3200);  
}

function stopSlideshow(){
        clearInterval(autoslajd);
}

$(document).ready(function() {
        runSlideshow();
});



function switchTabs(numer){
  if (numer == 1) {
     $("#tab_reklamodawcy" + " img").attr ("src","http://afilo.pl/webapps/front/html/img/images/tab_reklamodawcy_off.png");
     $("#tab_witryny" + " img").attr ("src","http://afilo.pl/webapps/front/html/img/images/tab_witryny.png");
     $("#tab_ul_reklamodawcy").hide(); 
     $("#tab_ul_witryny").show(); 
     $("#tab_button_reklamodawcy").hide(); 
     $("#tab_button_witryny").show(); 
     }
  else {
     $("#tab_reklamodawcy" + " img").attr ("src","http://afilo.pl/webapps/front/html/img/images/tab_reklamodawcy.png");
     $("#tab_witryny" + " img").attr ("src","http://afilo.pl/webapps/front/html/img/images/tab_witryny_off.png");    
     $("#tab_ul_reklamodawcy").show(); 
     $("#tab_ul_witryny").hide();   
     $("#tab_button_reklamodawcy").show(); 
     $("#tab_button_witryny").hide(); 
  }

}