/* 
	Requires Jquery
  Coder: VC 2008-08
 */

$(document).ready(function() {
	jQuery('#comments .comment-details').hide();
	
	//turn first one on
	jQuery('#comments .comment-details:first').show();
	jQuery('#comments .scroll li:first').addClass('active');
	
	//event handlers
	jQuery('#comments .scroll li').click(function(event){
		showComment(jQuery(this).children('p:first').children('a'), this);
		event.preventDefault();
	});
	jQuery('#comments .scroll li a').click(function(event){
		showComment(this, jQuery(this).parent('p').parent('li'));
		event.preventDefault();
		event.stopPropagation();
	});	
	jQuery('#comments #up').click(function(event){
		var prevone = jQuery('#comments .scroll li.active').prev();
		showComment(jQuery(prevone).children('p:first').children('a'), prevone);
		event.preventDefault();
		event.stopPropagation();
	});
	jQuery('#comments #down').click(function(event){
		var nextone = jQuery('#comments .scroll li.active').next();
		showComment(jQuery(nextone).children('p:first').children('a'), nextone);
		event.preventDefault();
		event.stopPropagation();
	});	
	jQuery('#comments #up').show();
	jQuery('#comments #down').show();
});

function showComment(link, button){
	try{
		var href = jQuery(link).attr('href');
		var theId = href.split('#')[1];
		var theSelector = '#'+theId;
		
		//hide prev
		jQuery('#comments .comment-details').hide();
		jQuery('#comments .scroll li.active').removeClass('active');

		//show this
		jQuery(theSelector).show();
		jQuery(button).addClass('active');
	}
	catch(err) { }
}