(function($){

function mycarousel_initCallback(carousel) {
    $('a.slide-link').bind('click', function() {
    	if (!$('.jcarousel-list').is(':animated')) {
        	var top = $(this).parents('.box:eq(0)').position().top + 18;
        	$('.slider .arrow-span').stop().animate({'top': (top).toString() + 'px'});
        }
        carousel.scroll(jQuery.jcarousel.intval(jQuery(this).attr('rel')));
        return false;
    });	    
};
	
function mycarousel_itemFirstInCallback(carousel, item, idx, state) {
	$('.box').removeClass('active');
	$('.box').eq(idx-1).addClass('active');
};


function getCalendarDate()
{
   var months = new Array(13);
   months[0]  = "Jan";
   months[1]  = "Feb";
   months[2]  = "Mar";
   months[3]  = "Apr";
   months[4]  = "May";
   months[5]  = "Jun";
   months[6]  = "Jul";
   months[7]  = "Aug";
   months[8]  = "Sep";
   months[9]  = "Oct";
   months[10] = "Nov";
   months[11] = "Dec";
   
   var days = new Array(7);
   days[0] = "Sun";
   days[1] = "Mon";
   days[2] = "Tue";
   days[3] = "Wed";
   days[4] = "Thu";
   days[5] = "Fri";
   days[6] = "Sat";
   
   var now         = new Date();
   var monthnumber = now.getMonth();
   var monthname   = months[monthnumber];
   var monthday    = now.getDate();
   var year        = now.getYear();
   var daynumber   = now.getDay();
   var day		   = days[daynumber];
   
   if(year < 2000) { year = year + 1900; }
   var dateString = day+","+monthname+" "+monthday+","+year;
   
   return dateString;
} // function getCalendarDate()

function getClockTime()
{
   var now    = new Date();
   var hour   = now.getHours();
   var minute = now.getMinutes();
   var second = now.getSeconds();
   var ap = "AM";
   if (hour   > 11) { ap = "PM";             }
   if (hour   > 12) { hour = hour - 12;      }
   if (hour   == 0) { hour = 12;             }
   if (minute < 10) { minute = "0" + minute; }
   var timeString = hour +
                    ':' +
                    minute +
                    ' ' +
                    ap;
   return timeString;
}

function updateTime() {
	var calendarDate = getCalendarDate();
	var clockTime = getClockTime();
	
	$("span.date").text(calendarDate);
	$("span.time").text(clockTime);
	
	Cufon.replace('.thermostat span');
	Cufon.replace('.box p');
}


$(function(){
	
	$("#navigation ul li").hover(function() {
		$(this).find(".dd").show();
		$(this).find("a:eq(0)").addClass('hover');
	}, function(e) {
		$(this).find(".dd").hide();
		$(this).find("a:eq(0)").removeClass('hover');
	});
	
	$("#mycarousel").jcarousel({
        scroll: 1,
        wrap:"both",
        itemFirstInCallback: mycarousel_itemFirstInCallback,
        initCallback: mycarousel_initCallback,
        // This tells jCarousel NOT to autobuild prev/next buttons
        buttonNextHTML: null,
        buttonPrevHTML: null
    });
	
	setInterval(function() {
		updateTime();
	}, 5000);
	updateTime();

})

})(jQuery)
