(function($) {

  $.extend({

    // $.cmsSetup();    
    cmsSetup: function() {

      $(':text, :password').addClass('text');
      
      $('ul').each(function() {
        $('li:first', $(this)).addClass('first');
        $('li:last', $(this)).addClass('last');
      });

      $('table.styled tbody tr:even:not(.header)').addClass('alt');

      $('#subscribe').appendTo('#hd .panel li:has(a.subscribe)');

      $('#hd .panel li:has(a.subscribe)').hoverIntent({
        over: function() {
          $('#subscribe').show();
          $('#hd #search').hide();
          $('.subscribe', $(this)).addClass('selected');
        },
        timeout: 500,
        out: function() {
          $('#subscribe').hide();
          $('#hd #search').show();
          $('.subscribe', $(this)).removeClass('selected');
        }
      });
      
      if ($.cookie("is_admin") == "true" && $('meta[name=section_id]')[0] != null) {
        $.get('/admin/mini_admin', {show_draft: $('meta[name=show_draft]')[0].content, section_id: $('meta[name=section_id]')[0].content, mode: $('meta[name=mode]')[0].content, article_id: $('meta[name=article_id]')[0].content, template_name: $('meta[name=template_name]')[0].content}, function (data) {
          $('body').prepend(data);
        });
      }
      
      $('a.external').click(function() {
        window.open($(this).attr("href"));
        return false;
      });

      $('a.new_window, a.new-window').attr("target","_blank");      

      try {
        var select_navigation_settings = {
          attribute: 'value',
          valid_domains: valid_domains,
          showDisclaimer: showDisclaimer
        };
        $('select.navigation option').linkDisclaimer(select_navigation_settings);
      } catch(e) {}
      $('select.navigation').change(function() {
        selected = $(this).find("option:selected")
        if (selected.hasClass('show-disclaimer')) { try {showDisclaimer(selected,select_navigation_settings)} finally {return;}}
        url = selected.attr('value');
        if (url && (url.indexOf('http') == 0 || url.indexOf('/') == 0)) {
          window.location = url;
        }
      });

      $.jQueryRandom = 0;

      $.extend($.expr[":"],  
      {  
          random: function(a, i, m, r) {  
              if (i == 0) {  
                  $.jQueryRandom = Math.floor(Math.random() * r.length);  
              };  
              return i == $.jQueryRandom;  
          }
      });

    }
    
  });

})(jQuery);