jQuery(document).ready(function()
{	
	jQuery("#MainNewsImage").pngFix();
	resize();
	zegar();
	preloadImages();
	setDatePicker();

	jQuery(window).bind("resize", resize);

	/* OPERA */
	var agent = navigator.userAgent;
	var operamini = 0;	
	if (agent.search('Opera Mini') != -1)
		operamini = 1;
	/* OPERA */	
	
	jQuery("#DataZaplanuj").datepicker();	
	jQuery("#DataRejs").datepicker();
	
	jQuery("#DataZaplanujKalendarz").click(function() {
		jQuery("#DataZaplanuj").datepicker('show');
	});
	
	jQuery("#DataRejsKalendarz").click(function() {
		jQuery("#DataRejs").datepicker('show');
	});
	
	jQuery("#formSearch").attr('target', 'blank');
	
	jQuery(".newwindow").click(function()
	{
		window.open(this.href, '_blank'); 
		return false;
	});
	
	jQuery("a.gallery").lightBox({
		txtImage: 'Obraz',
		txtOf: 'z',
		imageBlank: './img/lightbox-blank.gif',
		imageLoading: './img/lightbox-ico-loading.gif',
		imageBtnClose: './img/lightbox-btn-close.gif',
		imageBtnPrev: './img/lightbox-btn-prev.gif',
		imageBtnNext: './img/lightbox-btn-next.gif'
	});
		
	jQuery("#Menu ul li a").click(function(e) 
	{
		if(jQuery(this).next().get(0))
	    {
			if(this.className.indexOf("clicked") != -1) 
			{
		   		jQuery(this).next("ul").slideUp(200);
				jQuery(this).removeClass("clicked");
			}
			else 
			{
				jQuery(this).parent().parent().children().children("a").removeClass("clicked");
				jQuery(this).addClass("clicked");
				jQuery(this).parent().parent().children().children("ul").slideUp(200);
				jQuery(this).next("ul").slideDown(500);
			}
			if (operamini == 0)
				return false;
		}
	});
	
	/* powiększanie AAA */
	
	jQuery("#asmall").click(function()
	{
		jQuery("#Aktualnosci").css("height", "auto");
		jQuery("#MainContent").css("height", "auto");

		jQuery(".ascale").removeClass('asmall');
		jQuery(".ascale").removeClass('abig');
		
		jQuery(".ascale").addClass('asmall');
		resize();
	});

	jQuery("#anormal").click(function()
	{
		jQuery("#Aktualnosci").css("height", "auto");
		jQuery("#MainContent").css("height", "auto");

		jQuery(".ascale").removeClass('asmall');
		jQuery(".ascale").removeClass('abig');
		
		resize();		
	});
	
	jQuery("#abig").click(function()
	{
		jQuery("#Aktualnosci").css("height", "auto");
		jQuery("#MainContent").css("height", "auto");

		jQuery(".ascale").removeClass('asmall');
		jQuery(".ascale").removeClass('abig');
		
		jQuery(".ascale").addClass('abig');

		resize();
	});
	
	/* ostatnie zmiany */
	
	jQuery("#OstatnieZmiany table tr").mouseover(function()
	{
		jQuery(this).addClass("hovered");
	}).mouseout(function()
	{
		jQuery(this).removeClass("hovered");
	});
	
	jQuery("#OstatnieZmiany table tr").click(function()
	{
		var id = jQuery(this).attr("ID");
		var splitted = id.split("_");

		if (splitted[2] == 1)
			document.location.href = "zmiany.php?c=102&i=" + splitted[1] + "&l=" + splitted[3];
		else
			document.location.href = "zmiany.php?c=79&i=" + splitted[1] + "&l=" + splitted[3];
	});
	
	jQuery("#IDKomunikatDotyczy").change(function()
	{
		jQuery("#SzukajZmianyForm").submit();
	});
	
	/* rozkłady */
	
	jQuery("#RozkladContent span").mouseover(function()
	{
		jQuery(this).addClass("hovered");
	}).mouseout(function()
	{
		jQuery(this).removeClass("hovered");
	});
	
	/* drukowanie */
	
	
	jQuery("#Print").click(function()
	{
		
		if (jQuery("#MainContent").length > 0)
			printWebPart("MainContent");
		else
			printWebPart("TwoColContent");
		
		return false;
	});
	
	/* zamowienia publiczne i praca*/
	
	jQuery("table.hovertable tr").mouseover(function()
	{
		jQuery(this).addClass("hovered");
	}).mouseout(function()
	{
		jQuery(this).removeClass("hovered");
	});
	
	jQuery("table.hovertable tr").click(function()
	{
		var id = jQuery(this).attr("ID");
		var splitted = id.split("_");

		document.location.href = splitted[0] + ".php?c=" +  splitted[2] + "&i=" + splitted[1] + "&l=" + splitted[3];
	});
	
	/* pytania i odpowiedzi */
	
	jQuery("a.pytanieslide").click(function()
	{
		var id = jQuery(this).attr("ID");
		var splitted = id.split("_");
		jQuery("#MainContent").css("height", "auto");
		jQuery("#odpowiedz_" + splitted[1]).toggle();
	
		return false;
	});
	
	/* bannery eu */
	
	jQuery("#bannerEU").click(function()
	{
		jQuery("#bannerEUContainer").slideDown("normal", resize);
	});

	/* drzewo ftp*/

	var simpleTreeCollection;
	simpleTreeCollection = jQuery('.simpleTree').simpleTree(
	{
		autoclose: true,
		afterAjax: function()
		{
			jQuery("#MainContent").css("height", "auto");
			resize();
		}
	});
   
	/* googlemaps api*/	
	
	if(jQuery("#MapaPSB").length > 0)
	{
		mapaStart();
		jQuery("#SearchPSBForm").submit(function()
		{
			skoczDoAdresu(jQuery("#SearchPSB").val());
			return false;
		});		
	}
	
	/* psb */
	
	jQuery("#TablePSB table tr").mouseover(function()
	{
		jQuery(this).addClass("hovered");
	}).mouseout(function()
	{
		jQuery(this).removeClass("hovered");
	});
	
	jQuery("#TablePSB table tr").click(function()
	{
		var id = jQuery(this).attr("ID");
		var splitted = id.split("|");
		var nazwa = jQuery(this).children("td").html();
		var adres = jQuery(this).children("td").next("td").html();
		dodajMarker(nazwa, '<div class="dymek"><h4>' + nazwa + '</h4><p>' + adres + '</p></div>', new GLatLng(splitted[2], splitted[3]), splitted[4]);
	});
	
	/* Podpowiedzi linii */
	
	jQuery("#Linia").autocomplete('getLinie.php',{ 
	    width: 250, 
		extraParams: {r:jQuery('#IDRozklad').val()},
	    formatItem: function(row, i, max) { 
	        return row[0] + " (<em>" + row[1] + "</em>)";
	    }, 
	    formatMatch: function(row, i, max) { 
	        return row[0]; 
	    }, 
	    formatResult: function(row) { 
	        return row[0]; 
	    } 
	});
	
	jQuery("#Linia").result(function(event, data, formatted) 
	{
		jQuery("#Linia").attr("disabled", true);
		document.location.href='rozklad_nowy.php?c=' + jQuery('#CID').val() + '&i=' + jQuery('#IDJezyk').val() + '&q=' + data[0];
	});
	
	/* Podpowiedzi przysanki */
	
	jQuery("#Przystanek").autocomplete('getPrzystanki.php',{ 
	    width: 350,
		cacheLength: 0,
		minchars: 3,
		max: 20,
		matchContains: true,
		extraParams: {r:jQuery('#IDRozklad').val()},
	    formatItem: function(row, i, max) { 
	        return row[0] + " (<em>" + row[1] + "</em>)"; 
	    }, 
	    formatMatch: function(row, i, max) { 
	        return row[0] + " " + row[1]; 
	    }, 
	    formatResult: function(row) { 

	        return row[0];
	    } 
		
	}); 
	
	jQuery("#Przystanek").result(function(event, data, formatted) 
	{
		jQuery("#Przystanek").attr("disabled", true);
		document.location.href='rozklad_nowy.php?c=' + jQuery('#CID').val() + '&i=' + jQuery('#IDJezyk').val() + '&a=' + data[2];
	});
})