var $tabs;

function mezeruj(nStr)
{
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ' ' + '$2');
	}
	return x1 + x2;
}

function LibJS_ParseCislo(LibJS_Vstup){
    LibJS_Cislo='';
    LibJS_Vstup=LibJS_Vstup.toString();
    for(LibJS_Index=0; LibJS_Index<LibJS_Vstup.length; LibJS_Index++) {
        LibJS_Znak=LibJS_Vstup.charAt(LibJS_Index);
        if (LibJS_Znak==' ')
            LibJS_Znak='';  // mezery ignorovat
            else if (LibJS_Znak==',')  // desetinny carky zmenit na tecky
                LibJS_Znak='.';
		LibJS_Cislo+=LibJS_Znak;
	}
    //if (!isNaN(LibJS_Cislo))
	LibJS_Cislo=LibJS_Cislo*1;
	return LibJS_Cislo;
}
function LibJS_CisloVystup(LibJS_Cislo){
    LibJS_Cislo=LibJS_Cislo.toString();
    LibJS_Pozice=LibJS_Cislo.indexOf('.');
    LibJS_Cislo=LibJS_Cislo.replace('.',',');
    if (LibJS_Pozice==-1)  // desetinna tecka nenalezena
        LibJS_Pozice=LibJS_Cislo.length;
    LibJS_Vystup=LibJS_Cislo.substring(LibJS_Pozice, LibJS_Cislo.length);
    while(LibJS_Pozice>=4) {
        LibJS_Pozice-=3;
        LibJS_Vystup=' '+LibJS_Cislo.substring(LibJS_Pozice, LibJS_Pozice+3)+LibJS_Vystup;
	}
	LibJS_Vystup=LibJS_Cislo.substring(0, LibJS_Pozice)+LibJS_Vystup;
	return LibJS_Vystup;
}



$(document).ready(function() {
	$('.width260 select').selectbox(
		{inputClass: 'selectbox selectboxWidth260'}
	);
	$('.select80 select').selectbox();
	//$('#frmprojectMiniSearchForm-dispozice,#frmprojectMiniSearchForm-plocha,#frmprojectMiniSearchForm-podlazi').selectbox();

	
	$('#search .width335 select').selectbox(
		{inputClass: 'selectbox selectboxWidth335'}
	);
	$('#search .select120 select').selectbox(
		{inputClass: 'selectbox selectboxWidth120'}
	);
	
	$('#form form select').wrap('<div class="form-select" />');
	$('#form form select').selectbox(
		{inputClass: 'selectbox selectboxWidth260'}
	);
	
	$('.sw536 select').selectbox(
		{inputClass: 'selectbox selectboxWidth536'}
	);
	
	$('.sw80 select').selectbox();
	$('.sw47 select').selectbox(
		{inputClass: 'selectbox selectboxWidth47'}
	);
	$('.sw66 select').selectbox(
		{inputClass: 'selectbox selectboxWidth66'}
	);
	
	$(".radek5,.radek6").hide();
	

	$('.sw536 select').change(function() {
/*
    if ( ($(this).val()=='3') || ($(this).val()=='4') || ($(this).val()=='5') ){
      if ( ($(this).val()=='3') || ($(this).val()=='4') ){
	      $(".radek5,.radek6").hide();
				$(".radek6").show();
			}
			if ($(this).val()=='5'){
      	$(".radek5,.radek6").hide();
				$(".radek5").show();
			}
		}
		else{
      $(".radek5,.radek6").hide();
		}
		
		//zmena nadpisu u formulare
		if ( ($(this).val()>'0') && ($(this).val()<='6') ){
		  $(".form h2.cufon").text(formH2[$(this).val()])
		}
*/

		$(this).children().each(function(index) {
			if ($(this).is(":selected")){
				if ( (index=='2') || (index=='3')  || (index=='4')){
				  if ( (index=='2') || (index=='3') ){
			      $(".radek5,.radek6").hide();
						$(".radek6").show();
					}
					if (index=='4'){
		      	$(".radek5,.radek6").hide();
						$(".radek5").show();
					}

				}
					else{
			      $(".radek5,.radek6").hide();
					}
				//zmena nadpisu u formulare
				//$(".form h2.cufon").text(formH2[index]);
			}
	  });

	});
	
	//a totez pri nacteni stranky
	
	$('.sw536 select option').each(function(index) {
			if ($(this).is(":selected")){
				if ( (index=='2') || (index=='3')  || (index=='4')){
				  if ( (index=='2') || (index=='3') ){
			      $(".radek5,.radek6").hide();
						$(".radek6").show();
					}
					if (index=='4'){
		      	$(".radek5,.radek6").hide();
						$(".radek5").show();
					}

				}
					else{
			      $(".radek5,.radek6").hide();
					}
				//zmena nadpisu u formulare
				//$(".form h2.cufon").text(formH2[index]);
			}
	  });

	


//prepinani vyhledavani na HP
  $(".hledani-mapa").addClass("hidden");
	$.each($("#hledani-nav h2"), function(i, val) {
		$(this).click(function(){
		  if( $(this).children("a").hasClass("active") ){
			}
			  else{
			    $(".hledani-nav h2 a").removeClass("active");
			    $(this).children("a").addClass("active"); 
			    $("#hledani-in > div").addClass("hidden");
			    $("#hledani-in > div").eq(i).removeClass("hidden");
			    //Cufon.refresh('.cufon');
				}
			return false;
		})
	});

	if ($("#projekt #tabs").html()){ // to jen aby to nehazelo chyby v konzoli....
	    $tabs = $("#projekt #tabs").tabs({
		show: function(event, ui) {
		//Cufon.refresh('.cufon');
		}
	    });
	}


//hover menu
$("#menu > ul > li").hover(
  function () {
    $(this).addClass("hover-menu");
    $(this).children(".sub-menu").show();
  },
  function () {
    $(this).removeClass("hover-menu");
    $(this).children(".sub-menu").hide();
  }
);


//$("#clanek h1,#clanek h2,#clanek h3").addClass("cufon");
//$(".text h1,.text h2,.text h3").addClass("cufon");


//srovnani bylych boxiku na hp
/*
if ( $("#projekty").height() > $("#hledani").height() )
    boxHeight = $("#projekty").height();
    else
        boxHeight = $("#hledani").height();
*/
$("#projekty .projekt-in").height(220);
$("#hledani-in").height(201);



if ($(".galerie a").html()){
	$(".galerie a[rel='gallery']").lightBox({
	imageBtnClose: '/images/lightbox/close.gif',
	imageBtnPrev: '/images/lightbox/sipka-left.gif',
	imageBtnNext: '/images/lightbox/sipka-right.gif',
	txtImage: 'Obrázek',
	txtOf: 'z'

   });
}

$('.hledani-mapa object').click( function() {
  doOverlayOpen("overlay-mapa");
  return false;
});

// if window is resized then reposition the overlay box
$(window).bind('resize', function() {
  showOverlayBox();
});
// activate when the link with class launchLink is clicked
$('a.overlay').click( function() {
  doOverlayOpen( $(this).attr('rel') );
  return false;
});



// close it when closeLink is clicked
$('.overlayBox a.closeLink').click( function() {
  doOverlayClose();
  return false;
});
$('.overlayBox a.closeLink').livequery("click", function() {
  doOverlayClose();
  $('#overlay-mapa').remove();
  return false;
});


$.each($("#kontakt .form label"), function(i, val) {
    str = $(this).text();
    strn = str.replace("*", "<span class=\"required\">*</span>");
    $(this).html(strn);
});


$.each($("#search table.vypis tbody tr"), function(i, val) {
    if ($(this).children("td").children("a").html()){
        href = $(this).children("td").children("a").attr("href");
        $(this).children("td:not(:last)").addClass("clicable").css("cursor","pointer").attr("href",href);
    }
});
$('td.clicable').click( function() {
  window.location.href=$(this).attr('href');
  return false;
});

$("#search table.vypis tbody tr td").not("#search table.vypis tbody tr td.planekPDF").hover(
  function () {
    $(this).parent().addClass("hover");
  },
  function () {
    $(this).parent().removeClass("hover");
  }
);
$("#search table.vypis tbody tr td.planekPDF").hover(
  function () {
    $(this).addClass("hoverplanekPDF");
  },
  function () {
    $(this).removeClass("hoverplanekPDF");
  }
);

$("#splatkovyKalendar").show();

$("#tabs a").click(function(){
	$(".flashLeftPromo").show();
	$(".novinka").parent().show();
	$("#splatkovyKalendar").parent().hide();
});

$(".cenikSidebarIdentifier").click(function(){
    $(".flashLeftPromo").hide();
    $(".novinka").parent().hide();
    $("#splatkovyKalendar").parent().show();
});

if (location.hash == '#tab-cenik') {
   $(".flashLeftPromo").hide();
   $(".novinka").parent().hide();
   $("#splatkovyKalendar").parent().show();
}

$(".oprojektuSidebarIdentifier").click(function(){
    $("#splatkovyKalendar").parent().show();
});

if (location.hash == '#tab-o-projektu') {
   $("#splatkovyKalendar").parent().show();
}

$('.tab-lokalita-link').click(function() {
    $("#projekt #tabs").tabs('select', 1); 
});

$('.tab-cenik-link').click(function() {
    $("#projekt #tabs").tabs('select', 2); 
});

$('.tab-galerie-link').click(function() {
    $("#projekt #tabs").tabs('select', 3); 
});

$('.tab-standardy-link').click(function() {
    $("#projekt #tabs").tabs('select', 4); 
});

$('.tab-altuality-link').click(function() {
    $("#projekt #tabs").tabs('select', 5); 
});


});

//the status of overlay box
var isOpen = false;
//function to display the box
function showOverlayBox(overlayID) {
	//if box is not set to open then don't do anything
	if( isOpen == false ) return;
	// set the properties of the overlay box, the left and top positions

	$.each($('.overlayBox'), function(i, val) {
	  if ( $(this).attr("id") == overlayID )
	    overlayPosition=i;
	});

	topPozice=$(window).scrollTop() + ( $(window).height() - $('.overlayBox').eq(overlayPosition).height() )/2 -20;
	if(topPozice<0)
	  topPozice=1;
	$('.overlayBox').eq(overlayPosition).css({
		display:'block',
		left:( $(window).width() - $('.overlayBox').width() )/2,
		top:topPozice,
		position:'absolute'
	});
	// set the window background for the overlay. i.e the body becomes darker
	$('.bgCover').css({
		display:'block',
		width: $(window).width(),
		height:$("html").height()
	});
}
function doOverlayOpen(overlayID) {
	//set status to open

	isOpen = true;
	showOverlayBox(overlayID);
	$('.bgCover').css({opacity:0}).animate( {opacity:0.7}, 500 );
/*	$(".overlayBox-head p.cufon").text($(".overlayBox span.nadpis").text());
	Cufon.refresh('.overlayBox-head p.cufon');*///nepouziva se po nahrazeni vice boxema
	// dont follow the link : so return false.
	return false;
}
function doOverlayClose() {
//set status to closed
	isOpen = false;
	$('.overlayBox').css( 'display', 'none' );
	$('.bgCover').hide();
  return true;
}

function goToLocation(link) {
    location.href = link;
}


