$(function() {

  $('a.external').click(function() {
    window.open($(this).attr("href"));
    return false;
  });

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

  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);
    });
  }

  if ($.ui && $.ui.tabs) {
    $('ul.rate-table-tabs').tabs();
  }
  
  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;
    }
  });
  
  $('.pagination a').each(function() {
    if (!$.uri.param('skip_cache')) {this.href = this.href + "&skip_cache=true"}
  });

});

(function ($) {
  // VERTICALLY ALIGN FUNCTION
  $.fn.vAlign = function() {
  	return this.each(function(i){
  	var ah = $(this).height();
  	var ph = $(this).parent().height();
  	var mh = (ph - ah) / 2;
  	$(this).css('padding-top', mh).css('padding-bottom', mh);
  	});
  };
})(jQuery);