
$(document).bind("ready", function(){
	
	Cufon.replace('h1');
    Cufon.replace('span.subheading');
	Cufon.replace('#submenu h2');


	$('body').addClass("javascript");	
	
	$('.clickable').css("cursor", "pointer");

	$('.clickable').bind("click", function(){
		window.location = $(this).find("a:first").attr("href");
	});

	$('.clickable').hover(function(){
		$(this).addClass("hover");
	},function(){
		$(this).removeClass("hover");
	});
	
	jQuery.fn.extend({
		getCurrentAndNext: function(filter){
			current = $(this).find(filter + "[current]");
			
			len  = $(this).find(filter + "[current]").next(filter).length;
			if(len >= 1){
				next = $(this).find(filter + "[current]").next(filter);
			}else{
				next = $(this).find(filter + ":first");
			}
			
			$(current).removeAttr("current");
			$(next).attr("current", "true");
			
			return [current, next];
		}
	});
	
	$('#images img:not(:first)').css("display", "none");
	$('#images img:first').attr("current", "true");
	
	updateBanner = function(){
		if($('#images').find("img").length == 1) return;
		nextCurrent = $('#images').getCurrentAndNext("img");
		
		current = nextCurrent[0];
		next	= nextCurrent[1];
		
		$(current).fadeOut(2500);
		$(next).fadeIn(2500);
	}
	
	setInterval(updateBanner, 10000);

	$('#statistics img:not(:first)').css("display", "none");
	$('#statistics img:first').attr("current", "true");
	
	updateStats = function(){
		if($('#statistics').find("img").length == 1) return;
		
		nextCurrent = $('#statistics').getCurrentAndNext("img");
		
		current = nextCurrent[0];
		next	= nextCurrent[1];
		
		$(current).fadeOut(400);
		$(next).fadeIn(400);
	}
	
	setInterval(updateStats, 5000);
	
	$('.newsflash').each(function(){
		$('body').addClass("has-newsflash");
	});

});
