jQuery.noConflict();

jQuery(document).ready(function($){


  // clear input when focus
  var clearInputs = $('input.txt.clr');
  clearInputs.blur(function() {
  if($(this).attr('value') == '') {
      $(this).attr('value',$(this).attr('alt'));
    }
  });
  clearInputs.focus(function() {
    if($(this).attr('value') == $(this).attr('alt')) {
      $(this).removeAttr('value');
    }
  });


  // fadeoud success message
  $('.success').animate({opacity: 1.0}, 8000).animate({opacity: 0.0}, 500).slideUp('fast', function() {
    $(this).remove();
  });


  // focus active input
  $("input.txt, textarea.txt").focus(function() {
    $(this).parent().addClass("focusInput")
  });
  $("input.txt, textarea.txt").blur(function() {
    $(this).parent().removeClass("focusInput")
  })
  

  // hover for drop down menu
  $("#navigation menu li.item").hover(function() {
    //$(this).find("ul").slideDown("fast");
    $(this).find("ul").show();
    if($(this).hasClass("active")) { isActive = true; } else { $(this).addClass("active"); isActive = false; }
  }, function() {
    //$(this).find("ul").slideUp("fast");
    $(this).find("ul").hide();
    isActive == false ? $(this).removeClass("active") : '';
  });


  // hover product box
  $(".box").hover(function() {
    
    $(this).css("background-color", "#2c4d65");
    $(this).find(".inner").css("background-position", "right bottom");
  }, function() {
    $(this).css("background-color", "#26465e");
    $(this).find(".inner").css("background-position", "left bottom");
  });


  $(".changeRole").click(function() {
    var idUser = $(this).attr("rel");
    var roleUser = $(this).hasClass("role1") ? 1 : 2;
    var checkedRole = $(this).hasClass("yes") ? 1 : 0;
    $.ajax({
      type: "GET",
      url: "/edit-roles-ajax/",
      data: "id=" + idUser + "&role=" + roleUser + "&checked=" + checkedRole,
      dataType: "json",
      beforeSend: function() {
        $("table.acenter").append("<tr class=\"loader\"><td colspan=\"6\">Ukládám data...</td></tr>");
      },
      success: function(b) {
        $("a#"+b.check+b.id).removeClass("yes no").addClass((b.check == 'check1' ? b.role1 : b.role2));
        $(".loader").remove();
      }
    });
    return false;
  });


  $(".changeGroup").click(function() {
    var idFile = $(this).attr("rel");
    if($(this).hasClass("group1")) { var idGroup = 1; } else if($(this).hasClass("group2")) { var idGroup = 2; } else { var idGroup = 0; }
    var checkedGroup = $(this).hasClass("yes") ? 1 : 0;
    $.ajax({
      type: "GET",
      url: "/attachments-users-ajax/",
      data: "id=" + idFile + "&group=" + idGroup + "&checked=" + checkedGroup,
      dataType: "json",
      beforeSend: function() {
        $("table").append("<tr class=\"loader\"><td colspan=\"7\">Ukládám data...</td></tr>");
      },
      success: function(c) {
        $("a#check"+c.id).removeClass("yes no").addClass(c.checked);
        $(".loader").remove();
      }
    });
    return false;
  });

/*
  $("a.border img").each(function() {
    var anchorHeight = parseInt($(this).parent().height()/2);
    var imgHeight = parseInt($(this).height()/2);
    $(this).css({ marginTop:(80 - imgHeight) + 'px' });
  });
*/
});
