$(document).ready(function() {
  $(".loading").bind("ajaxSend", function() {
    $(this).show();
    $(this).css("cursor", "wait");
  }).bind("ajaxComplete", function() {
    $(this).hide();  
  });

  $("#noAcctDesc").hide();

  $("#noAcct a").click(function(e) {
    e.preventDefault();
    $("#noAcctDesc").show();
  });

  $(".faqA").hide();
  $(".simItem").hide();
  $("#multiples").hide();

  $("#addMult").click(function(e) {
    e.preventDefault();
    $(".itemQty").hide();
    $("#multiples").show();
  });

  $("#similarItems .1").show();
  $(".categoryViewPageIndex2 .1").addClass("selected");

  $(".categoryViewPageIndex2 a").click(function(e) {
    e.preventDefault();
    clicked = this.className;
    
    $(".simItem").hide();
    $("#similarItems ." + clicked).show();
    
    $(".categoryViewPageIndex2 > a").removeClass("selected");
    $(".categoryViewPageIndex2 ." + clicked).addClass("selected");
  });

  $(".relItem").hide();
  $("#relatedItems .1").show();
  $(".categoryViewPageIndex3 .1").addClass("selected");

  $(".categoryViewPageIndex3 a").click(function(e) {
    e.preventDefault();
    clicked = this.className;
    
    $(".relItem").hide();
    $("#relatedItems ." + clicked).show();
    
    $(".categoryViewPageIndex3 > a").removeClass("selected");
    $(".categoryViewPageIndex3 ." + clicked).addClass("selected");
  });

  $("#whatsNew").corner("6px");
  $("#promotionItem1").corner("6px");
  $("#promotionItem2").corner("6px");
  $("#promotionItem3").corner("6px");
  $("#itemDetailContainer").corner("6px");
  $("#relatedItems").corner("6px");
  $("#customOrder").corner("6px");
  
  $(".zoom").lightBox();
  $(".enlarge").lightBox();
  
  $(".sortDrops select").change(function() {
    $(".topNavBar form").submit();
  });
  
  $(".faqQ").click(function() {
    id = this.id;
    currentClass = $("#" + id + " span").attr("className");

    if (currentClass == "arrowUp") {
      $("#" + id + " span").removeClass("arrowUp");
      $("#" + id + " span").addClass("arrowDown");
      $("#" + id + "a").show();
    } else if (currentClass == "arrowDown") {
      $("#" + id + " span").removeClass("arrowDown");
      $("#" + id + " span").addClass("arrowUp");
      $("#" + id + "a").hide();
    }
  });
  
  $(".searchSubmit").click(function(e) {
    multChild = $(".multList").children();
    chldCnt = multChild.length;
    
    cont = true;
    for (i = 0; i < chldCnt; i++) {
      if (multChild[i].name != null && multChild[i].name.indexOf('itemQty') != -1) {
        if (multChild[i].value > 0) {
          cont = false;
        }
      }
    }
    if ($(".itemQty select").val() == 'NONE' && cont == true) {
        e.preventDefault();
        alert("Please Select A Size");
    }

    var clickedICN = this.value;
    if (clickedICN.indexOf('_') != -1) {
      clickedICN = clickedICN.substring(clickedICN.indexOf('_') + 1);
      clickedICN = clickedICN.substring(0, clickedICN.indexOf('_'));
    }
    var orderQty = $("#" + clickedICN).val();

    if (orderQty == "") {
      e.preventDefault();
      alert("Please Add A Quantity");
    }

    if ($(".cartQty #styledropdown_" + clickedICN).val() == 'NONE') {
      if ($("#multHide").val() != '') {
        e.preventDefault();
        alert("Please Select A Size");
      }
    }
  });

  $(".qtrSelector").corner("6px");
  $(".nomReview").corner("6px");
  $(".flexReview").corner("6px");

  $(".displayRadio").click(function() {
    document.selectType.submit();
  });

  $(".nomineeInfo").hide();
  
  $(".expandNominees").click(function() {
    var showID = this.id;
    var showOrHide = $("#" + showID).text();
    var p = {};
    p['showID'] = showID;

    if (showOrHide == "+") {
      $("#hide_" + showID).show();
      $("#" + showID).text("-");

      $("#showNominees_" + showID).css({
        'border-top' : '1px solid #DDD',
        'border-bottom' : '1px solid #DDD',
        'margin' : '15px',
        'padding' : '5px'
      });
      $("#showNominees_" + showID).load( base_url + 'index.php/champion/viewNominees/', p, function(str) {

      });
    } else {
      $("#hide_" + showID).hide();
      $("#" + showID).text("+");
    }
  });

  $(".expandAwardNominees").click(function() {
    var showID = this.id;
    var showOrHide = $("#" + showID).text();
    var p = {};
    p['showID'] = showID;

    if (showOrHide == "+") {
      $("#hide_" + showID).show();
      $("#" + showID).text("-");

      $("#showNominees_" + showID).css({
        'border-top' : '1px solid #DDD',
        'border-bottom' : '1px solid #DDD',
        'margin' : '15px',
        'padding' : '5px'
      });
      $("#showNominees_" + showID).load( base_url + 'index.php/topsaward/viewNominees/' + expQtr +'/', p, function(str) {

      });
    } else {
      $("#hide_" + showID).hide();
      $("#" + showID).text("+");
    }
  });

  $(".nomAward select").change(function() {
    var tier = $(this).val();
    var nomNum = this.id;
    
    nomNum = nomNum.substring(nomNum.indexOf("_") + 1);
    $.post( base_url + 'index.php/recognition/assignTier/', {
      nomNum: nomNum,
      tier: tier
    });
  });

  $(".nomPrint a").click(function(e) {
    e.preventDefault();
    var link = this.href;
    window.open(link);
    return false;
  });
});

sfHover = function() {
  var sfEls = document.getElementById("tabs").getElementsByTagName("LI");
  var sfEls2 = document.getElementById("category").getElementsByTagName("LI");
  for (var i=0; i<sfEls.length; i++) {
    sfEls[i].onmouseover=function() {
      this.className+=" sfhover";
    }
    sfEls[i].onmouseout=function() {
      this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
    }
  }

  for (var i=0; i<sfEls2.length; i++) {
    sfEls2[i].onmouseover=function() {
      this.className+=" sfhover";
    }
    sfEls2[i].onmouseout=function() {
      this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
    }
  }
}
if (window.attachEvent) window.attachEvent("onload", sfHover);

