/*
 * Simply tooltips with jQuery. Author: bluszcz (Rafał Zawadzki
 * bluszcz@bluszcz.net). Idea has been taken from:
 * http://www.kriesi.at/wp-content/extra_data/tooltip_tutorial/step1.html
 */

/* show the tooltip with message */
function showTooltip(message) {
  $('#tooltip0a').text(message);
  $('#tooltip0').fadeIn(500);
};




/* hide the tooltip */
function hideTooltip() {
  $('#tooltip0').fadeOut(500);
};

/* catch response and show proper tooltip */
function responseHandler(response) {
  if (response.status == 'ok') {
      $('#footerNewsletterComplete').hide();
      var message = 'Your email has been sent successfully';
  } else {
      var message = response.status;
  };
  showTooltip(message);
};

/* subscribe to newsletter and chechk if email is correct */
function subscribeNewsletter(a) {
  var email = a.val();
  var www = $('#newsletterWWW').val();
  var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
  if(reg.test(email) == false) {
    showTooltip('Email address is not valid');
  } else {
    $.post("/newsletter/ajax/add/", {email: email, www: www},
      responseHandler, "json");
  };
};

$(document).ready(function() {
  $(".mainMenuButton").hover(
    function () {
    bluszcz = $(this);
/*
  border:solid 1px #00a4ff; 
  padding-left:4px; 
  padding-right:4px; 
  -moz-border-radius:0.3em; 
  background-color: #00a4ff;

*/
      $(this).animate({
          border:"solid 1px #00a4ff", 
          paddingLeft:"4px", 
          paddingRight:"4px",
          backgroundColor: "#fdcf18",
          color: "#fff",
        });
    }, 
    function () {
      /*
      $(this).stop().animate({
          paddingLeft:"4px", 
          paddingRight:"4px",
          MozBorderRadius:"0.3em", 
          backgroundColor: "transparent",
          borderColor: "transparent",
        });
        */
      $(this).stop().css({backgroundColor: "transparent", color:"#ffffff"});
    }
  );



  /* this one is used to handle pressing ENTER key */
  $('#newsletterEmail').keypress(function(e){
    if ( e.which == 13 )
      {
        e.preventDefault();
        subscribeNewsletter($('#newsletterEmail'));
      }
  });
});

