jQuery().ready(function()
{	

	function replaceString(oldS, newS, fullS) {
		// Replaces oldS with newS in the string fullS
			for (var i = 0; i < fullS.length; i++) {
				if (fullS.substring(i, i + oldS.length) == oldS) {
					fullS = fullS.substring(0, i) + newS + fullS.substring(i + oldS.length, fullS.length);
				}
			}
		return fullS;
	}

	var aktywny=1;
	var speed=170;
	var speed2=400;
	var opacity = 0.5;
	var opacity2 = 1;
	var interval = 3000;
	
	jQuery("#rotator").addClass("czyrots");
	
	function rotuj2() {
	rotuj();
	}
	
	jQuery("#rotator").hover(function(){jQuery(this).removeClass("czyrots");},function(){jQuery(this).addClass("czyrots");});
	
	function rotuj() {
		var klaska = jQuery("#rotator").attr("class");
		if (klaska=="czyrots") {
		var c = jQuery(".kropki a").length;
		var thisid = jQuery(".kropki a.zaznaczone").attr("id");
		var thisid_l = parseInt(replaceString("krop","",thisid));
		
		if (thisid_l==c) {thisid_l=1} else {thisid_l=thisid_l+1}

		thisid = "krop"+thisid_l;
			
		var link = "rot_"+thisid;
		//jQuery("#rotator2").fadeTo(speed,0,function(){jQuery("#rotator2").load("rotator.php div#"+link,"",function(){jQuery("#rotator2").fadeTo(speed,1);jQuery(".kropki a").removeClass("zaznaczone");jQuery(".kropki a#"+thisid).addClass("zaznaczone");});});
		jQuery("#rotator2").fadeTo(speed,0,function(){jQuery("#rotator2").load("rotator.php div#"+link,"",function(){jQuery("#rotator2").fadeTo(speed,1);jQuery(".kropki a").removeClass("zaznaczone");jQuery(".kropki a#"+thisid).addClass("zaznaczone");});});
		}
		//return true;	
	}

	var link = "rot_krop1";
	jQuery("#rotator2").fadeTo(speed,0,function(){jQuery("#rotator2").load("rotator.php div#"+link,"",function(){jQuery("#rotator2").fadeTo(speed,1);setInterval(function() {rotuj2();}, interval);});});
	
	jQuery(".kropki a").live("click",function()
	{
		var thisid = jQuery(this).attr("id");
		var link = "rot_"+thisid;
		jQuery("#rotator2").fadeTo(speed,0,function(){jQuery("#rotator2").load("rotator.php div#"+link,"",function(){jQuery("#rotator2").fadeTo(speed,1);jQuery(".kropki a").removeClass("zaznaczone");jQuery(".kropki a#"+thisid).addClass("zaznaczone");});});
		return false;		
	});
	
});
