$(function($){

var mapUrl=''; /* path to the .png file;
                  if the map doesn't load properly, replace the direct path to the file, example:
                  var mapUrl='http://example.com/map/de-290px.png'; 
                  by default, the path to the map file is automatically taken by the script, but sometimes (for unknown reasons), this file is not located */
var loadingText="Loading ..."; // the pre-loader text shown when map is loading
var loadingErrorText="No map!"; // the loading error text
var tooltipArrowHeight=4; /* height of the arrow under the 'bubble';
                             You can remove the arrow in the CSS file, 
                             after removal of the arrow set: 
                             var tooltipArrowHeight=0; */
var IdListyAdresow='#addresses'; /* ID for the list of agents addresses
                                    don't forget about hash (#) before name  */

// MULTIPLE-CLICK MODE

var searchLink='search.php'; // search engine url
var searchLinkVar='region'; // variable passing to the search engine
var searchName='Suche'; // text of the search engine link

  $.multipleClickAction = function(e){
    var clickedRegions=[];
    $('#deutschland').find('.active-region').each(function(){ // searching for activated regions (DO NOT EDIT!)
       var url=$(this).children('a').attr('href'); // get urls of activated regions (DO NOT EDIT!)

       // links settings

       var slicedUrl=url.slice(1); // by default, removes hash (#) from the link url
       /* when you're using a safe urls, like: 'search.php?region=bratislavsky-kraj'
          you have to 'cut-off' parameters from the link url, by this function:

          var slicedUrl=url.slice(url.indexOf('?')+8); // removes: '?region=' ... +8 is the number of cut-off characters
       */


       // fill an array of activated regions (DO NOT EDIT!)
       clickedRegions.push(slicedUrl);
    });

    // creates a link to a search engine with the name of selected regions
    $('#search-link').attr('href',searchLink+'?'+searchLinkVar+'='+clickedRegions.join('|'));

   }

// STANDARD FEATURES

  // click on the region
  $.defaultClickAction = function(e){
    var url = $(e).children('a').attr('href'); // get link url of the clicked region (DO NOT EDIT!)

    // by default, clicking on the region moves to the page in the link
//    window.location.href=url; JS: Anker ist auf derselben Seite 

    // displays the agent address of the actived region
    $(IdListyAdresow).find('li:visible').hide();
    $(url).show();
  }

  // double click on the activated region
  $.doubleClickedRegion = function(e){
    // by default, disables the activated region
    $(e).removeClass('active-region');

    // hide agents addresses
    $(IdListyAdresow).find('li:visible').hide();
   }


/* --------------------------------------------------------
   the map starts here

DO NOT EDIT! 

Deutschland, CSS & jQuery clickable map | http://winstonwolf.pl/clickable-maps/deutschland.html
script version: 3.3.2 by Winston Wolf | http://winstonwolf.pl
Copyright (C) 2011 Winston_Wolf | All rights reserved


really, DO NOT EDIT THIS! */
  $('#map-de').prepend('<span id="loader">'+loadingText+'</span>').addClass('script'); $('#deutschland').find('a').hide(); $(IdListyAdresow).find('li').hide(); if($('#map-de').hasClass('multiple-click')){ if(searchLink==''){ searchLink='search.php'; } if(searchLinkVar==''){ searchLinkVar='region'; } if(searchName==''){ searchName='Search'; } $('<a href="'+searchLink+'" id="search-link">'+searchName+'</a>').insertAfter('#deutschland'); } if(mapUrl==''){ var mapUrl=$('#deutschland').css('background-image').replace(/"/g,"").replace(/url\(|\)$/ig, ""); } var mapImg=new Image();
  $(mapImg).load(function(){
    var countRegions=0; $('#loader').fadeOut();
    $('#deutschland').find('li').each(function(){
      var liid=$(this).attr('id'); var code=null; countRegions++;
      switch(liid){case 'de1': case 'de14': case 'de16': spans=33; break; case 'de3': case 'de5': case 'de6': case 'de12': spans=9; break; case 'de9': spans=64; break; case 'de2': case 'de4': case 'de7': case 'de10': spans=42; break; default: spans=25;}
      var tooltipLeft=$(this).children('a').outerWidth()/-2; var tooltipTop=$(this).children('a').outerHeight()*-1-tooltipArrowHeight; if($('#map-de').hasClass('no-tooltip')){ var tooltipTop=0; }
      $(this).prepend('<span class="map" />').append('<span class="bg" />').attr('tabindex',countRegions); for(var i=1;i<spans;i++){$(this).find('.map').append('<span class="s'+i+'" />');}
      $(this).children('a').css({'display':'none','margin-left':tooltipLeft,'margin-top':tooltipTop,'visibility':'visible'});
      if($(this).children('a').hasClass('active-region')){ $(this).addClass('active-region focus'); }
     }).hover(function(){ $.MapHoveredRegion($(this)); },function(){ $.MapUnHoveredRegion($(this)); }).focus(function(){ $.MapHoveredRegion($(this)); }).blur(function(){ $.MapUnHoveredRegion($(this)); }).keypress(function(e){ code=(e.keyCode ? e.keyCode : e.which); if(code==13) $.MapClickedRegion($(this));}).click(function(e){$.MapClickedRegion($(this)); });
   }).error(function(){$('#loader').text(loadingErrorText); $('#deutschland').find('span').hide(); $('#map-de,#deutschland').css({'height':'auto','left':'0','margin':'0 auto'});}).attr('src',mapUrl);
  $.MapClickedRegion = function(e){ if($('#map-de').hasClass('multiple-click')){ if($(e).hasClass('active-region')){ $(e).removeClass('active-region'); } else{ $(e).addClass('active-region'); } $.multipleClickAction(e); } else{ if($(e).hasClass('active-region')){ $.doubleClickedRegion(e); } else{ $('#deutschland').find('.active-region').removeClass('active-region'); $('#deutschland').find('.focus').removeClass('focus'); if($(e).hasClass('active-region')){ $(e).removeClass('active-region focus'); } else{ $(e).addClass('active-region focus').children('a').show(); } $.defaultClickAction(e); } } }
  $.MapHoveredRegion = function(e){ $('#deutschland').find('.active-region').children('a').hide(); $(e).children('a').show(); $(e).addClass('focus'); }
  $.MapUnHoveredRegion = function(e){ $(e).children('a').hide(); if($(e).hasClass('active-region')==false){ $(e).removeClass('focus'); } }
  var loaderLeft=$('#loader').outerWidth()/-2; var loaderTop=$('#loader').outerHeight()/-2; $('#loader').css({'margin-left':loaderLeft,'margin-top':loaderTop});
// end of the map

});
