jQuery(document).ready(function () {
  //make individual subnav collumns the same height as the container, add right hand border
  jQuery(".topNavCol").css({"height": jQuery("#divTopNav_TopRow_Items").height() + "px","border-right":"solid 1px #555"});
  jQuery(".topNavCol:last").css("border-right","none");

  //check top nav top position
  var navBarHeight = 48;
  var linkAreaHeight = jQuery("#divTopNav_TopRow_Items").height() + parseInt(jQuery("#divTopNav_TopRow_Items").css("padding-top"),10) + parseInt(jQuery("#divTopNav_TopRow_Items").css("padding-bottom"),10);

  jQuery("#divTopNav").css("top",jQuery("#divHeader").height() + parseInt(jQuery("#divHeader").css("padding-top"),10) + parseInt(jQuery("#divHeader").css("padding-bottom"),10) + "px");
  jQuery("#divTopNav_TopRow").css("top",(navBarHeight - linkAreaHeight) + "px");

  //detect "enter" key pressed in search box
  jQuery("#txtSearch").keyup(function(e){
    if(e.keyCode == 13) {
      GoToSearch();
    }
  });
});

//shows ore hides the top nav
function showHideTopNav() {
    var navBarHeight = 48;
    var linkAreaHeight = jQuery("#divTopNav_TopRow_Items").height() + parseInt(jQuery("#divTopNav_TopRow_Items").css("padding-top"),10) + parseInt(jQuery("#divTopNav_TopRow_Items").css("padding-bottom"),10);
      
    if (jQuery("#divTopNav_TopRow").css("top") != navBarHeight + "px") {
        jQuery("#divTopNav_TopRow").animate({ top: navBarHeight + "px" }, "slow");
    }
    else {
        jQuery("#divTopNav_TopRow").animate({ top: (navBarHeight - linkAreaHeight) + "px" }, "slow");
    }
}

function GoToSearch(){
  window.location = "/Home/Search.aspx?query=" + jQuery("#txtSearch").val();
}
