$(document).ready(function(){

	$('div.newswrapper').ready(function(){
		num_news_items = $(this).find('div.news').length;
		$('div.newswrapper').css({'width': num_news_items*600 });
		var current_news = 0;
		$('a#back_button').text('');
		$('a#next_button').text('');
		$('div.newscontainer').css({'height':($('div.newswrapper>div:eq('+(current_news)+')').height()) }, 1000);
		$('a#back_button').fadeOut(0);
		
		$('a#next_button').click(function(){
			if(current_news == (num_news_items - 2)){
				$(this).fadeOut(300);
			}
			if(current_news == 0){
				$('a#back_button').fadeIn(300);
			}
			$('div.newswrapper').animate({left: '-=600px'}, 1000);
			$('div.newscontainer').animate({'height':($('div.newswrapper>div:eq('+(current_news+1)+')').height()) }, 1000);
			current_news ++;
			return false;
		});
		
		$('a#back_button').click(function(){
			if(current_news == 1){
				$('a#back_button').fadeOut(300);
			}
			if(current_news == (num_news_items - 1)){
				$('a#next_button').fadeIn(300);
			}
			$('div.newswrapper').animate({left: '+=600px'}, 1000);
			$('div.newscontainer').animate({'height':($('div.newswrapper>div:eq('+(current_news-1)+')').height()) }, 1000);
			current_news --;
			return false;
		})
	});
	
	$("a.fancybox").fancybox({'autoScale': false, 'padding': 0, 'overlayShow': false});
	$("a.fancybox_iframe_video").fancybox({'autoScale': false, 'padding': 0, 'overlayShow': false, 'width' : 768, 'height' : 432});
	$("a.fancybox_iframe_video_tall").fancybox({'autoScale': false, 'padding': 0, 'overlayShow': false, 'width' : 533, 'height' : 400});
});
