$(document).ready(function() {
	/**
 * Open window handler
 */
	function openWindow(url, menu, name) {
		var menuString = 'yes';
		if (menu === false || menu == 'no') {
			menuString = 'no';
		}

		var winName = name;
		if (name == undefined) {
			var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
			var string_length = 8;
			var randomstring = '';
			for (var i=0; i<string_length; i++) {
				var rnum = Math.floor(Math.random() * chars.length);
				randomstring += chars.substring(rnum,rnum+1);
			}

			winName = randomstring;
		}

		winParams = "toolbar=no,menubar=" + menuString + ",location=no,directories=no,scrollbars=yes,resizable=no,status=no,width=100,height=100";
		newWindow = window.open(url, winName, winParams);
		try {
			newWindow.focus();
		} catch(e) {}
		return newWindow;
	}

	$("a.window").click(function() {
		openWindow($(this).attr("href"), 'no');
		return false;
	});

	// expand boxes

	//$('.expandBoxContent').css('display', 'none')
	
	$('div.expandBox')
		.children('h2')
		.children('a.expand')
		.click(function() {
			$(this)
				.parent('h2')
				.parent('div.expandBox')
				.children('div.expandBoxContent')
				.children('p')
				.children('a.expand')
					.trigger('click')
			return false
		})

	$('div.expandBox')
		.children('div.expandBoxContent')
		.children('p')
		.children('a.expand')
		.click(function() {
			var expandInner =
				$(this)
					.parent('p')
					.parent('div.expandBoxContent')
					.children('div.expandInner')

			expandInner.slideToggle(function() {
				var aExpand =
					$(this)
						.parent('div.expandBoxContent')
						.children('p')
						.children('a.expand')

				if ($(this).css('display') == 'none') {
					aExpand.text('Více informací')
				} else {
					aExpand.text('Méně informací')
				}
			})
			return false
		})

	// end expand boxes


	if (parseInt($('#sessTips').val()) > 0 && parseInt($('#sessTips').val()) < 6) {
		$('#cs-button-tipsContent-'+parseInt($('#sessTips').val())).trigger('click');
	}

});
