jQuery(function($) {

    if( $('div.insta-popup').size() > 0 ) {
    
        var html = '';
        
        $('div.insta-popup').each( function() {
            html = html + $(this).html();
            $(this).remove();
        });
        
        html = '<div class="content2" style="width: 800px;">'+html+'</div>';
        
        $('body').append('<div style="display: none;"><div id="insta-popup">&nbsp;</div><a href="#insta-popup" id="insta-popup-trigger" class="nod">&nbsp;</a></div>');
        $('a#insta-popup-trigger').fancybox({
            'padding' : 20,
            'hideOnContentClick' : false,
            'autoScale' : false,
            'titleShow' : false,
            'transitionIn' : 'none',
            'transitionOut' : 'none',
            'content' : html
        });
        
        $("a#insta-popup-trigger").trigger("click");
    } 


  /* ---------------------------------------------------------------- 
    jQuery Tabs
  ---------------------------------------------------------------- */
			var tabContainers = $('div.tabs > div');
			tabContainers.hide().filter(':first').show();
			
			$('div.tabs ul.tabNavigation a').click(function () {
				tabContainers.hide();
				tabContainers.filter(this.hash).show();
				$('div.tabs ul.tabNavigation a').removeClass('selected');
				$(this).addClass('selected');
				return false;
			}).filter(':first').click();
			


  /* ----------------------------------------------------------------
    external links
  ---------------------------------------------------------------- */
  $("a[href^=http]").not('.nonewpage').each(function() {
    if (this.href.indexOf(location.hostname) == -1) {
      $(this)
        .addClass('external')
        .click(function() {
          window.open(this.href);
          return false;
        });
    }
  });
  
  $("a[href^=/redirect.php]").each(function() {
    $(this)
      .addClass('external')
      .click(function() {
        window.open(this.href);
        return false;
      });
  });
  
  
  /* ----------------------------------------------------------------
    files
  ---------------------------------------------------------------- */
  $('a[href$=.pdf]').addClass('file');
  $('a[href$=.pdf]').addClass('pdf');
  
  	
  /* ---------------------------------------------------------------- 
    pdf do noveho okna
  ---------------------------------------------------------------- */    
  $("a[href$=pdf]").click(function(){window.open(this.href);return false;});
			
		
  /* ---------------------------------------------------------------- 
    toggle_container
  ---------------------------------------------------------------- */
	$(".toggle_container").hide();

	 $("h2.h2-crumbs, h3.h3-crumbs, p.crumbs").toggle(function(){
		  $(this).addClass("active").find('em').text(''); 
		  }, function () {
		  $(this).removeClass("active").find('em').text('(více...)');
	 });
	
	 $("h2.h2-crumbs, h3.h3-crumbs, p.crumbs").click(function(){
		  $(this).next(".toggle_container").slideToggle("slow,");
	 });
	 
	 $('h2.h2-crumbs a, h3.h3-crumbs a, p.crumbs a').after('&nbsp;&nbsp;<a href="#"><em>(více...)</em></a>');
	 
	 
  /* ---------------------------------------------------------------- 
    lightbox - gallery
  ---------------------------------------------------------------- */
  $('a.iframe').fancybox();
  
  /* other galleries */
    $('a[rel=lightbox]').fancybox({
        'transitionIn' : 'none',
        'transitionOut' : 'none', 
        'titlePosition' : 'over'
    });   
  
  /* ---------------------------------------------------------------- 
    iE6 workaround (hover)
  ---------------------------------------------------------------- */
  if ($.browser.msie && $.browser.version == 6) {
    $('#menu a, #menu li').hover(function() {
      $(this).addClass('hover');
    },
    function() {
      $(this).removeClass('hover');
    });
  }
  
});


  /* ---------------------------------------------------------------- 
    Table rowizer
  ---------------------------------------------------------------- */
  function makeRows( elemntID, startRow, rowClass )
	 {
	 if ( elemntID == null || typeof( elemntID ) == "undefined" ) { return; }
	 if ( startRow == null || typeof( startRow ) == "undefined" ) { startRow = 2; } // by default we start w 2rd row
	 if ( rowClass == null || typeof( rowClass ) == "undefined" ) { rowClass = "bgcolor"; }
	
	 var tabulka = document.getElementById( elemntID );
	 if ( !tabulka || typeof tabulka == "undefined" ) { return; } 
	
	 var typ = tabulka.nodeName;
	 if ( typ != "TABLE" ) { return; } // We need to have a table
	
	 var radky = tabulka.getElementsByTagName("tr");
	 if ( radky.length < startRow ) { return; } // Not needed 
	
	 for( i = startRow; i < radky.length; i = i + 2 )
		{
		radky[i].className = rowClass;
		}
	}
  
  
  
/* zacatek -------------*/
  
  /* --------------------------------------------------------------------
    Seznam smluvnich zarizeni pro Zdravotni asistencni sluzbu Medikompas
  --------------------------------------------------------------------- */ 
  function showThisRegion(region){
		$("#service-department h2, #service-department .fLeft").show();
		$("table.sdresult").hide();
		$("#where h2.regionView").html($("#r"+region).html());
		$("table.i"+region).show();
	}
	function viewNameRegion(region,view){
		if (view=="show"){
			$("#where h2.regionViewShow").show();
			$("#where h2.regionViewShow").html($("#r"+region).html());
		}
		else{
			$("#where h2.regionViewShow").html("");
		}
	}



  /* ---------------------------------------------------------------- 
    Get element
  ---------------------------------------------------------------- */	
  function getById(id) {
	 if(document.getElementById)
		  e=document.getElementById(id);
	 else if(document.all)
		  e=document.all[id];
	 else
		  e=null;
	 return e;
  }
  
  var urlx = new Array();

  var lastPartIndex = null;
  
  function hidePart(pIndex) {
	 if (pIndex != lastPartIndex)	{
		  var part = getById('i'+lastPartIndex);
		  part.style.visibility='hidden';
	 }
	 return false;
  }

  function showPart(pIndex) {
    var part = getById('i'+pIndex);
    lastPartIndex = pIndex;
    part.style.visibility='visible';
    for (var j=1; j<6; j++) {	
      if (j!= lastPartIndex) getById('i'+j).style.visibility='hidden'; 
    }
	 return false;
  }

  /* ---------------------------------------------------------------- 
  Closing flash
---------------------------------------------------------------- */
	function hideLayer(id) {
		document.getElementById(id).style.display = "none";
	}

  /* ---------------------------------------------------------------- 
    Zobrazeni pusobnosti agentur
  ---------------------------------------------------------------- */	
  function showAgencyRegions() {
    var max = 8;
    if (document.getElementById) {
      for (i = 1; i <= max; i++) {
        obj = document.getElementById('agency-'+i);
        if (obj) obj.style.display = "none";
      }

    obj = document.getElementById('interestPlace');
		if(obj.value == 'agentura St�edn� �echy') {
			objDiv = document.getElementById('agency-1');
			if (objDiv) objDiv.style.display = "";
		} else if(obj.value == 'agentura Z�padn� �echy') {
			objDiv = document.getElementById('agency-2');
			if (objDiv) objDiv.style.display = "";
		} else if(obj.value == 'agentura Severn� �echy') {
			objDiv = document.getElementById('agency-3');
			if (objDiv) objDiv.style.display = "";
		} else if(obj.value == 'agentura V�chodn� �echy') {
			objDiv = document.getElementById('agency-4');
			if (objDiv) objDiv.style.display = "";
		} else if(obj.value == 'agentura Ji�n� �echy') {
			objDiv = document.getElementById('agency-5');
			if (objDiv) objDiv.style.display = "";
		} else if(obj.value == 'agentura Severn� Morava') {
			objDiv = document.getElementById('agency-6');
			if (objDiv) objDiv.style.display = "";
		} else if(obj.value == 'agentura St�edn� Morava') {
			objDiv = document.getElementById('agency-7');
			if (objDiv) objDiv.style.display = "";
		} else if(obj.value == 'agentura Ji�n� Morava') {
			objDiv = document.getElementById('agency-8');
			if (objDiv) objDiv.style.display = "";
		}
	}
}

/* hide a banner on hp */
function closeFishyBanner() {
    $.fancybox.close();
}

/* konec ---------- */
