var timer = null;
function slide()
{
	slideSwitch(true);
}

function slideSwitch(nxt)
{
	if (timer)
	{
		window.clearTimeout(timer); 
		timer = null;	
	}
	var $active = $('#header-img IMG.active');
	var $active_tool = $('#img-list-tool A.img-list-item-active');
	
	
	if ( $active.length == 0 ) $active = $('#header-img IMG:last');
	
	if (nxt)
	{
		var $next =  $active.next().length ? $active.next() : $('#header-img IMG:first');
		var $next_tool =  $active_tool.next().length ? $active_tool.next() : $('#img-list-tool A:first');
	}
	else
	{
		var $next =  $active.prev().length ? $active.prev() : $('#header-img IMG:last');
		var $next_tool =  $active_tool.prev().length ? $active_tool.prev() : $('#img-list-tool A:last');
	}
	
	$active_tool.removeClass('img-list-item-active');
	$active_tool.addClass('img-list-item');
	
	$next_tool.removeClass('img-list-item');
	$next_tool.addClass('img-list-item-active');
	
    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
	
	timer = window.setTimeout('slide()',5000);
	
	return false;
}

function PridejPokoj()
{
	var index = parseInt(document.getElementById('form_room_count').value);
	document.getElementById('room_no_'+index).style.display = 'block';
	index++;

	document.getElementById('form_room_count').value = index;
	
	document.getElementById('uber_pokoj').style.display = 'inline';
	if (index>=5)
	{
		document.getElementById('pridej_pokoj').style.display = 'none';
	}
	return false;
}

function UberPokoj()
{
	var index = parseInt(document.getElementById('form_room_count').value);
	index--;
	document.getElementById('room_no_'+index).style.display = 'none';

	document.getElementById('form_room_count').value = index;
	
	document.getElementById('pridej_pokoj').style.display = 'inline';
	if (index<=1)
	{
		document.getElementById('uber_pokoj').style.display = 'none';
	}
	return false;
}

function filterOptions($targetObj, $origObj, min, max)
{
	var sel = $targetObj.val();
	var $clone = $origObj.clone();
	
	$targetObj.find('option').remove();
	$origObj.clone().appendTo($targetObj);
	
	$targetObj.find('option:gt('+max+')').remove();
	$targetObj.find('option:lt('+min+')').remove();
	
	$targetObj.val(sel);
}

var $typy = null, $dospele = null, $deti = null;

function ZmenaKategorie(index)
{
	var kategorie = $('#form_category'+index).val();
	
	if (!$typy)
	{
		$typy = $('#form_type'+index+' option').clone();
		$dospele = $('#form_adult'+index+' option').clone();
	}
	
	// komfort A
	if (kategorie==1)
	{
		// max 3 dospeli
		// pristylka ano, dite6 ano
		
		filterOptions($('#form_type'+index), $typy, 0, 1);
		filterOptions($('#form_adult'+index), $dospele, 0, 2);

		document.getElementById('form_pristylka'+index).disabled = false;
		document.getElementById('form_dite6'+index).disabled = false;
		
		$('#room_no_'+index+' .tourist-pouze-leto').css('display','none');
	}
	
	// komfort B
	if (kategorie==2)
	{
		// max 2 dospeli
		// pristylka ne
		
		filterOptions($('#form_type'+index), $typy, 0, 1);
		filterOptions($('#form_adult'+index), $dospele, 0, 1);
		
		document.getElementById('form_pristylka'+index).checked = false;
		document.getElementById('form_pristylka'+index).disabled = true;
		
		document.getElementById('form_dite6'+index).checked = false;
		document.getElementById('form_dite6'+index).disabled = true;

		$('#room_no_'+index+' .tourist-pouze-leto').css('display','none');
	}

	// Turist
	if (kategorie==3)
	{
		// max 4 dospeli
		filterOptions($('#form_type'+index), $typy, 1, 3);
		filterOptions($('#form_adult'+index), $dospele, 0, 3);

		// pristylka ne
		document.getElementById('form_pristylka'+index).checked = false;
		document.getElementById('form_pristylka'+index).disabled = true;
		
		document.getElementById('form_dite6'+index).checked = false;
		document.getElementById('form_dite6'+index).disabled = true;
		
		$('#room_no_'+index+' .tourist-pouze-leto').css('display','block');
		
	}
	
	
}

function zmenaPoctuLidi(index)
{
	var kategorie = $('#form_category'+index).val();
	if (kategorie==1 && $('#form_adult'+index).val()==3)
	{
		$('#form_pristylka'+index).attr('checked', true);
	}
}
