$(document).ready(function() {

	// ovladaci prvek pro vyber data - datepicker
	setupDatepicker();

	// ovladaci prvek pro zmenu casu
	setupTimeControl();

	// Nastavení prvního 3D průvodce
	var swfFile = $("p.swflist a").attr('href');
	$('.video').flash({swf:swfFile,height:268,width:435});
	
	// Nastavení změny průvodce kliknutím na položku v seznamu
	$("p.swflist a").click(function() {
 		$('.video').flash({swf:this.href,height:268,width:435});
		return false;
	});


	//gallery
	$('.gallery a[rel*=lightbox]').lightBox({
		overlayBgColor: '#782328',
		overlayOpacity: 0.8,
		imageLoading: '/images/lightbox-ico-loading.gif',
		imageBtnClose: '/images/lightbox-btn-close.gif',
		imageBtnPrev: '/images/lightbox-btn-prev.gif',
		imageBtnNext: '/images/lightbox-btn-next.gif',
		txtImage: 'Obrázek',
		txtOf: 'z'
	});


});


function setupDatepicker() {
	try {
		$.datepicker.setDefaults($.datepicker.regional['cs']);
		var now = new Date();
		$("#datepicker").attr('value', zeroFill(now.getDate(), 2) + '.' + zeroFill(now.getMonth() + 1, 2) + '.' + now.getFullYear());
		$("#datepicker").datepicker({ showOn: 'button', buttonImage: '/images/cdos/cal.gif', buttonImageOnly: true, prevText: '', nextText: '', dateFormat: 'dd.mm.yy', firstDay: 1 });
	}
	catch (e) { }
}

function setupTimeControl() {
	try {
		var now = new Date();
		$("#thetime").attr('value', zeroFill(now.getHours(), 2) + ':' + zeroFill(now.getMinutes(), 2));
		$("#time-up").click(function() {
			updateTime(1);
		});
		$("#time-down").click(function() {
			updateTime(-1);
		});
	}
	catch (e) { }
}

function updateTime(hourStep) {
	var timeVal = $("#thetime").attr('value');
	var timeSep = timeVal.split(':');
	var h;
	if (!isNaN(timeSep[0])) {
		h = Number(timeSep[0]);
		h += hourStep;
		if (h > 23)
			h = 0;
		else if (h < 0)
			h = 23;
	}
	else {
		h = 12;
	}
	$("#thetime").attr('value', zeroFill(h, 2) + ':00');
}

//1 zmeni na 01
function zeroFill(number, width)
{
	width -= number.toString().length;
	if ( width > 0 ) {
		return new Array( width + (/\./.test( number ) ? 2 : 1) ).join( '0' ) + number;
	}
	return number;
}


