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();
	});

	if ($('#Scrollarea').length > 0)
	{
		$('#Scrollarea').cycle({ 
	    	fx:    'scrollLeft', 
		    delay: -4000 ,
			speed:  4000,
			pause: 1
		});
	}	
	
	/* 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("#Utrudnienia table tr").mouseover(function()
	{
		jQuery(this).addClass("hovered");
	}).mouseout(function()
	{
		jQuery(this).removeClass("hovered");
	});

	jQuery("#Utrudnienia table tr").click(function()
	{
		var id = jQuery(this).attr("ID");
		var splitted = id.split("_");
		document.location.href = "utrudnienia.php?c=539&i=" + splitted[1] + "&l=" + splitted[2];
	});

	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();
		var godziny = jQuery(this).children("td").next("td").next("td").html();
		var godzinyT = jQuery(this).children("td").next("td").next("td").attr("alt");
		var bilety = jQuery(this).children("td").next("td").next("td").next("td").html();
		var biletyT = jQuery(this).children("td").next("td").next("td").next("td").attr("alt");
		var platnosc = jQuery(this).children("td").next("td").next("td").next("td").next("td").html();
		var platnoscT = jQuery(this).children("td").next("td").next("td").next("td").next("td").attr("alt");
		dodajMarker(nazwa, '<div class="dymek"><h4>' + nazwa + '</h4><p>' + adres + '</p><br/><p>' + godzinyT +':<br/>' + godziny + '</p><br><p>' + biletyT + ': ' + bilety + '</p><br><p>' + platnoscT + ': ' + platnosc + '</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];
	});

	jQuery('#Hafas').click(function()
	{
		jQuery('#formSearch').attr("action", "http://wyszukiwarka.ztm.waw.pl/bin/query.exe/pn");

		jQuery('#Start').attr("name", "REQ0JourneyStopsS0G");
		jQuery('#Koniec').attr("name", "REQ0JourneyStopsZ0G");
		jQuery('#DataZaplanuj').attr("name", "nhd");
		jQuery('#Odjazd').attr("name", "REQ0HafasSearchForw");
		jQuery('#Przyjazd').attr("name", "REQ0HafasSearchForw");
		jQuery('#Godzina').attr("name", "time");

		jQuery('#Odjazd').attr("value", "1");
		jQuery('#Przyjazd').attr("value", "0");
		jQuery('#REQ0JourneyStopsS0A').attr("disabled", false);
		jQuery('#REQ0JourneyStopsZ0A').attr("disabled", false);

		jQuery.post("zliczKlikniecia.php", { click: "h"} );

		jQuery('#formSearch').submit();
	});

	jQuery('#jakdojade').click(function()
	{
		jQuery('#formSearch').attr("action", "http://jakdojade.pl/form");

		jQuery('#Start').attr("name", "fn");
		jQuery('#Koniec').attr("name", "tn");
		jQuery('#DataZaplanuj').attr("name", "d");
		jQuery('#Odjazd').attr("name", "ia");
		jQuery('#Przyjazd').attr("name", "ia");
		jQuery('#Godzina').attr("name", "h");

		jQuery('#Odjazd').attr("value", "false");
		jQuery('#Przyjazd').attr("value", "true");
		jQuery('#REQ0JourneyStopsS0A').attr("disabled", true);
		jQuery('#REQ0JourneyStopsZ0A').attr("disabled", true);

		jQuery.post("zliczKlikniecia.php", { click: "j"} );

		jQuery('#formSearch').submit();
	});
})

