$(document).ready(function(){
	$(function() {
	  $("a[rel^='lightbox']").lightbox();
	});
	  
  $('.box').corner("3px");
  $('#diskuze input, #diskuze textarea').corner("3px");
  $('.prispevek .head').corner("top 3px");
  $('.prispevek').corner("bottom 3px");

  $(function() {
      $("#carusel").jCarouselLite({
    		auto: 6000,
    		speed: 350,
    		visible: 1,
        btnNext: "#btnr",
        btnPrev: "#btnl"
      });
  });
  $(".prvni-strong td:even").css("font-weight", "bold");
  $(".obecna tr:even").addClass("suda");
  $(".obecna tr:odd").addClass("licha");
  
  $('.popis').click(function(){
    if ($(this).next('div').css("display") == "none") 
    {
      $(this).next('div').slideDown();
      $(this).css("background-color","#E5E5E5");
    }
    else
    {
      $(this).next('div').slideUp();
      $(this).css("background-color","#FFF");
    }
  });
  $('.souteze td .linka').click(function(){
    if ($(this).parents("tr").next('tr.a').css("display") == "none") 
    {      
      $(this).parents("tr").next('tr.a').removeClass("none");
    }
    else
    {
      $(this).parents("tr").next('tr.a').addClass("none");
    }
  });
  $('.souteze td .linkb').click(function(){
    if ($(this).parents("tr").next('tr.a').next('tr.b').css("display") == "none") 
    {      
      $(this).parents("tr").next('tr.a').next('tr.b').removeClass("none");
    }
    else
    {
      $(this).parents("tr").next('tr.a').next('tr.b').addClass("none");
    }
  });
});

re = /^[^.]+(\.[^.]+)*@([^.]+[.])+[a-z]{2,4}$/;

function kontrolanews() {
	if (document.news.email.value== ""){
		alert("Prosím, vložte svůj email");
		document.news.email.focus();
		document.news.email.select();
		return false;
	}
	if ( document.news.email.value != "" ) {
		if (re.test(document.news.email.value) == 0) {
			alert ("Emailová adresa není správná");
			document.news.email.focus();
			document.news.email.select();
			return false;
		}
	}
}

function kontroladiskuze() {
	if (document.diskuze.jmeno.value== ""){
		alert("Prosím, vyplňte pole jméno");
		document.diskuze.jmeno.focus();
		document.diskuze.jmeno.select();
		return false;
  }
	if (document.diskuze.textik.value== ""){
		alert("Prosím, vyplňte svůj vzkaz");
		document.diskuze.textik.focus();
		document.diskuze.textik.select();
		return false;
  }
	if (document.diskuze.mat.value != "13"){
		alert("Prosím, 5 + 8 zvládne vypočítat každý");
		document.diskuze.mat.focus();
		document.diskuze.mat.select();
		return false;
  }
}

$(function(){
	var loader=$('#loader');
	var pollcontainer=$('#pollcontainer');
	loader.fadeIn();
	$.get('../poll.php', '', function(data, status){
		pollcontainer.html(data);
		animateResults(pollcontainer);
		pollcontainer.find('#viewresult').click(function(){
			loader.fadeIn();
			$.get('../poll.php', 'result=1', function(data,status){
				pollcontainer.fadeOut(1000, function(){
					$(this).html(data);
					animateResults(this);
				});
				loader.fadeOut();
			});
			return false;
		}).end()
		.find('#pollform').submit(function(){
			var selected_val=$(this).find('input[name=poll]:checked').val();
			if(selected_val!=''){
				loader.fadeIn();
				$.post('../poll.php', $(this).serialize(), function(data, status){
					$('#formcontainer').fadeOut(100, function(){
						$(this).html(data);
						animateResults(this);
						loader.fadeOut();
					});
				});
			}
			return false;
		});
		loader.fadeOut();
	});
	
	function animateResults(data){
		$(data).find('.bar').hide().end().fadeIn('slow', function(){
							$(this).find('.bar').each(function(){
								var bar_width=$(this).css('width');
								$(this).css('width', '0').animate({ width: bar_width }, 1000);
							});
						});
	}
	
});
