var speed = 'normal';

function showSearchSchool()
{
	var url = 'region=' + $('#region').val();
	url += '&vyraz=' + $('#search-school').val();
	url += '&pouzevyber=' + $('#pouzevyber').val();
	if ($('#zakladni').attr('checked') == true) url += '&zakladni=1';
	if ($('#stredni').attr('checked') == true) url += '&stredni=1';	
	if ($('#in-thickbox').size() == 0) tb_show('Hledej školu', '/hledej-skolu?' + url + '&TB_iframe=true&height=500&width=705', false);
	else window.location.href = '/hledej-skolu?' + url;
	
}

function showTab(code)
{
	$('#rel-all').css('cursor', 'pointer'); // kurzor
	$('#region-box').hide(speed, function() { // skryt stary obsah
		$('#region-box').html($('#region-' + code).html()); // zmena obsahu
		$('#region').val(code); // zmena hodnoty pomocneho pole
		$('#region-box').show(speed, function() { // zobrazit novy obsah
			$('#region-box a').each(function() {
				$(this).click(function() {
					$('#region').val($(this).attr('rel')); // zmena hodnoty pomocneho pole
					showSearchSchool();
					return false;
				});		
			});
		});
	});			
}

function regionsTab()
{
	$('#region-box a').each(function() {
		$(this).click(function() {
			showTab($(this).attr('rel')); // zobrazit dany obsah
			return false;
		});		
	});
}

function returnRegionsTab()
{
	var code = 'all';
	$('#region-box').hide(speed, function() {
		$('#region-box').html($('#region-' + code).html());
		$('#region-box').show(speed, function() {
			regionsTab();
		});
	});
}

function hideComments(list) { $(list).children().each(function(){if ($(this).nextAll().size() > 1) $(this).hide(speed); }); }

function showAllComments(list) {$(list).children().each(function(){$(this).show(speed); }); }

$(document).ready(function(){

	regionsTab();
	
	$('#rel-all').click(function(){returnRegionsTab(); });
	
	$('#searchSchoolForm').submit(function(){showSearchSchool(); return false; });
	$('#topSearchBox').submit(function() {tb_show('Hledej školu', '/hledej-skolu?vyraz=' + $(this).find('input[name=vyraz]').val() + '&TB_iframe=true&height=500&width=705', false); return false; });
	
	$('a[rel=parent]').attr('target', '_parent');
	$('a.select-school').click(function(){var p = window.parent; p.$('#selectedSchoolName').html($(this).attr('title')); p.$('#selectedSchoolId').val($(this).attr('rel')); p.tb_remove(); return false; });
	
	$('a.just-voted').click(function(){jAlert('<p>Nemůžete hlasovat, neboť jste již hlasovali,<br />nebo nejste přihlášeni, nebo jde o Váš vlastní příspěvek.</p>'); return false; });
	
	$('a.comment').toggle(function(){$('#'+$(this).attr('rel')).show(speed); showSmilies($('#'+$(this).attr('rel') + ' .add-smilye')); return false; },function(){$('#'+$(this).attr('rel')).hide(speed); return false; });
	
	$('a.show-all-comments').toggle(function(){showAllComments('#'+$(this).attr('rel')); },function(){hideComments('#'+$(this).attr('rel')); });
	
	$('#show-menu').toggle(function(){$('#main-menu').show(speed); return false; },function(){$('#main-menu').hide(speed); return false; });
	
	$('input.comment-text').livequery('focus', function() {
		parent = $(this).parent();
		parent.html($('#newMessageBox form fieldset').html());
		parent.find('label').remove();
		var menuId = 'smilies-menu' + Math.round(Math.random() * 100000);
		parent.find('ul').attr('id', menuId);
		showSmilies(parent.find('.add-smilye'));
		parent.find('textarea').attr('name', 'FormCO').focus().addClass('comment-text').blur(function() {
			if ($(this).val() == '') hideTextarea[menuId] = setTimeout(function(){parent.html('<input class="comment-text" type="text" name="FormCO" value="Napsat komentář" />');}, 100);
		});
	});


});
