currentImg = 0;
maxImg = 0;

$(document).ready(function(){
	slideImages = $('.slideImg');
	textAreas = $('.textArea');
	maxImg = slideImages.length - 1;
	
	slideImages.hide().filter(':first').show();
	textAreas.hide().filter(':first').show();
	
//	$('.slideshow .title').text($('img', slideImages).filter(':first ').attr('alt'));
	
	$('.nav a').click(function(){
		if (this.className.indexOf('selected') == -1) {
			slideImages.hide();
			textAreas.hide();
			
			$(slideImages[$(this).attr('rel')]).fadeIn(500);
			$(textAreas[$(this).attr('rel')]).fadeIn(500);
			
			$('.nav a').parent().removeClass('selected');
			$(this).parent().addClass('selected');
			
			currentImg = $(this).attr('rel');
			
			//$('.slideshow .title').text($('img', slideImages).filter($('img',this.hash)).attr('alt'));
		}
		nextprevReset();
		
		return false;
	});
	$('.nextprev a').click(function(){
		if (this.className == "prev"){
			nextprevImg("prev");
		}else{
			nextprevImg("next");
		}
		return false;
	});
	nextprevReset();
});

function nextprevReset() {
	$('.nextprev div').show();
	if(currentImg == 0){
		$('.nextprev .arrowLeft').hide();
	}
	if(currentImg == maxImg){
		$('.nextprev .arrowRight').hide();
	}
}

function nextprevImg(num) {
	if(num == "prev") {
		currentImg--;
	}else{
		currentImg++;
	}
	
	slideImages.hide();
	textAreas.hide();
	
	$(slideImages[currentImg]).fadeIn(500);
	$(textAreas[currentImg]).fadeIn(500);
	
	$('.nav a').parent().removeClass('selected');
	$($('.nav a')[currentImg]).parent().addClass('selected');
	
	nextprevReset();
}

