$(document).ready(function(){
	
// News Panel Code {	
	
	var offset = $('div#latestnews').offset();
	var news_current = 1;
	var panels = $('.newspanel').get();
	var number_of_panels = panels.length;
	
	// Hack to give the div height...
	$('div#latestnews').height($('div#latestnews').height());
	
	// Set height of the news panel...
	$('div.newspanel').each(function(){
		
		this_height = $(this).height();
		that_height = $('div#latestnews').height();
		
		if(this_height > that_height){
			$('div#latestnews').height(this_height);
		}
		
		$(this).css('left', offset.left);
		$(this).css('top', offset.top);
	
	});
	
	// Sort out class for previous link
	if(news_current == 1){ $('a#prevnewslink').addClass('grey'); }
	if(news_current == number_of_panels){ $('a#nextnewslink').addClass('grey'); }
	
	// Set up running indicator...
	var newsrunning = false;
	
	function nextNewsPanel(cur_panel){
		
		newsrunning = true;

		if(news_current <= number_of_panels && news_current >= 1){

			news_current++;

			if(news_current > 1){ $('a#prevnewslink').removeClass('grey'); }
			if(news_current == number_of_panels){ $('a#nextnewslink').addClass('grey'); }

			next_panel = $('div#newspanel'+news_current);
	
			$(cur_panel).hide('slide',{ direction: 'left' });;
			$(next_panel).show('slide',{ direction: 'right' });
		
			
		} else {
			
			news_current = number_of_panels;
			
		}
		
		newsrunning = false;
		
		return false;
		
	}
	function prevNewsPanel(cur_panel){
		
		newsrunning = true;

		if(news_current <= number_of_panels && news_current > 1){

			news_current--;

			if(news_current == 1){ $('a#prevnewslink').addClass('grey'); }
			if(news_current < number_of_panels){ $('a#nextnewslink').removeClass('grey'); }

			next_panel = $('div#newspanel'+news_current);
	
			$(cur_panel).hide('slide',{ direction: 'right' });;
			$(next_panel).show('slide',{ direction: 'left' });
			
		} else {
			
			news_current = number_of_panels;
			
		}
		
		newsrunning = false;

		return false;

	}	
	
	$('a#nextnewslink').click(function(){
		if(!newsrunning && !$(this).hasClass('grey')){
			nextNewsPanel($('div.newspanel:visible'));
		}
		return false;
	});
	
	$('a#prevnewslink').click(function(){
		if(!newsrunning && !$(this).hasClass('grey')){
			prevNewsPanel($('div.newspanel:visible'));
		}
		return false;
	});
	
// }
	
	var offset = $('div#latestconf').offset();
	var conf_current = 1;
	var panels = $('.confpanel').get();
	var number_of_panels = panels.length;
	
	// Hack to give the div height...
	$('div#latestconf').height($('div#latestconf').height());
	
	// Set height of the news panel...
	$('div.confpanel').each(function(){
		
		this_height = $(this).height();
		that_height = $('div#latestconf').height();
		
		if(this_height > that_height){
			$('div#latestconf').height(this_height);
		}
		
		$(this).css('left', offset.left);
		$(this).css('top', offset.top);
	
	});
	
	// Sort out class for previous link
	if(conf_current == 1){ $('a#prevconflink').addClass('grey'); }
	if(conf_current == number_of_panels){ $('a#nextconflink').addClass('grey'); }
	
	// Set up running indicator...
	var confrunning = false;
	
	function nextConfPanel(cur_panel){
		
		confrunning = true;

		if(conf_current <= number_of_panels && conf_current >= 1){

			conf_current++;

			if(conf_current > 1){ $('a#prevconflink').removeClass('grey'); }
			if(conf_current == number_of_panels){ $('a#nextconflink').addClass('grey'); }

			next_panel = $('div#confpanel'+conf_current);
	
			$(cur_panel).hide('slide',{ direction: 'left' });;
			$(next_panel).show('slide',{ direction: 'right' });
		
			
		} else {
			
			conf_current = number_of_panels;
			
		}
		
		confrunning = false;
		
		return false;
		
	}
	function prevConfPanel(cur_panel){
		
		confrunning = true;

		if(conf_current <= number_of_panels && conf_current > 1){

			conf_current--;

			if(conf_current == 1){ $('a#prevconflink').addClass('grey'); }
			if(conf_current < number_of_panels){ $('a#nextconflink').removeClass('grey'); }

			next_panel = $('div#confpanel'+conf_current);
	
			$(cur_panel).hide('slide',{ direction: 'right' });;
			$(next_panel).show('slide',{ direction: 'left' });
			
		} else {
			
			conf_current = number_of_panels;
			
		}
		
		confrunning = false;

		return false;

	}	
	
	$('a#nextconflink').click(function(){
		if(!confrunning && !$(this).hasClass('grey')){
			nextConfPanel($('div.confpanel:visible'));
		}
		return false;
	});
	
	$('a#prevconflink').click(function(){
		if(!confrunning && !$(this).hasClass('grey')){
			prevConfPanel($('div.confpanel:visible'));
		}
		return false;
	});
	
	$(window).resize(function(){
		
		var offset = $('div#latestnews').offset();
		
		$('div.newspanel').each(function(){
				
			$(this).css('left', offset.left);
			$(this).css('top', offset.top);

		});
		
		var offset = $('div#latestconf').offset();
		
		// Set height of the news panel...
		$('div.confpanel').each(function(){

			$(this).css('left', offset.left);
			$(this).css('top', offset.top);

		});
		
	});
	
	
	this_height = $('div#latestconf').height();
	that_height = $('div#latestnews').height();
	
	if(this_height > that_height){
		$('div#latestnews').height(this_height + 10);
		$('div#latestconf').height(this_height + 10);
	} else {
		$('div#latestconf').height(that_height + 10);	
		$('div#latestnews').height(that_height + 10);
	}
	
});