try {
  $(document).ready(function() {  
    
    $(".popup").fancybox({
      'autoScale' : true,
      'scrolling' : 'auto',
      'centerOnScroll' : true
    });
    
    // Funkce pro rotaci banneru na HP START
    try {
      $('#slider').cycle({
        fx: 'scrollVert',
        speed: 500,
        pause: 1,
        timeout: 4000,
        delay: 500,
        prev: '#slider_next',
        next: '#slider_prev'
      });
    } catch(err) {}
    // Funkce pro rotaci banneru na HP END
    
    // Funkce pro obrazkovy slider u referenci START
    try {
      $('#carousel').jcarousel({scroll:1});
    } catch(err) {}
    // Funkce pro obrazkovy slider u referenci END
    
    // Funkce pro skryvani/odkryvani v sekci nas tym START
    try {
      $("#ourTeam .btn").click(function(){
        var box = $(this).parents(".boxEnv");
        
        $(box).toggleClass('hide');
      });
    } catch(err) {}
    // Funkce pro skryvani/odkryvani v sekci nas tym END
    
    // Funkce pro stylovani file inputu START
    try {
      $(".inputFile").filestyle({ 
         image: "/img/btnBrowse.png",
         imageheight : 34,
         imagewidth : 88,
         width : 192,
         Height : 30
     });
    } catch(err) {}
   // Funkce pro stylovani file inputu END
   
   // Funkce pro pridani noveho file inputu START
   try {
      $("#newFile").click(function(){
        var env = $('<div class="env"></div>');
        var delBtn = $('<a title="Odstranit">x</a>');
        
        
        delBtn.click(function(){
          var thisId = $(this).attr("href");
          var parent = $(thisId).closest(".env");
          parent.remove();
          return false;
        });
        
        
        var input = $('<input class="file inputFile" title="Životopis" type="file" />');
        //var input = $("#cv").clone();
        var count = $(".inputFile").length;
        input.attr("name","NewFile"+count);
        input.attr("id","cv"+count);
        input.attr("title","Další soubor");
        delBtn.attr("href","#cv"+count);
        env.append(delBtn).append(input);
        $("#newFileBox").append(env);
        count++;
        $(input).filestyle({
          image: "/img/btnBrowse.png",
          imageheight : 34,
          imagewidth : 88,
          width : 192,
          Height : 30
        });
        return false;
      });
    } catch (err) {
      //console.log('Chyba newFile');
    }
    // Funkce pro pridani noveho file inputu END
    
    // Funkce pro pricitani / odcitani ciselne hodnoty inputu START
    try {
      $("#countPerson_plus").click(function(){
        var countPerson = $("#countPerson").val();
        var size = $("#countPerson").attr('size');
        
        if ($("#countPerson").attr('size')) {
          if(countPerson < size) {
            countPerson++;  
          }
        } else {
          countPerson++;
        }
        $("#countPerson").val(countPerson);
        
      });
    } catch(err) {
      //console.log('Chyba countPerson_plus');
    }
    
    try {
      $("#countPerson_minus").click(function(){
        var countPerson = $("#countPerson").val();
        if(countPerson != 1) {
          countPerson--;
          $("#countPerson").val(countPerson);
        } 
      });
    } catch(err) {
      //console.log('Chyba countPerson_minus');
    }
    // Funkce pro pricitani / odcitani ciselne hodnoty inputu END
    
    // Funkce pro zobrozavátí tipů u rozcestníku START
    try {
      var positionIndex;
    	var copyObject;
    	var selectStr;
    	var envelope = $('<div id="positionEnvelope"></div>');
    
    	$("#bubleDesc td").each(function(){
        $(this).attr("rel", $(this).index());
    	});
    
    	$("#buble tr:first td").hover(
    		// on
    		function(){
    
    			// zjisteni pozice a selektoru
    			position = $(this).index();
    			selectStr = "#bubleDesc>td:eq("+ position +") table";
    
    			// zkopirovani objektu, nastaveni ID, pripojeni do DOMu a ukazani
    			copyObject = $(selectStr).clone();
    			copyObject.attr("id","positionTable");
    									
    			copyObject.appendTo(envelope);
    			envelope.appendTo($(this));
    			
    			copyObject.fadeIn(200);
    
    		},
    		// off
    		function(){
    			// smazani zkopirovaneho objektu z DOMu
    			copyObject.remove();
    		}
    	);
    } catch(err) {}
  	// Funkce pro zobrozavátí tipů u rozcestníku END
    
    
  	$("#ftrRss").mousedown(function(){ pageTracker._trackPageview('/rss/'); });
  	$("#ftrFacebook").mousedown(function(){ pageTracker._trackPageview('/facebook/'); });
  	$("#ftrTwitter").mousedown(function(){ pageTracker._trackPageview('/twitter/'); });
  
  	$("#iRss").mousedown(function(){ pageTracker._trackPageview('/rss/'); });
  	$("#iFacebook").mousedown(function(){ pageTracker._trackPageview('/facebook/'); });
  	$("#iTwitter").mousedown(function(){ pageTracker._trackPageview('/twitter/'); });
  
  	//$("#jmeno").focus();
  	$("#popDetailTable").hide();		
  	$("#popDetailChbx").click( function(){ $("#popDetailTable").toggle(); });
  
  	/* form sjednat schuzku START */
    $("#plAcomware").show();	
  	$(".inradio").change(function(){
  		var rel = $(this).attr("rel");
  		var sRel = "#"+rel;
  		
  		$(".pl").hide();
  		$(sRel).show();
  		
  	});
  	$("#Praha, .Praha").show();
  	
  	try {
  	$("#map").ndMaps({mapCenter:[50.066297, 14.535619], mapZoom:19, mapZoomMarker:16, mapWidth: 425, mapHeight: 425, markersIco: ["/img/ico.png","/img/ico.png","/img/ico.png"], markersSource:"/_js/mapPoints.js"});
    $("#map").ndMaps.showMarker(1);
  	
    $("#selMeetingAddress").change(function(){
      if( $(this).find("option:selected") ) {
        var selId = $(this).find("option:selected").attr("id");
        var selMeeting = $(this).find("option:selected").val();
        var sSelMeeting = "#"+selMeeting;
        var sMap = "."+selMeeting;
        
        $(".address").hide();
        $(".map").hide();
        
        $(sSelMeeting).show();
        $(sMap).show();
        
        $("#map").ndMaps.showMarker(selId);
      }
  		
  	});
  	
  	
  	
  	} catch(err) {
    
    }
    
    try {
      $("#clientMap").ndMaps({mapCenter:[49.889, 15.402], mapZoom:7, mapZoomMarker:10, mapWidth: 605, mapHeight: 400, markersIco: ["/img/ico.png"], markersSource:"/reference/map-points/", markersClustering:true});
      //$("#clientMap").ndMaps({mapCenter:[49.889, 15.402], mapZoom:7, mapZoomMarker:10, mapWidth: 605, mapHeight: 400, markersIco: ["/img/ico.png"], markersSource:"/_js/testPoints2.js"});
    } catch(err) {
    
    }
    
  	//$("#map").ndMaps({mapCenter:[50.06651, 14.53564], mapZoom:16, mapWidth: 425, mapHeight: 425, markersIco: ["/img/ico.png"], markersSource:'/_js/mapPoints.js' });
    //$("#map").ndMaps.showMarker(2);
    /* form sjednat schuzku END */
  
  	if( $(".artDetail img").attr("align")=="left" ){
  		$(".artDetail img").addClass("imgLeft");
  	}
  	if( $(".artDetail img").attr("align")=="right" ){
  		$(".artDetailimg").addClass("imgRight");
  	}
  
    	// definice menu
    try {
      $("#header").ndMenu();
    	$("#form").ndFormValidator({autoSizeAlert:"false"});
    	$("#miniContact").ndFormValidator({autoSizeAlert:"false"});
    	$("#newsForm").ndFormValidator({autoSizeAlert:"false"});
  	} catch(err) {
    
    }
  	
  	$('a.nw').click( function() {
  		window.open( $(this).attr('href') );
  		return false;
  	});	
  	
  	// --------------------
  	
  	$("#dotaznikLink").click(function(){
  		$("#feedbackOverlay").show();
  		$("#feedback").show();		
  		return false;
  	});
  	// po odeslani formu, zobraz form znova kvuli podekovani
  	$("#feedbackOverlay.show").css('display','block');
  	$("#feedback.show").css('display','block');
  			
  	// klikani na ikonky
  	$("#feedback .icons .item").click(function(){			
  		var myRel = $(this).attr("rel");
  		$("#satisfactionIndex").val(myRel);
  		$("#feedback .icons .item").removeClass("active");
  		$(this).addClass("active");	
  		return false;
  	});
  	
  	// zavreni formulare
  	$("#closeFeedback, .closeBtn, .feedbackClose").click(function(){
  		$("#feedbackOverlay").hide();
  		$("#feedback").hide();
  		return false;
  	});
  	
  	// automaticke vybrani emailu
  	$("#feedbackEmail").click(function(){ 
  		if( $(this).val() == '@' ){ $(this).select(); }			
  	});	
  	
  	$("#feedbackMessage").click(function(){
  		if( $(this).val() == ' ' ){ $(this).val(""); }
  	});
  	
  	// --------------------
  	
  	$("#verticalTabs2-env .text").hide();
  	$("#verticalTabs2-env #c1.text").show();
  	
  // MARTIN 37706 
  	var pocetTabu = $("#control li").length;
  	var randomNumber = Math.floor(Math.random()*pocetTabu);
  	
  		$("#verticalTabs2-env .text").hide();
  		$("#verticalTabs2-env .text").each(function(i){
  			if(i == randomNumber)
  				$(this).show();
  		});
  		$("#control ul li a").each(function(i){
  			if(i == randomNumber)
  				$(this).addClass("active");
  		});
  
  
  	
  	
  	
  	
  
  	$("#control a").click(function(){
  		var myHref = $(this).attr("href");	// ziskani retezce z odkazu
  			myHref = myHref.substring(1);	// odseknuti #
  		
  		$("#control a").removeClass("active");
  		$(this).addClass("active");
  		
  		// prace s obsahovymi prvky
  		$("#verticalTabs2-env .text").hide();
  		$("#verticalTabs2-env .text").each(function(){				
  			if( $(this).attr("id") == myHref ){ $(this).show(); }
  		});
  		
  		return false;			
  	});
  	
  	/* novy mini formular */
  	try {
  	$("#minicontact2").ndFormValidator({errorToAlert: "true"});
  	
  	$("#yourMessage")
  	.click(function(){
  		if( $(this).val() == "Zpráva pro nás..." ){
  			$(this).text("");
  		}
  	})
  	.blur(function(){
  		if( $(this).val() == "" ){
  			$(this).text("Zpráva pro nás...");
  		}
  	});
  	
  	$(".submiter").hover(
  		function(){ $(this).addClass("btnHover"); },
  		function(){ $(this).removeClass("btnHover"); }		
  	);
  	
  	// formular misto konani
  	var jednotkovaCena = $("#jednotkovaCena").val();		
  	if( jednotkovaCena > 0 ){
  		$("#celkovaCenaVal").text( jednotkovaCena +" Kč bez DPH" );
  		$("#celkovaCena").val( jednotkovaCena );
  
  		// ovladaci prvek
  		$("input.number").ndInputs({min:1, max:10});
  
  		// prepocitani hodnoty
  		$(".number-env .ctrl").click(function(){
  			var thisInput = $(this).parents(".number-env").find(".number").val();
  			$("#celkovaCenaVal").text();
  			$("#celkovaCenaVal").text( thisInput * jednotkovaCena +" Kč bez DPH");
  			$("#celkovaCena").val( thisInput * jednotkovaCena );
  		});
  		
  		$(".number").change(function(){
  			var myVal = parseInt( $(this).val() );
  			var maximumMist = parseInt($("#maximumMist").val());
  			
  			if( myVal > 0 && myVal <= maximumMist ){
  				var thisInput = $(this).parents(".number-env").find(".number").val();									
  				$("#celkovaCenaVal").text();
  				$("#celkovaCenaVal").text( thisInput * jednotkovaCena +" Kč bez DPH");
  				$("#celkovaCena").val( thisInput * jednotkovaCena );				
  			}
  			else{
  				$(this).focus();
  				alert("Zadejte počet míst v rozmezí 1 - "+ maximumMist );				
  				return false;
  			}
  			
  		});						
  	}
  	
  	$("textarea").click(function(){
  		var thisVal = $(this).val();
  		if( thisVal == ' ' ){ $(this).val(''); }
  	});
  	
  	} catch(err) {
    
    }
    
    /* popUp okno pro PF 2011 START */
		/*if(readCookie("popUp") == null) {  
      $("#popUpFull").show();
      $(".closeBtn").click(function(){
        $("#popUpFull").hide();
      });
      createCookie("popUp","true",1);
    }*/
    /* popUp okno pro PF 2011 END */
  	
  });
} catch(err) {}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}
	

function random(X){
    return Math.floor(X * (Math.random() % 1));
}

function randomBetween(MinV, MaxV){
  return MinV + random(MaxV - MinV + 1);
}


function GenerateCustomFckGallery(files_array)
{
		var result="";
		for (var a=0;a<files_array.length;a++)
			result+="<a href=\""+files_array[a].path+"\" class=\"nyroModal\" rel=\"lightbox\"><img alt=\"\" src=\""+files_array[a].thumb+"\" /></a>";
		return result;
}

function newImage(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}

// funkce pro zrušení defaultního textu input pole END

function KillDefaultText(elementValue,elementId) {
  if(document.getElementById(elementId).value == elementValue) {
    document.getElementById(elementId).value = "";
  }
}

// funkce pro zrušení defaultního textu input pole END

// funkce pro zpětné vložení def. textu START

function PasteDefaultText(elementValue,elementId) {
  if(document.getElementById(elementId).value == "") {
    document.getElementById(elementId).value = elementValue;
  }
}

// funkce pro zpětné vložení def. textu END

