// JavaScript Document
var headline_count;
var headline_interval;
var old_headline = 0;
var current_headline = 0;


$(document).ready(
			function(){
				$('li.hasSub').mouseover(function(){$(this).addClass("show");});
				$('li.hasSub>ul').mouseout(function(){$(this).parent().removeClass("show");});

  				headline_count = $("p.headline").size();
  				$("p.headline:eq("+current_headline+")").css('top', '5px');
  				headline_interval = setInterval(headline_rotate,7000);
  				$('#scrollup').hover(function() {
    				clearInterval(headline_interval);
  				}, function() {
   				headline_interval = setInterval(headline_rotate,7000);
    			headline_rotate();

				});
				
				$('#header').innerfade({
					speed: 300,
					timeout: 8000,
					type: 'sequence',
					containerheight: '175px'
				});
				calctime();

		});

function  clock(){
	var d = new Date();
	document.getElementById('clock').innerHTML = d.getDateString('%hour:%min, %date%ordinal %month %year') + "<a href='/'></a>";
	setInterval('clock()',60000);
}
	
function calctime()
{
var dnames = ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'];
var mnames = ['January','February','March','April','May','June','July','August','September','October','November','December'];
var currenttime = new Date();
var hours = currenttime.getHours();
var minutes = currenttime.getMinutes();
var seconds = currenttime.getSeconds();
var ord= currenttime.getDateOrdinal();
var day = currenttime.getDate();
var month = mnames[currenttime.getMonth()]
var y = currenttime.getFullYear();
var timesuffix = "am";
if (hours > 11)
{
timesuffix = "pm";
hours = hours - 12;
}
if (hours == 0){hours = 12;}
if (hours < 10){hours = "0" + hours;}
if (minutes < 10){minutes = "0" + minutes;}
if (seconds < 10){seconds = "0" + seconds;}
var clocklocation = document.getElementById('clock');
clocklocation.innerHTML =  hours + ":" + minutes + ":" + seconds + " " + timesuffix + ", " + day + ord + " " + month + " " + y;
setTimeout("calctime()", 1000);
}
	
	
	
	
	
	
	
	
	
	
	
	
	
Date.prototype.getDateString = function(str)
	{
	var dnames = ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'];
	var mnames = ['January','February','March','April','May','June','July','August','September','October','November','December'];
	str = str.replace('%day',dnames[this.getDay()] );
	str = str.replace('%date',this.getDate() );
	str = str.replace('%ordinal',this.getDateOrdinal() );
	str = str.replace('%month',mnames[this.getMonth()] );
	str = str.replace('%year',this.getFullYear() );
	str = str.replace('%hour',this.getHours() );
	var m;
	this.getMinutes() < 10 ? m = "0" + this.getMinutes() : m = this.getMinutes();
	str = str.replace('%min',m );
	str = str.replace('%sec',this.getSeconds() );
	return str;
	}
Date.prototype.getDateOrdinal = function()
	{
		var n = this.getDate();
		var ord = 'th';
		if(n % 10 == 1 && n % 100 != 11)
		{ord = 'st';}
		else if(n % 10 == 2 && n % 100 != 12)
		{ord = 'nd';}
		else if(n % 10 == 3 && n % 100 != 13)
		{ord = 'rd';}
		return ord;		
}

      function headline_rotate() {
        current_headline = (old_headline + 1) % headline_count;
        $("p.headline:eq(" + old_headline + ")")
          .animate({top: -205},2000, function() {
            $(this).css('top', '210px');
          });
        $("p.headline:eq(" + current_headline + ")")
          .animate({top: 5},2000); 
        old_headline = current_headline;
      }