/**
 * XenTan site enhancement
 *
 * @author Jim Tunstall <jtunstall@doc-net.com>
 * @copyright Copyright &copy; 2009, Doctor Net Limited
 * @package XenTan
 */
$(document).ready(function(){
   dropdown_menu();

   // :sub-optimal: duplicated code
   // Upper banner
   if ($('#form_newsletter_subscribe').size() > 0) {
      // We have a newsletter signup form on the page
      $('#btn_newsletter_subscribe', $(this)).click(function () {
         // :todo: email validation
         AjaxHandler.process_form( $('#form_newsletter_subscribe').get(0) );
         AjaxHandler.dispatch(function () {
            alert('You have successfully been successfully entered into the XEN-TAN prize draw.');
         }, function() {
            alert('You could not be entered into the XEN-TAN prize draw at this time.  Please try again.');
         });
      });
   };

   // Product details page
   if ($('#form_register_interest').size() > 0) {
      // We have a "register interest" form on the page
      $('#btn_register_interest', $(this)).click(function () {
         // :todo: email validation
         AjaxHandler.process_form( $('#form_register_interest').get(0) );
         AjaxHandler.dispatch(function () {
            alert('You have successfully signed up for product availability alerts');
         }, function() {
            alert('You could not signed up for product availability alerts at this time.  Please try again.');
         });
      });
   };

   //Competition winners page (content section)
   if ($('#form_newsletter_subscribe_alt').size() > 0) {
      // We have a newsletter signup form on the page
      $('#form_newsletter_subscribe_alt', $(this)).click(function () {
         // :todo: email validation
         AjaxHandler.process_form( $('#form_newsletter_subscribe_alt').get(0) );
         AjaxHandler.dispatch(function () {
            alert('You have successfully been successfully entered into the XEN-TAN prize draw.');
         }, function() {
            alert('You could not be entered into the XEN-TAN prize draw at this time.  Please try again.');
         });
      });
   };

   return false;
});

/**
 * Show dropdown menus on (main menu) hover
 */
dropdown_menu = function() {
   // menu dropdown transparency
   $('ul#main_menu ul').fadeTo(0, 0.95);

   $("#main_menu li").hover(
      function () {
         // Show the popup menu directly below the parent menu item, and match the widths.
         $("ul", this).css('top', $(this).outerHeight());
         $("ul", this).css('width', $(this).outerWidth() - 1);

         // Temporary fix. li class first doesn't have left border
         if($(this).attr('class') != 'first') {
            $("ul", this).css('left', -1);
         }

         $("ul", this).show();
      },
      function () {
         $("ul", this).hide();
      }
   );
}

function update_basket_quantity(int_inventory_id) {
   location.href = "/basket/update-quantity/int_inventory_id/"+int_inventory_id+"/int_quantity/"+$("#int_quantity"+int_inventory_id).val();
}