//Main Navigation rollover behavior

jQuery(function(){
    
    $("#success_message, #error_message").bind("DOTGO.close_message", function(){
        $(this).animate({opacity: 0}, {duration: "slow", complete: function(){
            $(this).slideUp("medium");
        }});
    })
    .prepend("<span id=\"close_message\">\u2715</span>");
    $("#close_message").click(function(){
        $(this).parent().trigger("DOTGO.close_message");
    });
    
  var listItem = $('#mainNav li.selected');
  var anchorItem = $('#mainNav li a.selected');

  $('#mainNav li:not(li li)').not('.selected').hover(
    function(){
      listItem.removeClass('selected');
      anchorItem.removeClass('selected');
    },
    function(){
      listItem.addClass('selected');
      anchorItem.addClass('selected');
    }
  );

  $('#mainNav li ul').not('.selected ul').hover(
    function(){
      $(this).prev('a').addClass('selected');
      $(this).parent('li').addClass('selected');
    },
    function(){
      $(this).prev('a').removeClass('selected');
      $(this).parent('li').removeClass('selected');
    }
  );

  //hover states for previous and next status buttons
  $("th#next, th#prev").mouseover(function() {
    $(this).addClass("over");
  }).mouseout(function() {
    $(this).removeClass("over");
  });
  
  //table striping
  $(".stripe tr:odd").removeClass("even").addClass("odd");
  $(".stripe tr:even").removeClass("odd").addClass("even");
  $(".revStripe tr:odd").removeClass("odd").addClass("even");
  $(".revStripe tr:even").removeClass("even").addClass("odd");
  
  //Rounded corners for the bottom of tables
  $("table:not(.notRounded) tr:last-child td:first-child").addClass("BL");
  $("table:not(.notRounded) tr:last-child td:last-child").addClass("BR");


  // Reset the scroll to original location
  $('#historyData').scrollTo(0);

  //Table sliding, slide to the next 7 days
  $('th#next a').click(function(){
    $('#historyData').scrollTo('+=458px', 500);

    return false;
  });

  //Table sliding, slide to the previous 7 days
  $('th#prev a').click(function(){
    $('#historyData').scrollTo('-=458px', 500);
    return false;
  });

  //round corners of non-button elements
  $('.rounded').corner("11px");
  $('.roundedbb').corner("11px ");

  // carousel for scrolling logos on main page
  $(".carousel").jCarouselLite({
      visible: 5,
      auto: 2500,
      speed: 1250
  });

  
  // tables with an expandable row (class "details")
  // stripe only odd rows so table looks striped when not expanded
  // all the not('.footer') stuff is cause i got lazy and wanted to allow
  // a table with a single "status" row (e.g. debug log with no data) to
  // display correctly.  Striping should really be done better, tracking
  // i depending on whether the row has details.
  $('.details tr:odd').each(function(i) {
    if(i%2 == 0) {
      $(this).addClass('odd').next("tr:not(.footer)").addClass('detail-odd');
    }
    else {
      $(this).not('.footer').addClass('even').next('tr:not(.footer)').addClass('detail-even');
    }
  });

  $('.details tr:odd').next().not('.footer').hide().children('td');
  $('.details tr:odd').find('a.toggle-details').addClass('plus');
  $('.details tr:odd').find('a.toggle-details').click(function(){
    $(this).parents('tr').next('tr').toggle();
    $(this).toggleClass('plus').toggleClass('minus');
    return false;
  });

  // submit delete form for debug log
  $('#delete-log #delete').click(function(){
    if(confirm('Are you sure you want to permanently delete these events from the log?')) {
      $('#delete-log').submit();
    }
    return false;
  });

  //assigns height to vertical divider based on content
  dividerHeight();

});


//calculate height of vertical divider based on div#content height
function dividerHeight(){
  contentHeight = $('#content').height();
  $('#vertDivMid').css('height', (contentHeight-480)+'px');
}


//select input text onclick in simulator
function highlight(field) {
  field.focus();
  field.select();
}


//typereplacement
Cufon.replace('#contentWrap h1');
Cufon.replace('#contentWrap h2' , { hover: true });
Cufon.replace('#page h2 a' , { hover: true });
Cufon.replace('.roundedBtn em');
Cufon.replace('a.linkButton');

