function doPopups() {

  if (!document.getElementsByTagName) return false;

  var links=document.getElementsByTagName("a");

  for (var i=0; i < links.length; i++) {

    if (links[i].className.match("popup")) {

      links[i].onclick=function() {

        window.open(this.href, "");

        return false;

      }

    }

  }

}


/*====

 * new rotator

 *================================================ */

var headline_count;
var headline_interval;
var old_headline = 0;
var current_headline = 0;

$(document).ready(function(){
	$("div#TopStories").removeClass('noscript'); 
	$("div#TopStories").addClass("active");
	headline_count = $("div.TopStoryItem").size();
	$("div.TopStoryItem:eq("+current_headline+")").css('display','block');
	headline_interval = setInterval(headline_rotate,7000); //time in milliseconds
	$("div#TopStories").append('<div id="TopStoryButtons"><ul></ul></div>');
	$('div#TopStories .TopStoryItem h2').each(function(index) {
		var $sectionLabel = $(this).remove().text();
		$("div#TopStoryButtons ul").append('<li class="' + $sectionLabel + '">' + $sectionLabel + '</li>');
		$("#TopStoryButtons li:eq(0)").addClass('activeControls'); 
	});
		$("div#TopStories").append('</ul></div>');
		$("#TopStoryButtons li:eq(0)").click(function() { 
		selected_headline = 0;
		$("div.TopStoryItem:eq(" + current_headline + ")").fadeOut("slow");
		$("#TopStoryButtons li:eq(" + current_headline + ")").removeClass('activeControls'); 
		$("#TopStoryButtons li:eq(0)").addClass('activeControls'); 
		$("div.TopStoryItem:eq(0)").fadeIn("slow"); 
		current_headline = selected_headline;
		clearInterval(headline_interval);
		return false;
	});
	$("#TopStoryButtons li:eq(1)").click(function() { 
		selected_headline = 1;
		$("div.TopStoryItem:eq(" + current_headline + ")").fadeOut("slow");
		$("#TopStoryButtons li:eq(" + current_headline + ")").removeClass('activeControls'); 
		$("#TopStoryButtons li:eq(1)").addClass('activeControls'); 
		$("div.TopStoryItem:eq(1)").fadeIn("slow"); 
		current_headline = selected_headline;
		clearInterval(headline_interval);
		return false;
	});
	$("#TopStoryButtons li:eq(2)").click(function() { 
		selected_headline = 2;
		$("div.TopStoryItem:eq(" + current_headline + ")").fadeOut("slow");
		$("#TopStoryButtons li:eq(" + current_headline + ")").removeClass('activeControls'); 
		$("#TopStoryButtons li:eq(2)").addClass('activeControls'); 
		$("div.TopStoryItem:eq(2)").fadeIn("show"); 
		current_headline = selected_headline;
		clearInterval(headline_interval);
		return false;
	});
	$("#TopStoryButtons li:eq(3)").click(function() { 
		selected_headline = 3;
		$("div.TopStoryItem:eq(" + current_headline + ")").fadeOut("slow");
		$("#TopStoryButtons li:eq(" + current_headline + ")").removeClass('activeControls'); 
		$("#TopStoryButtons li:eq(3)").addClass('activeControls'); 
		$("div.TopStoryItem:eq(3)").fadeIn("slow"); 
		current_headline = selected_headline;
		clearInterval(headline_interval);
		return false;
	});
});

function headline_rotate() {
	current_headline = (old_headline + 1) % headline_count; 
	$("div.TopStoryItem:eq(" + old_headline + ")").fadeOut("slow");
	$("#TopStoryButtons li:eq(" + old_headline + ")").removeClass('activeControls'); 
	$("#TopStoryButtons li:eq(" + current_headline + ")").addClass('activeControls'); 
	$("div.TopStoryItem:eq(" + current_headline + ")").fadeIn("slow"); 
	old_headline = current_headline;
}

$(document).ready(function() { 
  $("#loginArea").addClass("active");
  $("#loginArea input")
    .focus(function() {
      $(this).removeClass("empty");
    })
    .blur(function() {
      if ($(this).val() == "") {
        $(this).addClass("empty");
      };
    });
  $(window).load(function() {
    $("#loginArea input[value='']").addClass("empty");
  });
});