/*** SOUBOR OBECNYCH FUNKCIONALIT ***/
$(function(){


// Cufon - Dynamicke nahrazeni fontu
   Cufon.replace($('h1'));  //vyber prvku, kterym se ma zmenit font
   Cufon.replace($('h2'));  //vyber prvku, kterym se ma zmenit font
   Cufon.replace($('h3'));  //vyber prvku, kterym se ma zmenit font
   Cufon.replace($('.submenus h4')); // nadpisy submenu
   Cufon.replace($('h4.NewsBox')); // nadpisy newsboxu
   Cufon.replace($('h4.survey')); // nadpisy boxu s anketou
   Cufon.replace($('h4.related-files')); // souvisejici soubory - nadpisy
   Cufon.replace($('h4.SearchResultsTitle')); // nadpisy vysledku hledani
   Cufon('ul.main-menu', {
	   hover: {
	   color: '#DA251D'
	   }
	   }); 

// Inicializace selektoru  vyhledavaciho INPUTu a napovedneho textu
   populateElement('#search-panel-text', DEFAULT_SEARCH_TEXT_VALUE);   

// pomale odscrollovani nahoru
   $('a[href=#top]').click(function(){
	   $('html, body').animate({scrollTop:0}, 800);
   		return false;
   });
   
  
// odscrollovani na kotvu
   if ( jQuery.url.attr("anchor") != '' ) {
	   $('#'+jQuery.url.attr("anchor")).scrollTo();
   }   
   

// Inicializace SuperFish menu
	if ($.browser.msie) {} // POZOR: v MSIE to dela problem!
	else $('ul.main-menu').superfish();


//Inicializace FancyBox
   //$("a[rel^='lightbox']").fancybox();
   $("a[rel^='lightbox']").fancybox({
      'type' : 'image',  // tento zapis by mel osetrit URL na image ve tvaru "image.php?img=123"  
    	'titlePosition': 'inside',
	    //'transitionIn': 'elastic',
	    'transitionOut': 'elastic',
	    'padding': 12,
	    'margin': 0
    }); 


   
   //var liftoffTime = new Date(); 
   var term1 = new Date(2012,6,1,9,0,0,0); // pozor, mesice se pocitaji od NULY !!! (je treba tedy jeden odecist)
   var term2 = new Date(2012,6,15,9,0,0,0);  // pozor, mesice se pocitaji od NULY !!! (je treba tedy jeden odecist)
   var term3 = new Date(2012,6,29,09,0,0,0);  // pozor, mesice se pocitaji od NULY !!! (je treba tedy jeden odecist)
   //var term4 = new Date(2012,7-1,16,9,0,0,0);  // pozor, mesice se pocitaji od NULY !!! (je treba tedy jeden odecist)
   
   //$("#countdown-2").countdown({until: term2, format: 'dHMS'});
   
   $("#countdown-1").countdown({until: term1});
   $("#countdown-2").countdown({until: term2});
   $("#countdown-3").countdown({until: term3});
   //$("#countdown-4").countdown({until: term4});   
   
   
// Externi odkazy - otvira do externiho okna
   $.expr[':'].external = function(obj){
       return !obj.href.match(/^mailto\:/) && !obj.href.match(/^javascript\:/) && (obj.hostname != location.hostname);     // vybereme pouze externi odkazy
   };
   
   //$('a:external, a.newWindow') // vyhleda vsechny externi odkazy
   $('#page-all a:external:not(:has(img)), #page-all a.newWindow:not(:has(img))') //  vyhleda vsechny externi odkazy vyjma tech, ktere odkazuji pomoci IMG
       .addClass('link-external')
       .click(function(){
           window.open(this.href);
           return false;
       });   
   
   

// oznacime odkazy na emailove adresy
   $.expr[':'].emails = function(obj){
   	  var $this = $(obj);
   	  return (obj.href.match(/^mailto\:/));
   }; 
	    // emailovym odkazum pridat GATC
	    $("a:emails")
			 .addClass('link-email')
			 .click(function(){
				 //_gaq.push(['_trackEvent', 'E-mails', 'Email link click', this.href, 1]); // vcetne "mailto:" a hodnoty
				 _gaq.push(['_trackEvent', 'E-mails', 'Email link click', ((this.href).substr(((this.href).lastIndexOf(":") + 1)))+' ('+CONST_PAGE_TITLE+' ['+CONST_PAGE_ID+'])', 1 ]); // pouze emailova adresa + oznaceni stranky (Titulek [page_id])
			 });    
	    


//oznacime odkazy na soubory v datovem ulozisti (krome obrazkovych)
   $.expr[':'].datafiles = function(obj){
   	  var $this = $(obj);
   	  return ( obj.href.match(/.*(data).*\.([a-zA-Z0-9]){3,4}$/) && !obj.href.match(/.*(data).*\.(jpg|gif|png|JPG|GIF|PNG)$/) );
   }; 
     // souborovym odkazum pridame GATC a otevreme je v novem okne
     $("a:datafiles")
		    .addClass('link-datafile')
		    .click(function(){
		    	//_gaq.push(['_trackEvent', 'Downloads', 'File link click', ((this.href).substr(((this.href).lastIndexOf("/") + 1))), 1]);   // jen nazev souboru + volitelna ciselna hodnota
		    	_gaq.push(['_trackEvent', 'Downloads', 'File link click', this.href, 1]); // nazev souboru s celou cestou
		    	window.open(this.href);
		    	return false;
		    });     
   
   
   
// inicializace Carouselu
   // Automatically click the Next button every 5 secs, with a delay of 2 secs between each click
   $("div.carousel").carousel( { 
           autoSlide: true, 
           autoSlideInterval: 3000,
           delayAutoSlide: 3000,
           dispItems: 1,
           //slideEasing: "easeOutBounce",
           loop: true
          
   } );      
   
   
   
// dynamicka mapa - planovani cesty
   $('#route-form-title').click(function () {
   	$('#route-form-info').slideToggle("slow");
   	$('#route-form').slideToggle("slow");
     });
   // vychozi stav
   $('#route-form').hide(0);   
   
   
   
   
   // skryvani formulare v guestbooku
   
   $('#guestbookInsertForm').slideToggle(0); // ve vychozim stavu ho skryjeme
   
   // skryti formu
   $('#guestbookInsertLink_a').click(function () {
   	$('#guestbookMessageList').slideToggle("slow");
   	$('#guestbookInsertForm').slideToggle("slow");
       $('#guestbookInsertLink_a').slideToggle(0);
       $("#main-title").scrollTo();
     });
   
   // obnoveni
   $('#guestbookInsertLink_b').click(function () {
   	$('#guestbookInsertLink_a').slideToggle(0);
   	$('#guestbookMessageList').slideToggle("slow");
   	$('#guestbookInsertForm').slideToggle("slow");
   	$("#main-title").scrollTo();
     });
   
   // pokud byl odeslan formik, rozbalime ho (poznam na zaklade kotvy v URL)
   if ( jQuery.url.attr("anchor") == 'GBinsert' ) {
   	$('#guestbookMessageList').slideToggle("slow");
   	$('#guestbookInsertForm').slideToggle("slow");
   	$('#guestbookInsertLink_a').slideToggle(0);
   	$("#main-title").scrollTo();
	}
   
   // obnoveni odkazem na kotvu formulare
   $('.formularAnchor').click(function () {
   	//$.scrollToElement( $("#guestbookInsertForm") );
   	$('#guestbookInsertLink_a').slideToggle(0);
   	$('#guestbookMessageList').slideToggle("slow");
   	$('#guestbookInsertForm').slideToggle("slow");
   	$("#main-title").scrollTo();
     });
   
   
   
// vyhledavani - prepinani tabu
   
   $('#search-form-title').click(function () {
   	$('#search-form').slideToggle("slow");
     });
   $('#search-results-title').click(function () {
   	$('#search-results').slideToggle("slow");
     });

   if ( jQuery.url.param("pgContent") ) {
   	showSearchResultsTab('content');
   }
   else if ( jQuery.url.param("pgNews") ) {
   	showSearchResultsTab('news');
   }
   else if ( jQuery.url.param("pgPhotogallery") ) {
   	showSearchResultsTab('photogallery');
   }
   else if ( jQuery.url.param("pgCatalog") ) {
   	showSearchResultsTab('catalog');
   }
   else if ( jQuery.url.param("pgBlog") ) {
   	showSearchResultsTab('blog');
   }
   else if ( jQuery.url.param("pgGuestbok") ) {
   	showSearchResultsTab('guestbook');
   }
   else {
   	showSearchResultsTab('content');
   }   
   
   
   // zalozka "obsah"
   $('#tab-content-tb').click(function () {
   	showSearchResultsTab('content');
     });

   // zalozka "news"
   $('#tab-news-tb').click(function () {
   	showSearchResultsTab('news');
     });    

   // zalozka "fotogalerie"
   $('#tab-photogallery-tb').click(function () {
   	showSearchResultsTab('photogallery');
     });    

   // zalozka "katalog"
   $('#tab-catalog-tb').click(function () {
   	showSearchResultsTab('catalog');
     });    

   // zalozka "blog"
   $('#tab-blog-tb').click(function () {
   	showSearchResultsTab('blog');
     });    

   // zalozka "guestbook"
   $('#tab-guestbook-tb').click(function () {
   	showSearchResultsTab('guestbook');
     });     
   
   
//ukonceni fce document ready
});



