var ww = false;
function getUrl(i) {
	curIndex = i;
	ww = urls[i];
	$("#main2").hide();
	$("#main2").load(ww + "?x=1", function() {
		$("#main").fadeOut("slow");
		$("#main2").fadeIn("slow", function() {
			$("#main").html($("#main2").html());
			$("#main").show();
			$("#main2").hide();
			clearTimeout(t);
			t = setTimeout("nextUrl()", 5000);
			for(n=0;n<$("#submenu a").length;n++) {
				if(n<=i) {
					$("#balk img").eq(n).attr("src", "/gfx/dot_blue.gif");
				} else {
					$("#balk img").eq(n).attr("src", "/gfx/dot_white.gif");
				}
			}
		});
		
	});
	
}
var urls;
var num = 0;
var curIndex = 0;
var t = false;
function go() {
	//$("#submenu a").click(function() {
	//	ww = this.href;
	//	getUrl();
	//	return false;
	//});
	urls = new Array();
	len = $("#submenu a").length;
	num = 0;
	$("#submenu a").each(function(intIndex) {
		urls[intIndex] = $(this).attr("href");
		$(this).attr("number", intIndex);
		//$(this).click(function() {
		//	getUrl(intIndex);
		//	return false;
		//});
	});
	curIndex = 0;
	$("#main").hide();
	$("#main").load(urls[curIndex] + "?x=1", function() {
		$("#main").fadeIn("slow");
	});
	t = setTimeout("nextUrl()", 5000);
	
}
function nextUrl() {
	curIndex = curIndex + 1;
	if(curIndex >= $("#submenu a").length) {
		curIndex = 0;
	}
	getUrl(curIndex);
}

$(document).ready(function() {
	$('#pane').jScrollPane({showArrows:true});
	
	$(".popImage").click (function() {
		 $("#picturesrc").attr({"src":this.href});
		 $("#picture").fadeIn(); 
		 return false;
	});
	$("#picture").click(function() {
		$(this).fadeOut(); 
	}); 
	$("#scroll_left").click(function() {
		clearTimeout(t);
		curIndex = curIndex - 1;
		if(curIndex < 0) {
			curIndex = $("#submenu a").length - 1;
		}
		getUrl(curIndex);
	});
	$("#scroll_right").click(function() {
		clearTimeout(t);
		nextUrl();
	});
	$("#menu li").hover(
	  function () {
	    
	    $(this).find("ul").css("zIndex", 12348);
	    $(this).find("ul").show();
	    
	  },
	  function () {
	    //$(this).removeClass("hover");
	    $(this).find("ul").hide();
	  }
	);
	lightbox();
});

var play = false;
var kavelNum = 0;
function doKavel(num) {
	if(kavelNum == num) {
		return;
	}
	if(play) {
		return;
	}
	play = true;
	$("#kavel" + kavelNum).fadeOut("slow", doKavelIn); 
	kavelNum = num;
}
function doKavelIn() {
	$("#kavel" + kavelNum).fadeIn("slow", stopPlay); 
}
function stopPlay() {
	play = false;
}
