﻿$(document).ready(function() {
  $('.slideshow').cycle({
    fx: 'fade' // choose your transition type, ex: fade, scrollUp, shuffle, etc...
  });

  $('.lightbox').lightBox({ fixedNavigation: true });
  var id = $('.paragraph_table tr:first-child').attr("style", "background-color:#293169;color:White;font-weight:Bold;padding:0 3px;");

  $("#top-menu li").mouseenter(
  function() {
    var position = $(this).position();   
    $("#" + $(this).attr("id") + "Level2").css("left", position.left);
    //$("#" + $(this).attr("id") + "Level2" + " tr:last-child").css("border-bottom", "none");
    $("#" + $(this).attr("id") + "Level2").css("top", position.top + 31); //$("#top-menu").height());
    $("#" + $(this).attr("id") + "Level2").css("display", "block");

    id = $(this).attr('id') + 'Level2';

    menu = document.getElementById(id);
    if (menu != null)
      menu.canHideYart = false;

  }
  );

  $("#top-menu li").mouseleave(
  function() {
    var id;
    id = $(this).attr('id') + 'Level2';
    var menu;
    menu = document.getElementById(id);
    if (menu != null) {
      menu.canHideYart = true;
      setTimeout("HideMenu('" + id + "')", 50);
    }
  }
  );

  $(".dynamicMenu").mouseenter(
  function() {
    var id, menu;
    id = $(this).attr('id');
    menu = document.getElementById(id);
    menu.canHideYart = false;
  }
  );


  $(".dynamicMenu").mouseleave(
  function() {
    var id, menu;
    id = $(this).attr('id');
    menu = document.getElementById(id);
    menu.canHideYart = true;
    setTimeout("HideMenu('" + id + "')", 50);
  }
  );
  //$(".shoppingBasket").addClass("invisible");

  //  $(".addButton").click(function() {
  //    $(this).after('<div class="notification">2 items added to shopping basket</div>');
  //    var notification = $(this).next();
  //    notification.fadeIn('slow');
  //    setTimeout(function() { notification.fadeOut('slow'); }, 2000);
  //    setTimeout(function() { notification.remove() }, 2500);
  //  });

});

function HideMenu(menu) {

  menu = document.getElementById(menu);
  if (menu.canHideYart == true)
    $('#' + menu.id).css('display', 'none');
}

function AddToShoppingBasket(FKIDDataContent_100_Product, Shopper) 
{
  var id = "#Quantity_" + FKIDDataContent_100_Product;
  var quantity = $(id).attr("value");
  //quantity = parseInt(quantity);
  if(quantity>0)//(typeof quantity) == "number"&& )
      AddToShoppingBasketDirect(FKIDDataContent_100_Product, Shopper, quantity);
  else 
  {
     var buttonID = "#Add_" + FKIDDataContent_100_Product;
     $(buttonID).after('<div class="notification">You must enter a number greater than zero</div>');
     var notification = $(buttonID).next();
     notification.fadeIn('slow');
     setTimeout(function() { notification.fadeOut('slow'); }, 2000);
     setTimeout(function() { notification.remove() }, 2500);
  }
}

function AddToShoppingBasketDirect(FKIDDataContent_100_Product, Shopper, Quantity) {
  //use AJAX
  var address, buttonID;

  buttonID = "#Add_" + FKIDDataContent_100_Product;

  //alert(window.location);
  address = "/ShoppingBasketMethods.aspx";

  $(buttonID).after('<div class="notification">'+Quantity+' items added to shopping basket</div>');
  var notification = $(buttonID).next();
  notification.fadeIn('slow');
  setTimeout(function() { notification.fadeOut('slow'); }, 2000);
 
  if(window.location.toString().indexOf("localhost") != -1)
    address = "/web" + address;

  //ShoppingBasketMethods?FKIDDataContent_100_Product=FKIDDataContent_100_Product&FKOrder=FKOrder&Quantity=Quantity
  $.get(address, { FKIDDataContent_100_Product: FKIDDataContent_100_Product, Shopper: Shopper, Quantity: Quantity });

  setTimeout(function() { notification.remove() }, 2500);
}

