$(function() {
	$.datepicker.regional['cs'] = {
                closeText: 'Zavřít',
                prevText: 'Předchozí',
                nextText: 'Další',
                currentText: 'Hoy',
                monthNames: ['Leden','Únor','Březen','Duben','Květen','Červen', 'Červenec','Srpen','Září','Říjen','Listopad','Prosinec'],
                monthNamesShort: ['Le','Ún','Bř','Du','Kv','Čn', 'Čc','Sr','Zá','Ří','Li','Pr'],
                dayNames: ['Neděle','Pondělí','Úterý','Středa','Čtvrtek','Pátek','Sobota'],
                dayNamesShort: ['Ne','Po','Út','St','Čt','Pá','So',],
                dayNamesMin: ['Ne','Po','Út','St','Čt','Pá','So'],
                weekHeader: 'Sm',
                dateFormat: 'dd.mm.yy',
                firstDay: 1,
                isRTL: false,
                showMonthAfterYear: false,
                yearSuffix: ''};

    $.datepicker.setDefaults($.datepicker.regional['cs']);
    $(".datepicker").datepicker();


	//Confirmation dialog
	$('a.confirm_dlg').live('click', function(e) {
        e.preventDefault();

        if (confirm( $(this).data('confirm') )) {
            $.get(this);
        }
    });


	//Toggle box
	$('.toggle_box').live('click', function(e) {
		$('#'+$(this).data('element')).slideToggle(500);

		return false;
	});


	//Carousel item
	$('.jcarousel-item a').live('click', function(e) {
		$('.jcarousel-item a').removeClass('active');
		$(this).addClass('active');

		$('#main_img img').attr('src', $(this).attr('href'));


		var actual = parseInt($('.jcarousel-item a.active').attr('rel'));
		var photos = $('.jcarousel-item a').length;

		if(actual > 1) $('#main_img a.prev_first').attr('class', 'prev');
		else $('#main_img a.prev').attr('class', 'prev_first');

		if(actual == photos) $('#main_img a.next').attr('class', 'next_last');
		else $('#main_img a.next_last').attr('class', 'next');

		return false;
	})


	//Detail gallery
	$('#main_img a').live('click', function(e) {
		var dir = $(this).attr('class');
		var photos = $('.jcarousel-item a').length;
		var actual = parseInt($('.jcarousel-item a.active').attr('rel'));

		if(dir == 'next') {
			var next = actual + 1;
			var thumb = $('.jcarousel-item a[rel="'+next+'"]');

			$('#main_img img').attr('src', thumb.attr('href'));

			$('.jcarousel-item a').removeClass('active');
			thumb.addClass('active');

			if(next == 2) $('#main_img a.prev_first').attr('class', 'prev');
			if(next == photos) $('#main_img a.next').attr('class', 'next_last');
		
		} else if(dir == 'prev') {
			var prev = actual - 1;
			var thumb = $('.jcarousel-item a[rel="'+prev+'"]');

			$('#main_img img').attr('src', thumb.attr('href'));

			$('.jcarousel-item a').removeClass('active');
			thumb.addClass('active');

			if(prev == 1) $('#main_img a.prev').attr('class', 'prev_first');
			if(actual == photos) $('#main_img a.next_last').attr('class', 'next');
		}

		return false;
	})
});
