$(document).ready(function() {
	$(".autocomplite").focus(function() {
		if ($(this).val()=='Szukaj') $(this).attr("value", "");
	});
	$(".autocomplite").blur(function() {
		if ($(this).val()=='') $(this).attr("value", "Szukaj");
	});
	
	$("#autocomplite1").autocomplete({url:'/autocomplete.php', cacheLength:10, onItemSelect:function() { $("#wyszukaj_button").click(); } });
	$("#autocomplite2").autocomplete({url:'/autocomplete.php', cacheLength:10});
	
	$('.hint *').tooltip({showURL: false, showBody: "---", fixPNG: true, track: true, delay: 0});
	
	$("#loguj_gora").focus(function() {
		if ($(this).val()=='Login') $(this).attr("value", "");
	});
	$("#loguj_gora").blur(function() {
		if ($(this).val()=='') $(this).attr("value", "Login");
	});	
	
	$("#haslo_gora").focus(function() {
		if ($(this).val()=='Login') $(this).attr("value", "");
	});
	$("#haslo_gora").blur(function() {
		if ($(this).val()=='') $(this).attr("value", "Login");
	});
	
	$(".arrow").live("click", function() {
		if ($(this).attr("pozycja")>0&&$(this).attr("pozycja")<=3) {
			var id_gry_dnia = parseInt($(this).attr("pozycja"));
			if ($(this).attr("arrow")=='left') {
				$(this).attr("pozycja", id_gry_dnia-1);
				$(".arrow.right").attr("pozycja", id_gry_dnia+1);
			}
			else {
				$(this).attr("pozycja", id_gry_dnia+1);
				$(".arrow.left").attr("pozycja", id_gry_dnia-1);
			}
			$("#box").html('<div class="srodek" style="margin-top:130px">Loading...<img src="/img/indicator.gif" alt="" /></div>');
			$("#box").load("/inc/slideshow_box.php", {'id_gry_dnia': id_gry_dnia});	
		}
	});
	
	$(".moduly").live("click", function() {
		var strona = parseInt($(this).attr("strona"));
		var limit = parseInt($("#limit_moduly").attr("limit"));
		if (strona<=limit&&strona>0) {
			if ($(this).attr("limit")>0) {
				$(this).attr("strona", strona+1);
				$(".moduly.left").attr("strona", strona-1);
				if (strona>=limit) $(this).css("display", "none");
			}
			else {
				$(this).attr("strona", strona-1);
				$(".moduly.right").attr("strona", strona+1);
			}
			if (strona>1) $(".moduly.left").css("display", "inline");
			else {
				$(".moduly.left").css("display", "none");
				$(".moduly.right").css("display", "inline");
			}
			$("#moduly_teraz").html(strona);
			$("#box_moduly").html('<div class="srodek" style="margin-top:50px; padding-bottom:50px">Loading...<img src="/img/indicator.gif" alt="" /></div>');
			$("#box_moduly").load("/inc/moduly.php", {'strona': strona});
		}
	});
	
	$(".bt").live("click", function() {
		var jaki = $(this).attr("jaki");
		var id_gry = $(this).parent().attr("id_gry");
		var co = $(this).parent().attr("co");
		if (co=='duze') {
			$(this).parent().parent().attr("cel", "tutaj");
			var param = "margin-top:90px; width:300px; height:180px";
		}
		else {
			var param = "margin-top:90px; padding-bottom:70px; padding-right:60px"
			co = 'male_new';
			$(this).parent().attr("cel", "tutaj");
		}
		$("[cel='tutaj']").prev().html('<div class="srodek" style="'+param+'">Loading...<img src="/img/indicator.gif" alt="" /></div>');
		$(this).parent().children(".on").attr("class", "bt off");
		$(this).attr("class", "bt on");
		$.post('/valid/screen.php', {'id_gry':id_gry, 'jaki':jaki}, function(response) {
			if(response) $("[cel='tutaj']").prev().html("<img src='/screeny/gry/"+co+"/"+response+".jpg' alt='brak' />");
			else $("[cel='tutaj']").prev().html('<div class="srodek" style="'+param+'">Brak screena</div>');
			$("[cel='tutaj']").removeAttr("cel");
		});
	});
	
	$('.info *').tooltip({
		track: true,
		delay: 0,
		showURL: false,
		showBody: "---",
		extraClass: "pretty",
		fixPNG: true,
		left: -120
	});
	
	$('ul.sf-menu').superfish();
	
	$("#fb_slider_main").hover(
		function () {
			$("#fb_slider_box").show("fast");			
		},
		function () {
			$("#fb_slider_box").hide("fast");
		}
	);
});

function modalOpen (dialog) {
	dialog.overlay.fadeIn('slow', function () {
		dialog.container.fadeIn('slow', function () {
			dialog.data.fadeIn('fast');	 
		});
	});
};

