  //the status of overlay box
var isOpen = false;
//function to display the box
function showOverlayBox() {
	//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
	//spocitam top pozici
	$('.overlayBox').css({
		display:'block',
		left:( $(window).width() - $('.overlayBox').width() )/2,
		top:$(window).scrollTop() + ( $(window).height() - $('.overlayBox').height() )/2 -20,
		position:'absolute'
	});
//	alert($('.overlayBox').css('top'));
	if ( parseInt($('.overlayBox').css('top')) < 19 )
    $('.overlayBox').css('top',"20px");
	// 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() {
	//set status to open
	

	isOpen = true;
	showOverlayBox();
	$('.bgCover').css({opacity:0}).animate( {opacity:0.7} );
	// dont follow the link : so return false.
	jQuery('#galerie-in .galerie-carousel').jcarousel({
        scroll: 1,
        autoSlide: false,
        wrap: "circular"
  });
	return false;
}
function doOverlayClose() {
        //set status to closed
	isOpen = false;
	$('.overlayBox').css( 'display', 'none' );
	$('.bgCover').hide();
  return true;
}


$(document).ready(function(){

    jQuery('#mycarousel').jcarousel({
        scroll: 1,
        autoSlide: false,
        wrap: "circular"
    });

    jQuery('#eshop-galerie .eshop-carousel').jcarousel({
        scroll: 1,
        autoSlide: false,
        wrap: "circular"
    });
    

  $('.eshop-carousel a').click(function () {
    classFotky = $(this).attr("class");
    srcFotky = $('#galerie .'+classFotky).attr("href");
    $.each($(".galerie-carousel a"), function(i, val) {
      $(this).removeClass("active");
    });
    $('#galerie .'+classFotky).addClass("active");
    $("#galerie ul li a").append('<span class="activeSpan" />');
    $('#galerie .img img').attr("src",srcFotky)
  	doOverlayOpen();
    return false;
  });
  
  $('.overlayBox a.closeLink').click( doOverlayClose );
  
  $('.galerie-carousel a').click(function () {
    $.each($(".galerie-carousel a"), function(i, val) {
      $(this).removeClass("active");
    });
    $(this).addClass("active");
    $('#galerie .img img').attr("src",$(this).attr("href"))
    return false;
  });
  
  $('.kalendar a').click(function () {
    $(this).parent().parent().parent().find("a").removeClass("active");
    $(this).addClass("active");
    mesic = $(this).parents(".kalendar").find("select").val();
    $(this).parents("table").parent().find("input").val( $(this).text()+'.'+ mesic)
    return false;
  });
  


});
