﻿// VERIFICO CHE SIANO PRESENTI prototype e scriptaculous
if ((typeof Prototype == 'undefined') || (typeof Effect == 'undefined')) {
  alert("Attenzione!!!\r\n\r\nPer il corretto funzionamento includere le seguenti librerie:\r\n\r\nprototype.js\r\nscriptaculous.js");
};

// ==================================================================================================================
// SLIDE : 
// ==================================================================================================================
function habaSlide(parentName, className) {

  this.parent = document.getElementById(parentName);
  this.className = className;
  this.imgWidth;
  this.slideInUse = 1;
  this.repeat = false;
  this.slideNumber;
  this.selectedSlide;

  var slider = document.createElement('DIV');
  slider.className = this.className;
  this.parent.appendChild(slider);
  this.slider = slider;

};

habaSlide.prototype = {

  addTab: function(imgSrc, url, description) {
    var imgSlide = document.createElement('IMG');
    with (imgSlide) {
      setAttribute('src', imgSrc);
      style.width = this.imgWidth + 'px';
      style.height = (this.imgWidth * .75) + 'px';
      style.float = "left";
      style.cursor = "pointer";
      var newAttr = document.createAttribute("description");
      newAttr.value = description;
      setAttributeNode(newAttr);
    };
    if (imgSlide.addEventListener) {
      imgSlide.addEventListener('click', function() { window.open(url, '_self') }, false);
    } else {
      imgSlide.attachEvent('onclick', function() { window.open(url, '_self') });
    };
    this.slider.appendChild(imgSlide);
    this.slider.style.width = (this.slider.childNodes.length) + 'em';
    this.slideNumber = this.slider.childNodes.length;
  },

  nextSlide: function() {
    if (this.slideInUse == this.slider.childNodes.length) {
      if (this.repeat) { this.slideInUse = 0; } else { return; };
    }
    this.slideInUse = this.slideInUse + 1;
    dest_position = ((this.slideInUse - 1) * this.imgWidth) * (-1);
    new Effect.Move(this.slider, { x: dest_position, y: 0, mode: 'absolute' });
  },

  prevSlide: function() {
    if (this.slideInUse == 1) { return; }
    this.slideInUse = this.slideInUse - 1;
    dest_position = ((this.slideInUse - 1) * this.imgWidth) * (-1);
    new Effect.Move(this.slider, { x: dest_position, y: 0, mode: 'absolute' });
  }

};
// ==================================================================================================================

