var headerDelay = 8000;
var headerTimeout = null;

function switchHeader() {
	var $active = $('#pozadi > :visible');

    if($active.length == 0) {
	    $active = $('#pozadi > :first');
    }

    $active.removeClass('active');

    var $next = $active.next().length ? $active.next()
        : $('#pozadi > :first');

    $next.addClass('active');

	$active.fadeOut(600, function () {
		$next.fadeIn(1400);
	});

	headerTimeout = setTimeout("switchHeader()", headerDelay, 'JavaScript');
}

$(document).ready(function() {
	/** spusteni animace hlavicky */
	var pozadi = $('#pozadi img');

	first = $('#pozadi img:visible:first');
	// var first = pozadi[0]; // prvni
	// var first = pozadi[Math.floor(Math.random() * pozadi.length)]; //nahoda

	$(first).addClass('active');
	$(first).hide();
	$(first).fadeIn(1400);

	if($('#pozadi img').length > 1) {
		headerTimeout = setTimeout("switchHeader();", headerDelay, 'JavaScript');
	}
	
	/** barveni menu */
	$('#menu a').mouseover(function() {
		var rel = $(this).attr('rel');
		$('#' + rel + '.hoverable').next().hide();
		$('#' + rel + '.hoverable').show();
	});
	$('#menu a').mouseout(function() {
		var rel = $(this).attr('rel');
		$('#' + rel + '.hoverable').next().show();
		$('#' + rel + '.hoverable').hide();
	});
	
	$('#' + $('#menu a.active').attr('rel')).show().removeClass('hoverable').next().hide();
	
	/** prejizdeni po ctvercich */
	$('#mrizka .vypln').mouseover(function() {
		$(this).stop();
		$(this).animate({opacity: '0'}, 300, 'swing');
	});
	
	$('#mrizka .vypln').mouseout(function() {
		$(this).stop();
		//$(this).animate({opacity: '0.' + $(this).text()}, 300, 'swing'); // puvodni hodnota
		$(this).animate({opacity: '0.' + Math.floor(Math.random()*70+1)}, 300, 'swing');
	});
	
	/** proklik referenci */
	$('.inner-heading .clickable').click(function() {
		var rok = $(this).find('.t_red').text();
		//alert(rok);
		
		$('.hideable:visible').slideUp('fast', function() {
			$('.group-' + rok).slideDown('fast');
		});
	});
});

