/*
 * script.js - scripty
 * Autor: Radek Liska, radarfox at seznam.cz 
 */


function loadKalendar(month, year) {
	$('#kalendar').load("/ajax_kalendar.php?month="+month+"&year="+year+"");
}

$(function() {
        $('[rel=foto]').lightBox();
});

$(function() {
        $('[rel=kalendar]').lightBox();
});



function showBox(id) {
	$.cookie(id, 1, { expires: 365 });
	$(id).removeClass('hidden');
}

function hideBox(id) {
	$.cookie(id, 0, { expires: 365 });
	$(id).addClass('hidden');
}

function toggleBox(id) {
	if ($(id).hasClass('hidden')) {
		showBox(id);
	}
	else {
		hideBox(id)
	}
}

function updateBox(id) {
	if ($.cookie(id) == 1) {
		$(id).removeClass('hidden');
	}
	else if ($.cookie(id) == 0) {
		$(id).addClass('hidden');
	}
}

// Skryvani slideshow

function showSlideshow() {
	$.cookie('slideshow', 1);
	$('#all').removeClass('noslide');
}

function hideSlideshow() {
	$.cookie('slideshow', 0);
	$('#all').addClass('noslide');
}

function updateSlideshow() {
	if ($.cookie('slideshow') == 1) {
		$('#all').removeClass('noslide');
	}
	else if ($.cookie('slideshow') == 0) {
		$('#all').addClass('noslide');
	}
}

// Slideshow

var speed = 15000;
var zindex = 0;
var slide = [];
slide[0] = '#head .slideshow .slide.n00';
slide[1] = '#head .slideshow .slide.n01';
slide[2] = '#head .slideshow .slide.n02';
slide[3] = '#head .slideshow .slide.n03';

function startSlide() {
	var random = Math.round(Math.random() * slide.length);
	for(var i = 0; i < slide.length; i++) {
		$(slide[(random + i) % slide.length]).css('z-index', zindex++);
	}
	setTimeout('changeSlide(' + random + ')', speed);
}

function changeSlide(num) {
	$(slide[num]).hide();
	$(slide[num]).css('z-index', zindex++);
	$(slide[num]).fadeIn('slow');
	setTimeout('changeSlide(' + ((num + 1) % slide.length) + ')', speed);
}


// Funkce

$(document).ready(function(){

	// SKRYVANI TOP

	$('#top .control .more a').click(function() {showBox('#top');});
	$('#top .control .less a').click(function() {hideBox('#top');});
	//updateBox('#top');

	// SKRYVANI BOXU

	$('#box01 .header a').click(function(){toggleBox('#box01');});
	updateBox('#box01');

	$('#box02 .header a').click(function(){toggleBox('#box02');});
	updateBox('#box02');

	$('#box03 .header a').click(function(){toggleBox('#box03');});
	updateBox('#box03');

	$('#box04 .header a').click(function(){toggleBox('#box04');});
	updateBox('#box04');

	$('#box05 .header a').click(function(){toggleBox('#box05');});
	updateBox('#box05');

	$('#box06 .header a').click(function(){toggleBox('#box06');});
	updateBox('#box06');

	$('#box07 .header a').click(function(){toggleBox('#box07');});
	updateBox('#box07');

	$('#box08 .header a').click(function(){toggleBox('#box08');});
	updateBox('#box08');

	$('#box09 .header a').click(function(){toggleBox('#box09');});
	updateBox('#box09');

	$('#box10 .header a').click(function(){toggleBox('#box10');});
	updateBox('#box10');

	$('#box11 .header a').click(function(){toggleBox('#box11');});
	updateBox('#box11');

	$('#box12 .header a').click(function(){toggleBox('#box12');});
	updateBox('#box12');

	$('#box13 .header a').click(function(){toggleBox('#box13');});
	updateBox('#box13');

	$('#box14 .header a').click(function(){toggleBox('#box14');});
	updateBox('#box14');

	$('#box15 .header a').click(function(){toggleBox('#box15');});
	updateBox('#box15');

	$('#box16 .header a').click(function(){toggleBox('#box16');});
	updateBox('#box16');

	$('#box17 .header a').click(function(){toggleBox('#box17');});
	updateBox('#box17');

	$('#box18 .header a').click(function(){toggleBox('#box18');});
	updateBox('#box18');

	$('#box19 .header a').click(function(){toggleBox('#box19');});
	updateBox('#box19');

	$('#box20 .header a').click(function(){toggleBox('#box20');});
	updateBox('#box20');

	// SLIDESHOW
	$('#head .slideshow .control .more').click(function(){showSlideshow();});
	$('#head .slideshow .control .less').click(function(){hideSlideshow();});
	updateSlideshow();
	startSlide();
});
