(function($){

	$.fn.sp_rotate = function(userInput){
		
		var $all = $(this);
		//alert( $all.length);
		var max_index = $all.length - 1;
		var active = 0;
		$all.css("z-index",10).css({
				opacity:0
		});
	
			
		
		function rotate()
		{
			active++;
			//alert(max_index);
			if(active > max_index) active = 0;
			$all.css("z-index",10).animate({
				opacity:0
			},500);
			
			//alert(active);
			$all.eq(active).stop().css("z-index",11).animate({
				opacity:1
			},500);
		}
		
		$all.eq(0).css({
			"opacity": 1,
			"z-index": 11
		});
		
		setInterval(function(){
			rotate();
		}, 3000);

	}
	
})(jQuery);


$(document).ready(function(){
	
	$("#menu img").each(function(){
		var link_image = $(this).attr("src");
		link_image = link_image.replace("grey","white");
		var image = $("<img/>").attr("src", link_image);	
	});
	
	$("#menu a").hover(function(){
		var link_image = $("img", this).attr("src");
		link_image = link_image.replace("grey","white");
		$("img", this).attr("src", link_image);
	},function(){
		var link_image = $("img", this).attr("src");
		link_image = link_image.replace("white","grey");
		$("img",this).attr("src", link_image);
	});
	
	$("a").click(function(){
		$(this).blur();	
	});
	
	
	$("a.e_box").elephantbox();
	
	$("#right a").attr("target", "_blank");
	
	if($(".spotlight_rotator").length > 0)
	{
		$(".spotlight_wrapper").each(function(){
			$(this).find(".spotlight_rotator").sp_rotate();
		});
	}
	
	if($("#menu_left_news").length>0){
		news_menu();
		$("#more_news").click(function(e){
			e.preventDefault();
			more_news();
		});
		
		$("#more_news").click();
	}
		
});

var last_news = 0;
var show_until = 2;
var $items;
var show_time = 0;

function news_menu()
{
	$items = $("#menu_left_news li");
	$items.hide();
}

function more_news()
{
	show_until += 10;
	
	$items.slice(last_news,show_until).show();
	show_time = 300;
	last_news = show_until;
	if(last_news>$items.length) $("#more_news").hide(250);
}

