function rr_init_imageSlider(sliderType, direction) {
    for(var i=1; i<=rr_js_ImageSlider_config.length; i++)
      rr_js_ImageSlider[i] = new rr_ImageSlider(i, rr_js_ImageSlider_config[i-1]["sizes"], rr_js_ImageSlider_config[i-1]["sliderType"], rr_js_ImageSlider_config[i-1]["direction"], rr_js_ImageSlider_config[i-1]["delay"]);
}


function rr_ImageSlider(slider_id, i, sliderType, direction, delay) {

    this.sliderId=slider_id;
    this.sliderType = sliderType;
    this.direction = direction;
	this.delay = delay;
    this.rr_init(i);
}


rr_ImageSlider.prototype.rr_getNext = function(i) {
    i++;
    if (i > this.rr_contents.length-1) i=0;

    return i;
}

rr_ImageSlider.prototype.rr_getPrevious = function(i) {
    i--;
    if (i < 0) i= this.rr_contents.length-1;

    return i;
}

rr_ImageSlider.prototype.rr_setNewValue = function(i) {
      if(this.sliderType=="slide") {
	  if(this.direction=="vertical") {
		  this.rr_slider.style.top = i+'px';
	  } else if(this.direction=="horizontal") {
	      this.rr_slider.style.left = i+'px';
	  }
      } else if(this.sliderType=="fade") {
	   //this.rr_shower[0].style.opacity = i/100;
	   this.rr_shower[1].style.opacity = i/100;
	   this.rr_shower[0].style.opacity = (100-i)/100;
  	   this.rr_shower[1].style.filter = 'Alpha(opacity='+i+')';
  	   this.rr_shower[0].style.filter = 'Alpha(opacity='+(100-i)+')'
      }
}


rr_ImageSlider.prototype.rr_init =function(i){
  this.rr_scrollwidth = i;

  this.rr_contents = new Array();
  for (i=0; i<document.getElementById('imageslidercontents_'+this.sliderId).childNodes.length; i++) {
    if (document.getElementById('imageslidercontents_'+this.sliderId).childNodes[i].nodeType==1 && document.getElementById('imageslidercontents_'+this.sliderId).childNodes[i].tagName!="A")
      this.rr_contents.push(document.getElementById('imageslidercontents_'+this.sliderId).childNodes[i]);
  }

  this.rr_slider = document.getElementById('rr_ImageSlider_slider_'+this.sliderId);
  this.rr_shower = new Array();

  for (i=0; i<this.rr_slider.childNodes.length; i++) {
    if (this.rr_slider.childNodes[i].nodeType==1)
      this.rr_shower.push(this.rr_slider.childNodes[i]);
  }

  this.rr_started = new Array(false, false);

  this.rr_current = 0;
  this.rr_previous_id = 0;
  j=0;
  for (i=0; i<this.rr_shower.length; i++) {
      this.rr_shower[i].innerHTML = this.rr_contents[j].innerHTML;
      j = this.rr_getNext(j);
  }
 // rr_IS_hider.style.display = 'none';


  this.rr_running=false;
  if(this.sliderType=="fade")  {
 	this.rr_shower[0].style.position="absolute";
 	this.rr_shower[0].style.top="0px";
 	this.rr_shower[0].style.left="0px";
 	this.rr_shower[1].style.position="absolute";
 	this.rr_shower[1].style.top="0px";
 	this.rr_shower[1].style.left="0px";
 	this.rr_start_fade();
  }

}

rr_ImageSlider.prototype.rr_start_fade = function(){

  //rr_IS_slider.style.left = '0px';
  this.rr_position = 100;
  this.rr_setNewValue(this.rr_position);
  this.rr_shower[0].innerHTML = this.rr_contents[this.rr_current].innerHTML;
 
  window.setTimeout('rr_js_ImageSlider['+this.sliderId+'].rr_fade_Step()', this.delay);
}

rr_ImageSlider.prototype.rr_fade_Step = function(){
  this.rr_position -= 1;
  this.rr_setNewValue(this.rr_position); 
  // this.rr_shower[1].style.opacity = this.rr_position/100; 
//   this.rr_shower[1].style.filter = 'Alpha(opacity='+rr_IS_position+')';
  
  if (this.rr_position<= 0 ) {
      this.rr_shower[1].innerHTML=this.rr_shower[0].innerHTML;
      this.rr_setNewValue(100); 
     //  this.rr_shower[1].style.opacity = 1;
    //  this.rr_shower[1].style.filter = 'Alpha(opacity=100)';
      this.rr_current=this.rr_getNext(this.rr_current);
      this.rr_start_fade();
  } else {
      window.setTimeout('rr_js_ImageSlider['+this.sliderId+'].rr_fade_Step()', 20);
  }

}


rr_ImageSlider.prototype.rr_start = function(dir) {
    this.rr_started[dir]=true;
    if (dir==1)
      this.rr_next();
    else
      this.rr_previous();
      
}

rr_ImageSlider.prototype.rr_stop = function(dir) {
  this.rr_started[dir]=false;
}

rr_ImageSlider.prototype.rr_next = function(){
  if (this.rr_running) return;
  this.rr_running=true;

  this.rr_setNewValue('0');

  this.rr_position = 0;
  //rr_IS_shower[rr_IS_shower.length-1].innerHTML = rr_IS_contents[rr_IS_current].innerHTML;	
 // rr_IS_hider.style.display = 'block';
 // rr_IS_contents[rr_IS_current].innerHTML = '';
  

  window.setTimeout('rr_js_ImageSlider['+this.sliderId+'].rr_next_Step()', 20);
}

rr_ImageSlider.prototype.rr_next_Step = function(){
  this.rr_position -= 5;
  this.rr_setNewValue(this.rr_position); 
  
  if (this.rr_position<=-this.rr_scrollwidth) {
     // rr_IS_shower.innerHTML=rr_IS_hider.innerHTML;
     this.rr_setNewValue('0'); 
     this.rr_current=this.rr_getNext(this.rr_current);
     j=this.rr_current;
     for (i=0; i<this.rr_shower.length; i++) {
        this.rr_shower[i].innerHTML = this.rr_contents[j].innerHTML;
        j = this.rr_getNext(j);
     }
      this.rr_running=false;
      if (this.rr_started[1]==true) this.rr_next();
  } else {
      window.setTimeout('rr_js_ImageSlider['+this.sliderId+'].rr_next_Step()', 20);
  }

}


rr_ImageSlider.prototype.rr_previous =function(){
  if (this.rr_running) return;
  this.rr_running=true;

 // rr_IS_hider.style.display = 'block';
  this.rr_setNewValue((-this.rr_scrollwidth));

  this.rr_current=this.rr_getPrevious(this.rr_current);
  j=this.rr_current;
  for (i=0; i<this.rr_shower.length; i++) {
     this.rr_shower[i].innerHTML = this.rr_contents[j].innerHTML;
     j = this.rr_getNext(j);
  }

  this.rr_position = -this.rr_scrollwidth;

 // rr_IS_shower.innerHTML = rr_IS_contents[rr_IS_current].innerHTML;
  

  window.setTimeout('rr_js_ImageSlider['+this.sliderId+'].rr_previous_Step()', 20);
}

rr_ImageSlider.prototype.rr_previous_Step =function(){
  this.rr_position += 5;
  this.rr_setNewValue(this.rr_position); 
  
  if (this.rr_position>=0) {
      temp=this.rr_shower;	
      this.rr_setNewValue('0');
   //   rr_IS_hider.style.display = 'none';
      this.rr_running=false;
      if (this.rr_started[0]==true) this.rr_previous();
  } else {
      window.setTimeout('rr_js_ImageSlider['+this.sliderId+'].rr_previous_Step()', 20);
  }

}


function openLBox(str) {
   myLightbox.start(str);
}

