// JavaScript Document
function slideSwitch(fadeimages) {
    imageid = imageid + 1;		
    if (imageid == $imagecount + 1) imageid = 0;
    showSlide();
}


function
showSlide(image_id) {
    var $nextimage = '<img src="'+fadeimages[image_id][0]+'" alt=""/>';
	//var $nextmessage = fadeimages[imageid][1];
	var $oldimage = $('#image1').html();
    $('#image0').html($oldimage).css({opacity:1.0}).animate({opacity: 0.0}, 500);	
    $('#image1').html($nextimage).css({opacity:0.0}).animate({opacity: 1.0}, 500);	
    //$('#slideshow_text').html($nextmessage);
    var tn = '#tntd' + image_id ;
    tn_code = '<img src="../images/gallery/tn'+image_id+'.jpg" name="TN'+image_id+'" width="91" height="91" border="0" alt="" id="TN'+image_id+'" />';	
    $(tn).html(tn_code);
	
    var ctn = '#tntd' + current_id;
    ctn_code = '<a href="javascript:showSlide('+ current_id +');" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage(\'TN'+ current_id +'\',\'\',\'../images/gallery/tn'+ current_id + '.jpg\',1)"><img src="../images/gallery/tn' + current_id + 't.jpg" name="TN' + current_id + '" width="91" height="91" border="0" id="TN'+ current_id + '" alt=""/></a>';
    $(ctn).html(ctn_code);
	current_id = image_id;
}


$(document).ready(function() {
    imageid=0;
    if (window.fadeimages !== undefined) {
      // preload images
      for(var i = fadeimages.length -1; i > 0; i--) {
        $("<img>").attr("src",fadeimages[i][0]);
	  }

      showSlide(1);
      //$slideint = setInterval( "slideSwitch(fadeimages)", $interval);

     $("#prev_image").click(function(){
        if ($slideint) {
          clearInterval($slideint);
        }
        imageid = imageid - 1;		
        if (imageid == -1 ) imageid = $imagecount;
        showSlide();
      });
     $("#next_image").click(function(){
        if ($slideint) {
          clearInterval($slideint);
        }
        imageid = imageid + 1;		
        if (imageid == $imagecount + 1) imageid = 0;
          showSlide();
      });
     $("#pause_show").click(function(){
        if ($slideint) {
          clearInterval($slideint);
        }	   
      });
	}
});