jQuery(document).ready(function($){
  
  Cufon.replace('#menu a, .replace, h3, label, #body.get-plansource a, #demo h6', { fontFamily: 'Avenir' });
  
  function reposition() {
    if($("html").height() > $(window).height()) {
      $("#lightBoxes").css("height",$("html").height());
    } else {
      $("#lightBoxes").css("height",$(window).height());
    }
    $("#lightBoxes > div").each(function(){
      $(this).css("marginTop",($(window).height()-$(this).outerHeight())/2);
      $(this).css("top",$(window).scrollTop());
    });
    
  }
  $(window).scroll(reposition);
  $(window).resize(reposition);
  reposition();
  
  var videoCode = $("#video").html();
  $("#video").empty();
  
  function viewDemo(event) {
    event.stopPropagation();
    $("#lightBoxes").show();
    $("#demo").show();
    $("#video").html(videoCode);
    reposition();
  }
  function viewLogin(event) {
    event.stopPropagation();
    $("#lightBoxes").show();
    $("#login").show();
    reposition();
  }
  
  $("#navigation .view-demo a, #viewDemo a:not(h2 a)").click(viewDemo);
  $("#navigation .login a, #viewLogin").click(viewLogin);
  
  function closeLightbox() {
    $("#lightBoxes, #lightBoxes > div").hide();
    $("#video").empty();
  }
  
  $('#lightBoxes, #lightBoxes .closeBtn').click(function() {
      closeLightbox();
  });

  $('#lightBoxes > div').click(function(event){
      event.stopPropagation();
  });
  
  $("#body:not(.contact):not(.blogContent) ul:even").each(function(){
    if($(this).next().is("ul")){
      $(this).addClass("left");
      $(this).next().addClass("right");
      $(this).next().next().addClass("clearfix");
    }
  });
  $("#body.about ul:odd").each(function(){
    if($(this).next().is("ul")){
      $(this).addClass("left");
      $(this).next().addClass("right");
      $(this).next().next().addClass("clearfix");
    }
  });
  var run = true;
  $("#body:not(.contact):not(.blogContent) div:not(.grid):not(.advantage):not(.case-study):odd").each(function(){
    if($(this).is("div") && run === true){
      run = false;
      $(this).addClass("left");
      $(this).next().addClass("right");
      $(this).next().next().addClass("clearfix");
    }
  });
  
  $("#subNav li a").each(function(){
    if($(this).children().is("span")) { } else {
      $(this).append("<span></span>");
    }
  })

  $("#navigation span").css("display","block");
  $("#navigation a, #navigation p").mouseenter(function(){
    $(this).parent().find("span").stop().animate({"opacity": 1}, 500);
  }).mouseleave(function(){
    $(this).parent().find("span").stop().animate({"opacity": 0}, 300);
  });
  
  var dropDownState = "closed";
  var dropDownSI = 350;
  var dropDownSO = 600;
  var dropDownEI = "easeInOutCubic";
  var dropDownEO = "easeOutSine";
  function openDropDown(){
    if(dropDownState == "closed") {
      dropDownState = "";
      $("#menu").stop().animate({"height":"182px"},500,dropDownEI,function(){ dropDownState = "open"; });
    }
  }
  function closeDropDown(){
    if(dropDownState == "open") {
      dropDownState = "";
      $("#menu").stop().animate({"height":"0"},500,dropDownEO,function(){ dropDownState = "closed"; });
    }
  }
  $("#navigation .plansource-for-you a").mouseenter(openDropDown);
  $("#menu").mouseleave(closeDropDown);
  $("#headerHome, #header, .container_12").mousemove(closeDropDown);
  $("#navigation .nav a:not(.plansource-for-you a)").mouseenter(closeDropDown);

  $("#options li, #menu a").mouseenter(function(){
    if($(this).hasClass("active")){}else{
      $(this).stop().animate({"paddingLeft": "5px"}, 300);
    }
  }).mouseleave(function(){
    if($(this).hasClass("active")){}else{
      $(this).stop().animate({"paddingLeft": "0px"}, 300);
    }
  });
  
  function showArrow () {
    $(this).find("span").animate({"opacity":0.75,"right":"10px"},500);
  }
  function hideArrow () {
    $(this).find("span").animate({"opacity":0,"right":"20px"},500);
  }
  $("#subNav a:not(.active):not(.current_page_item a)").hoverIntent({
    sensitivity: 10, // number = sensitivity threshold (must be 1 or higher)
    interval: 100,   // number = milliseconds of polling interval
    over: showArrow,  // function = onMouseOver callback (required)
    timeout: 10,   // number = milliseconds delay before onMouseOut function call
    out: hideArrow    // function = onMouseOut callback (required)
  });
  
  
  $("#partnerTable tr:first td").each(function(){
    $(this).addClass("top");
  });
  $("#partnerTable tr:odd td").each(function(){
    $(this).addClass("odd");
  });
  $("#partnerTable tr:even td").each(function(){
    $(this).addClass("even");
  });
  $("#partnerTable td:nth-child(4n+1)").each(function(){
    $(this).addClass("description");
  });
  $("#partnerTable td:nth-child(4n+2)").each(function(){
    $(this).addClass("leftColumn");
  });
  $("#partnerTable td:nth-child(4n+3)").each(function(){
    $(this).addClass("centerColumn");
  });
  $("#partnerTable td:nth-child(4n+4)").each(function(){
    $(this).addClass("rightColumn");
  });
  
  
  $("input.wpcf7-submit.button").click(function(event){
    if($(".wpcf7-form-control-wrap.inquiring_as option:selected").val() == "Employee") {
      event.stopPropagation();
      event.preventDefault();
      alert("Please contact your employer or benefits broker directly for more information regarding their question. PlanSource is a technology provider for your organization and issues related to your benefit plans or HR related issues should be handled directly by your organization or their benefits broker. Thank you.");
    }
  });
  
  
  
});
