/* ---------------------------------------------

IMAGE ROTATOR CLASS
CREATED BY: BRANDON LAKE & ZACH HOLMQUIST
CREATED ON: SEPT 19 2007

------------------------------------------------- */


var image_rotator = Class.create();
//ROTATOR CLASS
image_rotator.prototype =
{
initialize : function(img_div,ref,total)
{
   this.img_div = img_div;
   this.ref = ref;
   this.total = total;
   this.current_rotation = 1;
   this.last;
   this.timer;
   this.nav;
   this.speed = 1000;
   this.display_nav();
},
//function
load_cta: function()
{
    this.timer = setTimeout(this.load_content.bind(this), this.speed);
},
//function
load_content: function()
{
   $(this.img_div).setOpacity(0);
   $(this.img_div).style.display = 'block';
   $(this.img_div).update('<img src="/images/'+ this.ref + this.current_rotation + '.jpg" border="0" width="550px" height="500px">');
    Effect.Appear(this.img_div);
   this.last = this.current_rotation;
   this.current_rotation++;

   if(this.current_rotation <= this.total)
   {
      this.timer = setTimeout(this.unload_cta.bind(this), this.speed);
   }
   else
   {

      this.current_rotation = 1;
      this.timer =  setTimeout(this.unload_cta.bind(this), this.speed);
   }
   this.update_nav();
},
//function
unload_cta: function()
{

   Effect.Fade(this.img_div);
   $('main_photo_container').style.backgroundImage = 'url("/images/'+ this.ref + this.last + '.jpg")';
   this.timer = setTimeout(this.load_cta.bind(this), this.speed);
   this.speed = 1000;
},
//function
stop_rotate : function () {
   clearTimeout(this.timer);
   if(this.current_rotation < this.total)
   {
     rand = Math.floor(Math.random() * ( this.total) );
     if(rand == 0) {
         rand = 1;
      }
     this.current_rotation = rand;

   } else {
     this.current_rotation--;
   }
},
//function
restart_rotate : function() {
 this.speed = 100;
 this.timer = setTimeout(this.load_cta.bind(this), 250);
  $('mid_large_photo').style.backgroundImage = 'url("/images/'+ this.ref + this.current_rotation + '.jpg")';
 $(this.img_div).update('<img src="/images/'+ this.ref + this.current_rotation + '.jpg" border="0" width="550px" height="500px">');
},
//function
change_picture : function(new_img) {
    this.stop_rotate();
   $(this.img_div).update('<img src="/images/'+ new_img + '.jpg" border="0" width="550px" height="500px">');
   $('mid_large_photo').style.backgroundImage = 'url("/images/'+ new_img + '.jpg")';
},
//function
click_change : function(id) {
   $('photo_nav_'+this.current_rotation).innerHTML = '<a href="javascript: jl_photo.click_change('+this.current_rotation+')" border="0"><img src="/images/dot.png" border="0" /></a>';
   this.current_rotation = id;
   this.id = id;
},
//function
display_nav : function() {
   var init_nav = '';   
      for(i=1; i <= this.total; i++) {
         init_nav = '<div id="photo_nav_'+i+'" class="photo_nav_dot"><a href="javascript: jl_photo.click_change('+i+')" border="0"><img src="/images/dot.png" border="0" /></a></div>';
         $('photo_nav').innerHTML += init_nav;
      }
},
//function
update_nav : function() {
   $('photo_nav_'+this.current_rotation).innerHTML = '<img src="/images/box.png" />';
   $('photo_nav_'+this.last).innerHTML = '<a href="javascript: jl_photo.click_change('+this.last+')" border="0"><img src="/images/dot.png" border="0" /></a>';
}
}

