

var open = false;
var opened = false;

function showPanels()
{
	if (open === true)
	{
		$("#panel, #commentsDiv").slideDown(400, function(){

		});
	}

}
function hidePanels()
{
	if (open === false)
	{
		$("#panel, #commentsDiv").slideUp(400, function(){

		});
	}

}



$(document).ready(function(){

	$("#adresa,#tagy").focus(function(){
		$(this).val('').removeClass('sedive');
		$(this).unbind('focus');
	});
	
	$("#nazevapopis").hide();
	$("#tagyamisto").hide();
	
	$("#embedDiv").hide();
	$("#pridatNazev").click(function(){
		$("#pridatNazev").toggleClass('minus');
		$("#nazevapopis").slideToggle(200);
		if ($(this).attr('class') != 'plus minus') 
		{
			$(this).text($("#textAddTitleAndDescription").val());
			$("#desc").val('');
		}
		else
		{
			$(this).text($("#textRemoveTitleAndDescription").val());
		}
		$("#desc").focus();
		
	});
	
	$("#pridatNazev").text($("#textAddTitleAndDescription").val());
	
	
	$("#pridatNazev").show();
	$("#pridatMisto").show();
	

	$("#nazevapopis").hide();
	$("#pridatMisto").click(function(){
		$("#pridatMisto").toggleClass('minus');
		$("#tagyamisto").slideToggle(200);
	});

	


	var b = setTimeout('hidePanels()', 2000);
	
	$('#pozadi').mouseenter(function(){
		var a = setTimeout('showPanels()', 500);
		open = true;

	});

	$('#pozadi').mouseleave(function(){
			if (opened === false)
			{
				var b = setTimeout('hidePanels()', 500);
				open = false;
			}
	});
	/*
	$("#pozadi").mousemove(function(e){
		opened = true;
	});
	*/
	
	// musime nechat otevreno, pokud se edituje
	$("#frm-komentar").focus(function(){
		opened = true;
	});
	$("#frm-komentar").blur(function(){
		opened = false;
	});	


	$("#lng").change(function(){
		
		window.location = '/?lng='+$(this).val();
	});
	
	$("#cojetwio").hide();
	$("#coje").click(function(){
		$("#cojetwio").slideToggle(200);
		return false;
	});


	$("#inByEmail").hide();
	$("#byemail > h2").click(function(){
		$("#inByEmail").slideToggle(200);
		return false;
	});


	$(".closeparent").click(function(){
		$(this).parent().slideUp(200);
		return false;
	});
	
	$("#rotr").click(function(){
		$(".obrazeka").rotateRight();
	});
	$("#rotl").click(function(){
		$(".obrazeka").rotateLeft();
	});
	
	$("#askDelete").click(function(){
		$("#askDeleteDiv").slideDown(200);
		return false;
	});
	
	$("#deleteReasonForm").submit(function(){
		$("#askDeleteDiv").slideUp(200);
		$.post('/?delete=1',{ ido: $("#deleteReasonIDO").val(), reason: $("#deleteReason").val() });
		alert('Žádost odeslána, pokusíme se jí co nejdříve vyřídit.');
		return false;
	});

	$("#embedIt").click(function(){
		$("#embedDiv").slideToggle(200);
	});
	
	$("#galerie > div > p.row2").hide();
	
	$("#galerie > div").hover(function(){
		$(this).find("p.row2").show();
		$(this).find("p.row1").hide();
	},
	function(){
		$(this).find("p.row1").show();
		$(this).find("p.row2").hide();
	});
	

	$(".ajaxLink").click(function(){
		
		$('#' + $(this).attr('rel')).load($(this).attr('href') + '&js=1');
		return false;
		
	});
	
	
	// psani popisu, odecitani znaku
	
	$("#desc").keyup(function(){
		$("#leftChars > div").text($(this).val().length);
		if ($(this).val().length > 120) 
		{
			$("#leftChars > div").css('color', '#be3030');
		}
		else
		{
			$("#leftChars > div").css('color', '');
		}
	});
	
	// steps
	
	$(".stepx, .stepa, #step").hide();

	$("#upload_file").click(function(){
		$('#step').slideDown();

	});

	$(".upload_file").live('click',function(){
		$('.stepa').slideDown();
	});
	
	
	$(".addAnother").live('click', function(){
		$(this).next().slideDown();
		$(this).parents().find('.stepx input[type=file]').first().addClass('upload_file');
		$(this).removeClass('addAnother plus').addClass('remove removeAnother');
		$(this).text($("#textRemoveAnother").val());
		return false;
	});

	$(".removeAnother").live('click', function(){
		$(this).next().slideUp();
		$(this).parents().find('.stepx input[type=file]').first().removeClass('upload_file');
		$(this).parents().find('.stepx input[type=file]').first().val('');
		$(this).removeClass('remove removeAnother').addClass('addAnother plus');
		$(this).text($("#textAddAnother").val());
		return false;
		//console.log($(this).parents().find('.stepx input[type=file]'));
	});	
	
	// doplneni textu
	
	$(".addAnother").text($("#textAddAnother").val());
	
	// velikost podle obrzku (pro original)
	
	if ($("#backToPicture").length > 0) {
		$('.obrazeka').load(function(){
			$("#pozadi").width($(".obrazeka").width() + 20);
		});
	}
	
	$("#tabs").tabs();

});
