function slideNext() {
	var $active = $('.gallery img.active');
	if ( $active.length == 0 ) $active = $('.gallery img:last');
	var $next =  $active.next().length ? $active.next() : $('.gallery img:first');
	$next.hide().show().addClass('active');
	$active.removeClass('active last-active').hide();
	setActiveCaption();
}
function slidePrev() {
	var $active = $('.gallery img.active');
	if ( $active.length == 0 ) $active = $('.gallery img:first');
	var $prev =  $active.prev('img').length ? $active.prev() : $('.gallery img:last');
	$prev.hide().show().addClass('active');
	$active.removeClass('active last-active').hide();

	setActiveCaption();
}
function setActiveCaption(){
	var id = $('.gallery img.active').attr('id');
	$('.imagelist li').removeClass('active');
	var nid = id.replace("img","imgcap");
	$("#"+nid).addClass('active');
}


$('').ready( function(){
	$('.gallery #nextimg').click( function(){  
		slideNext();
		return false;
	});
	$('.gallery #previmg').click( function(){  
		slidePrev();
		return false;
	});
	//$('.gallery img').hide();
	//$('.gallery img:first').show().addClass('active');
	$('.imagelist li:first a').addClass('active');
	
	$('.imagelist li a').click( function(){
		href = $(this).attr('href');
		$('.gallery img').attr('src',href);
		$('.imagelist li a').removeClass('active');
		$(this).addClass('active');
		return false;
	});
	
	//var x = window.setInterval( "slideNext()", 5000 );
	
	
});	



