// Scrolling headline variables	
var headlineCount;
var currentHeadline = 0;	

$(document).ready(function(){
	
	// Network Link Functionality
	$("#networkSearch").change(function(){
		var url = $("#networkSearch").val();
		location.href=url;
	})
	
    // the defaults for the tabs
	$("#altHeadline2").hide();
	$("#tabBtn1").addClass('tabOn');
	$("#tabBtn2").addClass('tabOff R');
	
	// When Premium Button is clicked
	$('#tabBtn2').click(function() {
	    // removed classes
		$("#tabBtn1").removeClass();
		$("#tabBtn2").removeClass();
		// add classes
		$("#tabBtn1").addClass('tabOff L');
		$("#tabBtn2").addClass('tabOn');
		// show and hide
		$('#altHeadline1').hide();
		$('#altHeadline2').show();
		return false;
	});
	
	// When Fan Button is clicked
	$('#tabBtn1').click(function() {
	    // removed classes
		$("#tabBtn1").removeClass();
		$("#tabBtn2").removeClass();
		// add classes
		$("#tabBtn1").addClass('tabOn');
		$("#tabBtn2").addClass('tabOff R');
		// show and hide
		$('#altHeadline1').show();
		$('#altHeadline2').hide();
		return false;
	});
	
	/*
	 * jQuery code for scrolling headlines
	 */
	headlineCount = $("div.scrolling-headline").size();
	$("div.scrolling-headline:eq("+currentHeadline+")").css('top', '5px');
	setInterval(headline_rotate,5000); //time in milliseconds
	
	/*
	 * Every link going to an outside page will refresh this page
	 */
	$(function() {
		$('a[rel*=external]').click(function(){
			window.open(this.href);
			refreshPeriodic();
			return false;
		});
	}); // end function
	
	/*
	 * When refreshed button is clicked
	 */
	$(".refresh").click(function() {
		refreshPeriodic();
	});
			
}); // end doc ready

/*
 * Function for the scrolling headlines
 */
function headline_rotate() {
  oldHeadline = currentHeadline % headlineCount;
  newHeadline = ++currentHeadline % headlineCount;
  $("div.scrolling-headline:eq(" + oldHeadline + ")").fadeOut(250, function() {
  		$(this).css('top', '35px');
  }); 
  $("div.scrolling-headline:eq(" + newHeadline + ")").show().animate({top: 5},1000);      
}

// function to refresh every 5 min.
function refreshPeriodic() { 
   // 
   location.reload(); 
   timerID = setTimeout("refreshPeriodic()",500000);  // time in milliseconds
}

// iPod Pulldown
$(function(){
	// BUTTONS
	$('.fg-button').hover(
		function(){ $(this).removeClass('ui-state-default').addClass('ui-state-focus'); },
		function(){ $(this).removeClass('ui-state-focus').addClass('ui-state-default'); }
	);
	
	// MENUS    	
	$('#hierarchy').menu({
		content: $('#hierarchy').next().html(),
		crumbDefaultText: ' '
	});
	
	$('#hierarchybreadcrumb').menu({
		content: $('#hierarchybreadcrumb').next().html(),
		backLink: false
	});
}); 
