$(document).ready(function(){
	$('.item a').each(function(){
		$(this).modal({
			xhr:$(this).attr('href'),
			closeHandler:"#close"
		}).bind('modalLoad', function(){
			document.location.hash = 'navrh-'+$(this).attr('href').replace(/[^=]+=/,'');
			$('#modal').delegate('a','click',function(){
				if($(this).is('.originallinka')){
					return true;
				}
				document.location.hash = 'navrh-'+$(this).attr('href').replace(/[^=]+=/,'');
				$('#modal .modal-content').load($(this).attr('href'));
				return false;
			});
			$('#modal').delegate('#emailform','submit',function(){
				$.post($('#emailform').attr('action'),$('#modal #emailform').serialize(),function(data){
					window.reloadOnCloseModal = 1; //po odeslani chceme reload
					$('#modal .modal-content').html(data);
				});
				return false;
			});
			$('#modal').delegate('#fbform','submit',function(){
				$.post($('#fbform').attr('action'),$('#modal #fbform').serialize(),function(data){
					window.reloadOnCloseModal = 1; //po odeslani chceme reload
					$('#modal .modal-content').html(data);
				});
				return false;
			});
		}).bind('modalUnload',function(){
			if(typeof(window.reloadOnCloseModal) != 'undefined'){
				document.location.hash = '';
				document.location.reload();
			}

		});
	});


	if(document.location.hash.toString().match(/navrh-\d+/)){
		var id = document.location.hash.toString().replace('#','');
		$('#'+id+" a:eq(0)").click();
	}



});
