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

	// 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
	    });

	// Inicializace FancyBox u QR kodu (aby se nepletl s galeriemi, ma jiny REL)      
		$("a[rel^='qr']").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
		}); 
		
		
// pomale odscrollovani nahoru
    $('a[href=#top]').click(function(){
    	$('html, body').animate({scrollTop:0}, 800);
    	return false;
    });	  
	    
// oznacemi externich odkazu
    
    $.expr[':'].external = function(obj){
        return !obj.href.match(/^mailto\:/) && !obj.href.match(/^javascript\:/) && (obj.hostname != location.hostname);     // vybereme pouze externi odkazy
    };
    	// Externi odkazy - otvira do externiho okna
      	$("#page-all a.newWindow:not('.notNewWindow'):not(:has(img))") //  vyhleda vsechny externi odkazy vyjma tech, ktere maji tridu noNewWindow nebo odkazuji pomoci IMG
      		.addClass('link-external')
      		//.append('<span class="h1dden"> (externí odkaz)</span>')     // indikator externiho odkazu pro slepce
      		.click(function(){
      			window.open(this.href);
      			return false;
      		});
    
      	$("#page-all a:external:not('.notNewWindow'):not(:has(img))") //  vyhleda vsechny externi odkazy vyjma tech, ktere maji tridu noNewWindow nebo odkazuji pomoci IMG
      		.addClass('link-external')
      		//.append('<span class="h1dden"> (externí odkaz)</span>')     // indikator externiho odkazu pro slepce
      		.click(function(){
      			window.open(this.href);
      			return false;
      		});
    
    
// bookmarky vsechny otevreme do noveho okna krome specifickych - tedy i ty s obrazky
    $("#page-all .bookmarks a:not(.notNewWindow)")
		//.addClass('bookmarks-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;
		    });  

       
// skryvani formulare v detailu produktu
    $('#ProductInfoForm_Form').slideToggle("0"); // ve vychozim stavu ho skryjeme
	  
	    // skryti
	    $('#ProductInfoForm_Form_link_a').click(function () {
	        $('#ProductInfoForm_Form').slideToggle("slow");
	        $('#ProductInfoForm_Form_a').slideToggle("slow");
		});
	    
	    // obnoveni
	    $('#ProductInfoForm_Form_link_b').click(function () {
	        $('#ProductInfoForm_Form').slideToggle("slow");
	        $('#ProductInfoForm_Form_a').slideToggle("slow");
		});
	    
	    // pokud byl odeslan formik, rozbalime ho (poznam na zaklade kotvy v URL)
	    if ( jQuery.url.attr("anchor") == 'ProductInfoForm' ) {
			$('#ProductInfoForm_Form').slideToggle("slow");
	        $('#ProductInfoForm_Form_a').slideToggle("slow");
		}
		  
        
// dynamicka mapa - planovani cesty
    $('#route-form-title').click(function () {
    	$('#route-form-info').slideToggle("slow");
    	$('#route-form').slideToggle("slow");
      });
    // vychozi stav
    $('#route-form').hide(0);
      
    
//ukonceni fce document ready
});



//----------------------------------------------------
//	P O M O C N E    F U N K C E
//----------------------------------------------------
	
	
	
	function handleLink(linkType,linkValue){
		switch(linkType) { 
		 
		 case "email":
		  _gaq.push(['_trackEvent', 'Email-link', 'launch', linkValue]);
		  break;
		 
		 case "external":
		  _gaq.push(['_trackEvent', 'External-link', 'exit', linkValue]);
		  break;
		 
		 case "file":
		  var fileName = linkValue.substr((linkValue.lastIndexOf("/") + 1));
		  _gaq.push(['_trackEvent', 'File-download', 'download', fileName]);
		  break;
		 default:
		   // we'll be in trouble if we get here;
		 }
		   
		 window.location.href = (linkValue);
	}



	// prepina zobrazeni elementu (skryva ci zobrazuje)
	function toggle(element) {
		if ($.browser.msie && $.browser.version.substr(0,2)=="7.") $('#'+element).toggle("slow"); // kvuli problemu v MSIE7
		else $('#'+element).slideToggle("slow", "swing");
	}
	
	// prepina zobrazeni elementu (skryva ci zobrazuje) a zmeni i styl u triggeru
	function toggleWithArrows(element,trigger) {
		
		toggle(element);
		
		if ( $('#'+trigger).hasClass('ui-icon-circle-triangle-s') ) {
			$('#'+trigger).removeClass('ui-icon-circle-triangle-s');
			$('#'+trigger).addClass("ui-icon-circle-triangle-n");
		}
		else {
			$('#'+trigger).removeClass('ui-icon-circle-triangle-n');
			$('#'+trigger).addClass("ui-icon-circle-triangle-s");
		}
	}


	
	


