﻿

$(function(){

$('#pl').each(function() {
	            var $ul = $(this);
	            var $li = $ul.children('li');
	            //przy wejsciu na strone ukrywamy tresc tabow i pokazujemy tylko aktywny...
	            $li.each(function() { //pŕtla po wszystkich tabach
	                var $trescTaba = $($(this).children('a').attr('href')); //pobieramy blok o id pobranym z linka-taba
	                if ($(this).hasClass('active')) { //je┐eli ten tab ma klasŕ aktywn╣
	                    $trescTaba.show(); //to pobrany przed chwil╣ blok pokazujemy
	                } else {
	                    $trescTaba.hide(); //je┐eli takiej klasy nie ma to blok ukrywamy
	                }
	            });
	                     
	            //ma│y trik - gdy klikamy na tab, wtedy wykonujemy zdarzenie dla linka, ktˇry siŕ w nim znajduje (dzieki temu mo┐emy klikn╣Š na ca│y tab, a nie tylko na linka)
	            $li.click(function() {$(this).children('a').click()});
	            //po klikniŕciu na link...
	            $li.children('a').click(function() {
	                //usuwamy z tabˇw klasŕ active
	                $li.removeClass('active');
	                //ukrywamy wszystkie taby              
	                $li.each(function() {
	                    $($(this).children('a').attr('href')).hide();
                });
	                //ustawiamy klikniŕtemu tabowi klasŕ aktywn╣
	                $(this).parent().addClass('active');
	                $($(this).attr('href')).show();
	                //nie chcemy wykonaŠ domyťlnej akcji dla linka
	                return false;
	            });
	        });


  $('#mapa').prepend('<span id="loader">Loading ...</span>').addClass('script'); $('#mapa').find('li').hide();

  var mapUrl=$('#pl').css('background-image').replace(/"/g,"").replace(/url\(|\)$/ig, "");
/* pobiera ścieżkę do pliku z mapką; w razie problemów z ładowaniem obrazka zastąp bezpośrednią ścieżką do obrazka:

  var mapUrl='http://twoja-strona.pl/images/pl-460px.png'; 

*/
  var mapImg=new Image();
  $(mapImg).load(function(){$('#loader').fadeOut(); $('#mapa').find('li').fadeIn(); $('#pl').find('a').prepend('<span class="map" />');
   for(var i=1;i<17;i++){ $('#pl .map').append('<span class="s'+i+'" />'); }
   if($('#mapa').hasClass('tooltip')){$('#pl').find('li').each(function(){ var tooltipName=$(this).children('a').text(); var tooltipLeft=$('.tt').outerWidth()/-2; var tooltipTop=$('.tt').outerHeight()/-2; $(this).append('<span class="tt">'+tooltipName+'</span>'); $('.tt').css({'display':'none','margin-left':tooltipLeft,'margin-top':tooltipTop});});$('#pl li').hover(function(){$(this).children(".tt:visible").hide(); $(this).children(".tt").show(); $(this).children("a").removeAttr('title');},function(){$(this).children(".tt").hide();});}
   }).error(function(){$('#loader').text('Brak mapy!'); $('#pl span').hide(); $('#mapa,#pl').css({'height':'auto','left':'0','margin':'0 auto'});
    }).attr('src',mapUrl);
  var loaderPos=$('#loader').outerWidth()/-2; $('#loader').css('margin-left',loaderPos);
  $('#pl').find('li').click(function(){window.location.href=$(this).children('a').attr('href');});
// koniec mapy

    $(function(){$('#options').find('a').click(function(){var klasa=$(this).text(); $('.switch').text(klasa); $('#mapa').removeClass().addClass(klasa+' script'); $(this).attr('href','#');}); $('#pl').find('li').click(function(){$('.active').removeClass(); $(this).find('a').addClass('active'); return false;});$('#pl').find('a').each(function(){if($(this).attr('href')===window.location.hash){$(this).addClass('active');}}); var scroll_timer; var displayed = false; var $message = $('#top-link'); var $window = $(window); var top = $(document.body).children(0).position().top; $window.scroll(function(){window.clearTimeout(scroll_timer);scroll_timer = window.setTimeout(function(){if($window.scrollTop() <= top){displayed = false;$message.fadeOut();}else if(displayed == false){displayed = true;$message.stop(true, true).fadeIn().click(function () { $message.fadeOut(); });}},100);});});
    //]]>

});
