(function($){
  
  // thanks nlogax
  $.fn.outerHtml = function(){
    return this.clone().wrap('<div/>').parent().html();
  };

})(jQuery);

// javascript number format
// '12,345'.replace(/\d(?=(?:\d\d\d)+(?!\d))/g,'$&,'); //=> 12,345

(function($){
  $(document).ready(function(){
    
    // navigation
    $('#navigation li').hover(
      function(){ $(this).addClass('over');     },
      function(){ $(this).removeClass('over');  }
    );
    
    // buttons
    $('button').each(function(){
      var self = $(this);
      var i = self.find('img');
      self.hover(
        function(){
          // mimick javascript negative lookbehind
          // http://blog.stevenlevithan.com/archives/mimic-lookbehind-javascript
          i.attr({src: i.attr('src').replace(/(_on)?\.gif$/, function($0, $1){ return $1?$0:'_on.gif'; })});
        },
        function(){
          i.attr({src: i.attr('src').replace(/_on\.gif$/, '.gif')});
        }
      );    
    });
    
    
    // qtip
    // $('.qtip-help').each(function(){
    //   var self = $(this);
    //   self.find('a').qtip({
    //     content: {
    //       text: self.find('.content')
    //     },
    //     position: {
    //       corner: {
    //          tooltip: 'topRight',
    //          target: 'bottomLeft'
    //       }
    //     },
    //     // debug
    //     // show: {
    //     //   when: {
    //     //     event: 'click'
    //     //   }
    //     // },
    //     // hide: {
    //     //   when: {
    //     //     event: 'click'
    //     //   }
    //     // },
    //     style: {
    //       tip: true,
    //       textAlign: 'left',
    //       padding: '5px',
    //       name: 'green'
    //     }
    //   })
    //   .click(function(){
    //     return false;
    //   });
    // });
  
    
    // markdown
    $(".markdown")
      .find("a:not([href^=/])").attr({target:"_blank"})
      .end()
    ;
    
    // notices
    $(".notice:not(#ticker)").each(function(){
      
      var self = $(this);
      
      // add close button
      self.find(".buttons").append(
        $('<a href="#" title="Hide this notice"><img src="/assets/icons/silk/cross.png" /></a>').click(function(){
          self.slideUp();
          return false;
        })
      );
      
      // auto hide
      setTimeout(function(){
        if(self.is(":visible")){
          self.fadeOut();
        }
      }, 15000);
    });
    
    // tabs
    $(".form_tabs").tabs();
    
    // datepicker
    $(".datepicker").datepicker({dateFormat: "yy-mm-dd"});
    
  });
})(jQuery);

//  table highlighter
//  (function($){
//    $(document).ready(function(){
//      $('table.striped tr:even:not(:first)').addClass('even');
//    });
//  })(jQuery);

var IE6UPDATE_OPTIONS = {
	icons_path: "assets/ie6update/"
};
