// javascript for NSYC
Image_box = {
  
  timer: {},
  rotating: 0,     // set to 1 if pictures are rotating thru slide show
  selected_box: '',
  box: '',
  
  init: function(box) {
	  this.selected_box = $('#'+box);
	  this.box = box;
  },
  
  show_image: function(index) {
    var old_image = this.selected_box.find('[id^="image"]').eq(index);
	old_image.addClass('show-it')
    old_image.show();
	},
	
   init_rotate: function() {
      image_index = 0;
	  this.rotating = 1;
	  this.selected_box.find('#image_1').addClass("show-it");
	  this.rotate_images();
   },

   change_image: function(howmany) {
      var index;
      var old_image;
      var new_image;
   
      old_image = this.selected_box.find('.show-it');
	  index = old_image[0].id.substr(6);
	  if(index >= howmany)
	      index = 1;
	  else
	      index++;
	  new_image = this.selected_box.find("#image_"+index);
	  old_image.removeClass('show-it').addClass('hide-it');
	  old_image.fadeOut(600, function() {
	     new_image.addClass('show-it').removeClass('hide-it');
         new_image.fadeIn(200);
	 });
   },

   rotate_images: function() {
	 var box;
	 if(this.selected_box != undefined) 
	     box = this;
     else if(this.Image_box.selected_box != undefined)
	     box = this.Image_box;
     else
	     return;
     howmany = box.selected_box.find('[id^="image"]').length;
     box.change_image(howmany);
     box.timer = setTimeout(arguments.callee, 3000);
   },

   stop_image: function() {
	 this.rotating = 0;  
	 clearTimeout(Image_box.timer);
   },
   
   change_image_byIndex: function(index, howmany) {
      var old_index;
      var new_index;
      var old_image;
      var new_image;
	  var t;
   
      if(index == howmany-1){
	      old_index = howmany-1;
		  new_index = 1;
      }
	  else {
	      old_index = index;
		  new_index = index+1;
	  }
      old_image = this.selected_box.find('[id^="image"]').eq(old_index);
	  new_image = this.selected_box.find('[id^="image"]').eq(new_index);
	  old_image.hide();
      new_image.show();
   }
}
