$(function () {
    var tabs = [];
    var tabContainers = [];
    $('.tabs ul.tabNavigation a').each(function () {
      // note that this only compares the pathname, not the entire url
      // which actually may be required for a more terse solution.
        //if (this.pathname == window.location.pathname) {
            tabs.push(this);
			$(this.hash).hide();
            tabContainers.push($(this.hash).get(0));
        //}
    });
    
    $(tabs).click(function () {
        // hide all tabs
        $(tabContainers).hide().filter(this.hash).show();
        // set up the selected class
        $(tabs).removeClass('sel');
        $(this).addClass('sel');
        
        return false;
    }).filter(vybraty_kalendar ? ':last' : ':first').click();
    
    $(window).bind('scroll resize', function() {
    	$('#float_banner').animate({top: ($(window).scrollTop() + 0) + 'px'}, 10); 
    });
});

// check, ci je setnute blade_root_path - ak nie, setneme na /
if(!window.blade_root_path)
  blade_root_path = "/";

// otvorenie obrazku v novom okne - picture_show.php
function show_picture(source) {
  window.open(blade_root_path + "picture_show.php?source=" + source, "", "toolbar=no,menubar=no,location=no,directories=no,scrollbars=no,resizable=no,status=no");
}

// otvorenie nahladu na tlac
function print_preview(params) {
  window.open(blade_root_path + 'print.php?' + params, '', 'toolbar=no,menubar=no,location=no,directories=no,scrollbars=yes,resizable=no,status=no,height=600,width=600')	
}

// vseobecna funkcia na zobrazenie / schovanie boxu
function show_hide(block, anch) {
  if($("#" + block).is(":visible")) {
	$("#" + block).slideUp("slow", function() {$(anch).html("zobraziť všetky fotografie")});
  }
  else {
	$("#" + block).slideDown("slow", function() {$(anch).html("schovať fotografie")});
  }
}

// top box na titulke
function top_box_show_hide(num) {
  if(!($("#top-box-" + num).is(":visible"))) {
	for(i = 0; i < top_box_celkom; i++) {
	  if($("#top-box-" + i).is(":visible")) {
	    $("#top-box-a-" + i).removeClass("sel");
		$("#top-box-" + i).fadeOut("normal", function() {$("#top-box-" + num).fadeIn("normal")});
		$("#top-box-a-" + num).addClass("sel");
		break;
	  }
	}
  }
  clearTimeout(top_box_timer);
}

// automaticke tocenie
function top_box_rotate() {
  top_box_i = (top_box_i + 1) % top_box_celkom;
  top_box_show_hide(top_box_i)
  top_box_timer = setTimeout('top_box_rotate()', 10000);
}

// request kalendara
function request_calendar(year, month) {
  $.post(blade_root_path + 'ajax_calendar.php', {'year' : year, 'month' : month}, function(data) {
    $("#kalendar").html(data);
  }, "html");
}

// zvacsenie textu v content boxe
function resize_text(num) {
  for(i = 1; i <= 3; i++)
    $('#resizer' + i).attr('class', '');
  
  $('#resizer' + num).attr('class', 'sel');
  $('#article').css({fontSize: (11 + (num - 1) * 2) + 'px'})
  $('#article h1').css({fontSize: (20 + (num - 1) * 4) + 'px'})
  $('#article h2').css({fontSize: (16 + (num - 1) * 4) + 'px'})
  $('#article h3').css({fontSize: (12 + (num - 1) * 2) + 'px'})
  $('#article p').css({fontSize: (11 + (num - 1) * 2) + 'px'})
  $('#article a').css({fontSize: (11 + (num - 1) * 2) + 'px'})
}

function slide_gallery(folder, inc) {
  for(i = 0; i < gallery_folder_ids.length; i++) {
	if(gallery_folder_ids[i] == folder) {
	  id = i;
	  break;
	}
  }
  
  // ak je mensia ako nula
  if(gallery_folder_counter[id] + inc < 0)
    return;
  
  // ak neexistuje
  if(gallery_folder_counter[id] + inc + 3 > gallery_folder_max[id])
    return;
  
  if(inc > 0) {
    hide = gallery_folder_counter[id];
	show = gallery_folder_counter[id] + inc + 2;
  }
  else {
    hide = gallery_folder_counter[id] + 2;
	show = gallery_folder_counter[id] + inc;
  }
  
  gallery_folder_counter[id] += inc;

  $('#gal_' + folder + '_' + hide).hide('fast', function() {$('#gal_' + folder + '_' + show).show('fast');});
}

