$(document).ready(function(){
	var months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"], $time = new Date();


	if($("#news_title .current_date").length > 0) { $('#news_title .current_date').text(months[$time.getMonth()] + " " + $time.getDate() + ", " + $time.getFullYear()); }
	if($("#carousel").length > 0) { $("#carousel").html($("#holder_images").html()).carousel3d({}); }
	if($("#headline_area").length > 0) {
		$('#headline_area .headline_menu .submenu').hide();
		$('#headline_area .headline_menu .silverheader:first').addClass('selected');
		$('#headline_area .headline_menu .submenu:first').slideDown();
		$('#headline_area .headline_menu .silverheader').mouseover(function(){
			if(!$(this).is('.selected')) {
				$('#headline_area .headline_menu .selected').removeClass('selected');
				$('#headline_area .headline_menu .submenu:visible').slideUp();
				$(this).addClass('selected').next().slideDown();
			}
		});
	}


	if($(".core_photo_gallery").length > 0) {
		slidegallery(".core_photo_gallery", 0);
		gallery = setInterval('slidegallery(".core_photo_gallery")', 10000); // Start the slide show.
		$('.core_photo_gallery .gallery_nav ul li').click(function(e){
			var idx = $(this).parent().children('li').index(this);
			clearInterval(gallery); // Stop the slide show.
			slidegallery(".core_photo_gallery", idx); // Change the slide to the one clicked on.
			gallery = setInterval('slidegallery(".core_photo_gallery")', 10000); // Start the slide show again.
			return false;
		});
	}


	$(".tabs li.dd, .tabs li.wsub").hover(
	    function(){ $("ul", this).fadeIn("fast"); },
	    function(){ $("ul", this).fadeOut("fast"); }
	);
	if(document.all) { $(".tabs li.dd, .tabs li.wsub").hoverClass("sfHover"); }
});
function slidegallery(targ, dex){
	var actID, nextID, sl = $(targ + " .gallery_nav ul li").length;
	if(dex == undefined) {
		$(targ + " .gallery_nav ul li").each(function(i,v){ if($(this).is('.active')){ actID = i; } });
		nextID = (actID+1 < sl)?actID+1:0;
	} else {
		if($(targ + " .gallery_content ul li.active").length < 1) { $(targ + " .gallery_content ul li:last").addClass('active'); }
		nextID = dex;
	}
	$(targ + " .gallery_nav ul li.active").removeClass('active');
	$(targ + " .gallery_content ul li.active").fadeOut('normal', function(){
		$(this).removeClass('active');
		$(targ + " .gallery_nav ul li").eq(nextID).addClass('active');
		$(targ + " .gallery_content ul li").eq(nextID).fadeIn('normal', function(){
			$(this).addClass('active').children('span:not(":empty")').slideDown();
		});
	}).children('span:visible').hide();
}
$.fn.hoverClass = function(c) {
    return this.each(function(){
        $(this).hover(
            function() { $(this).addClass(c);  },
            function() { $(this).removeClass(c); }
        );
    });
};
