var i = 1;
var j;
var imax = 3;
var si = '';
var sj = '';

$(document).ready(function()
{
  // initial slider
	$('#photoSlider img').hide();
	$('.photosliderTxtarea').hide();
	$('#prev').hide(); // hide prev button @ start slideshow
	if ( imax < 2 )
	{
		$('#next').hide(); // hide next button @ start slideshow
	}
	si = i += ''; // convert to str
  $('#img_' + si).fadeIn('slow');
  $('#txt_' + si).fadeIn('slow');
	document.getElementById('currentNumber').innerHTML = '1'; // show first number
	simax = imax += '';	// convert to str
	document.getElementById('maxNumber').innerHTML = simax; // show max number

  // next
  $('#next').click(function ()
	{
		$('#prev').show(); // show prev button after first click next button
    $('#img_' + si ).fadeOut('slow');
    $('#txt_' + si ).fadeOut('slow');
		j = i;
		j++;
    sj = j += '';	// convert to str
	  $('#img_' + sj).fadeIn('slow');
	  $('#txt_' + sj).fadeIn('slow');
		document.getElementById('currentNumber').innerHTML = sj; // show current number
	  i++;
	  // hide next button @ end slideshow
	  if (i > imax-1)
	  {
			$('#next').hide();
			document.getElementById('currentNumber').innerHTML = simax; // show last number
		}
  });

  // previous
  $('#prev').click(function ()
	{
		$('#next').show();
    $('#img_' + sj ).fadeOut('slow');
    $('#txt_' + sj ).fadeOut('slow');
		j = i;
		j--;
    sj = j += ''; // convert to str
	  $('#img_' + sj).fadeIn('slow');
	  $('#txt_' + sj).fadeIn('slow');
		document.getElementById('currentNumber').innerHTML = sj; // show current number
	  i--;
	  // hide prev button @ start slideshow
		if (i < 2)
		{
			$('#prev').hide();
			document.getElementById('currentNumber').innerHTML = '1'; // show first number
		}
  });

});
