var current_num = 2;
var interupted = 0;
var one_more = 0;
$(document).ready(function() {

      var num_of_images = $(".image").length;
      var i;

      setInterval("show_image(current_num)", 4000);

      $("#controls a img").live('click', function() {
          var xval = $(this).attr("xvalue");
          one_more = 1;
          interupted = 0;
          //alert("clicked " + xval);
          show_image(xval);
          

      });


      var img_src;
      var num_of_images = $(".image").length;
      for(i = 1; i <= num_of_images; i++)
      {
        img_src = $(".i" + i).attr("src");
        //alert(img_src);
        $("#controls").append("<a href=#><img src='" + img_src + "' height=30 width=60 xvalue='" + i + "'></a>  ");
      
      }
      $("#controls a img").css("border", "1px solid transparent");
      $("#controls a img").eq(0).css('border', '1px solid aqua');
      //alert("test");

});

function show_image(image_num)
{
    $("#status").html("image num = " + image_num + ", interupted = " + interupted + ", one_more = " + one_more);
    if(interupted == 0 && (one_more == 0 || one_more == 1))
    {

        $("#controls a img").css("border", "1px solid transparent");
        $("#controls a img").eq(image_num-1).css('border', '1px solid aqua');
        $(".image").not("#image_" + image_num).fadeTo(500, 0.0);
        $("#image_" + image_num).show().fadeTo(500, 1.0, function() {
          if(jQuery.browser.msie)
				$(this).get(0).style.removeAttribute('filter');
          $(".image").not("#image_" + image_num).hide();
        });

        var num_of_images = $(".image").length;
        if(num_of_images == current_num) { current_num = 1;}
        else {current_num++; }

      if(one_more == 1) { one_more = 2;interupted = 1; }
    }
}





