function swapImages(){ 
      var $active = $('#myGallery .active');
      var $next = ($('#myGallery .active').next().length > 0) ? $('#myGallery .active').next() : $('#myGallery img:first');
      $active.fadeOut(function(){
      $active.removeClass('active');
      $next.fadeIn().addClass('active');
      });
    }
	function prevImage(){ 
      var $active = $('#myGallery .active');
      var $prev = ($('#myGallery .active').prev().length > 0) ? $('#myGallery .active').prev() : $('#myGallery img:first');
      $active.fadeOut(function(){
      $active.removeClass('active');
      $prev.fadeIn().addClass('active');
      });
    }
////code used for changing image on clicking on image
$(document).ready(function() {
   //var $active = $('#myGallery .active');alert($active)
	 $('#thumb1').click(function() {
	 var $active = $('#myGallery .active');
     $active.fadeOut(function(){
      $active.removeClass('active');
	  $("#img1").fadeIn().addClass("active");
	 });
   });
   $('#thumb2').click(function() {
	 var $active = $('#myGallery .active');
     $active.fadeOut(function(){
      $active.removeClass('active');
	  $("#img2").fadeIn().addClass("active");
	 });
   });
   $('#thumb3').click(function() {
	 var $active = $('#myGallery .active');
     $active.fadeOut(function(){
      $active.removeClass('active');
	  $("#img3").fadeIn().addClass("active");
	 });
   });
$('#thumb4').click(function() {
	 var $active = $('#myGallery .active');
     $active.fadeOut(function(){
      $active.removeClass('active');
	  $("#img4").fadeIn().addClass("active");
	 });
   });
});

  setInterval('swapImages()', 5000);