
$(document).ready(function() {
  
  //when page loads get the id of the selected menu
  var curmenuid = $('#nav_level1').find('li.selected').attr('id');
  if (curmenuid == null) { curmenuid = 1102;  }  //for homepage, none will be selected so default to Our Firm
  else {curmenuid = curmenuid.substr(4); }

  
  //$('#scrollbar1').tinyscrollbar();
 
  $('#nav_level1 li').hover(function () {
      //$(this).css('background-color','#895726');
      $(this).find('a').css('border-bottom','solid 2px #C6A058');
      $('.nav_level2').addClass('hidden');
      var lid = $(this).attr('id');
      lid = lid.substr(lid.indexOf('_')+1);
      $('#level2_' + lid).removeClass('hidden');
  }, function () {
      //$(this).css('background-color','transparent');
      $(this).find('a').css('border-bottom','none');
      $('.nav_level2').addClass('hidden');
      $('#level2_' + curmenuid).removeClass('hidden');      
  });
  
  $('.nav_level2').hover (function (){
      $('.nav_level2').addClass('hidden');
      $(this).removeClass('hidden');
  },function () {
      $('.nav_level2').addClass('hidden');
      $('#level2_' + curmenuid).removeClass('hidden');
  });
       
  // EDLaw Blue Button hover       
  $('.edlbutton').hover(function () {
      $(this).css("background-image", $(this).css("background-image").replace('_up.png', '_ov.png'));
      $(this).parent().find('.edlbuttonleftend').css("background-image", $(this).parent().find('.edlbuttonleftend').css("background-image").replace('_up.png', '_ov.png'));
      $(this).parent().find('.edlbuttonrightend').css("background-image", $(this).parent().find('.edlbuttonrightend').css("background-image").replace('_up.png', '_ov.png'));
  }, function () {
      $(this).css("background-image", $(this).css("background-image").replace('_ov.png', '_up.png'));
      $(this).parent().find('.edlbuttonleftend').css("background-image", $(this).parent().find('.edlbuttonleftend').css("background-image").replace('_ov.png', '_up.png'));
      $(this).parent().find('.edlbuttonrightend').css("background-image", $(this).parent().find('.edlbuttonrightend').css("background-image").replace('_ov.png', '_up.png'));
  });
  
  
    $(".edlbutton2").hover(function () {
        $(this).attr("src", $(this).attr("src").replace('_up', '_ov'));

    }, function () {
        $(this).attr("src", $(this).attr("src").replace('_ov', '_up'));
    });
  
  // text box code to remove helper text from text boxes on the form
  $("#searchbox, #searchbox2, #searchbox3").click(function () {
       var cl = $(this).attr('class');
       if (cl.indexOf('hasvalue') < 0) $(this).val('');  //if first click (class not added yet), clear the helper value, but not the user entered value
       $(this).addClass('hasvalue');                     //change the class (color) for the user entered value
  });
  
  //---------------------------------------------------------------------------------
  // Do the search. There are 3 search boxes - one in shop area, one in site header and one on search results page
  
  //Shopping pages left nav search box
  $('.searchnow').live('click', function(){    
    var strSearch = $('#searchbox').val();
    $(this).attr('href','/search-results.aspx?q='+strSearch);
  });
  
  //do the search when enter key is pressed
  $('#searchbox').bind('keypress', function(e) {         
        if(e.keyCode==13){ 
           var strSearch = $('#searchbox').val();
          $('.searchnow').attr('href','/search-results.aspx?q='+strSearch);
          e.preventDefault();
          location.href = $('.searchnow').attr('href'); 
        } 
  }); 
  
  //Search Results page search box
  $('.searchnow2').live('click', function(){    
    var strSearch = $('#searchbox2').val();
    $(this).attr('href','/search-results.aspx?q='+strSearch);
  });
  
  //do the search when enter key is pressed
  $('#searchbox2').bind('keypress', function(e) {         
        if(e.keyCode==13){
           var strSearch = $('#searchbox2').val();
          $('.searchnow2').attr('href','/search-results.aspx?q='+strSearch);
          e.preventDefault();
          location.href = $('.searchnow2').attr('href');        
        }
  });
  
  //Site header search box
  $('.searchnow3').live('click', function(){    
    var strSearch = $('#searchbox3').val();
    $(this).attr('href','/search-results.aspx?q='+strSearch);
  });
  
  //do the search when enter key is pressed
  $('#searchbox3').bind('keypress', function(e) {         
        if(e.keyCode==13){
          var strSearch = $('#searchbox3').val();
          $('.searchnow3').attr('href','/search-results.aspx?q='+strSearch);
          e.preventDefault();
          location.href = $('.searchnow3').attr('href');      
        }
  });
  
  //--------------------------------------
  
   //create the popup for the item detail 
   $('.showdetail').each(function() {       
         $.data(this, 'dialog',        
                $(this).next('.shopdetail').dialog({
                  autoOpen: false,           
                  modal: true,           
                  draggable: true,
                  width: 500
                })     
               );     
       }).click(function() {         
         $.data(this, 'dialog').dialog('open');         
         return false;     
       }); 

      //Load the slideshow
          theRotator();
        
      $('#searchbox').removeClass('hasvalue').addClass('ready').val("Search...");
});
