$(function(){

   /*
    * Polska, klikalna mapa województw - 240px |
    * http://winstonwolf.pl/css,polska.html script version: 2.3 by Winston Wolf |
    * http://winstonwolf.pl Copyright (C) 2009 - 2011 Winston_Wolf | All rights
    * reserved
    */
   $('#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-240px.png';
    * 
    */
   var mapImg = new Image();
   $(mapImg).load(function(){
      $('#loader').fadeOut();
      $('#mapa').find('li').fadeIn();
      $('#pl').find('a.mapa_linki_x').prepend('<span class="map" />');
      for( var i = 1; i < 11; i++){
         $('#pl .map').append('<span class="s' + i + '" />');
      }
      if($('#mapa').hasClass('tooltip')){
         $('#pl').find('li').each(function(){
            var tooltipName = $(this).children('p').html();
            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,
            'z-index': 1000
            });
         });
         $('#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');
   });

});
