$(function(){

/*
España, CSS & jQuery Clickable map - 570px | http://winstonwolf.pl/css,espana.html
script version: 2.4 by Winston Wolf | http://winstonwolf.pl
Copyright (C) 2011 Winston_Wolf | All rights reserved
*/
  $('#map').prepend('<span id="loader">Loading ...</span>').addClass('script'); $('#map').find('li').hide();

  var mapUrl=$('#es').css('background-image').replace(/"/g,"").replace(/url\(|\)$/ig, "");

/* takes a path to a file with a map, in case of problems with loading the image, replace the direct path to the image:

  var mapUrl='http://example.com/images/es-570px.png'; 

*/
  var mapImg=new Image();
  $(mapImg).load(function(){$('#loader').fadeOut(); $('#map').find('li').fadeIn(); $('#es').find('a').prepend('<span class="map" />');
   for(var i=1;i<32;i++){ $('#es .map').append('<span class="s'+i+'" />'); }
   if($('#map').hasClass('tooltip')){$('#es').children('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});});$('#es 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('No map!'); $('#es').find('span').hide(); $('#map,#es').css({'height':'auto','left':'0','margin':'0 auto'});
    }).attr('src',mapUrl);
  var loaderPos=$('#loader').outerWidth()/-2; $('#loader').css('margin-left',loaderPos);
  $('#es').children('li').click(function(){window.location.href=$(this).children('a').attr('href');});
// end of the map



/* OPTIONAL: 

// Activation of the country without going to a page in the link:

  $('#es').find('li').click(function(){
    $('.active').removeClass();
    $(this).find('a').addClass('active');

    // plus an event for the active country

     return false;
   });


// Activation of the country by URL (np: example.com/#germany activates Germany on the map)

  $('#es').find('a').each(function(){
    if($(this).attr('href')===window.location.hash){
      $(this).addClass('active');

      // plus an event for the active country

     }
   });

*/
});
