function imgScroller(_name) {
  this.speed = 25;
  this.ImageCount = 0;
  this.timeScroll;
  this.Limage = new Array();
  this.mode = 0;
  this.name = _name;
  this.imgClassName = _name;
  this.Loop = 0;
  this.FinalReady = false;
  this.imgShift = 10;
  this.startDelay = 3000;
  this.pixelSpeed = 3;
  this.contentHeight = 50;
  this.aditionalShift = 80;
  this.ibody = document.documentElement;
  this.CurrentWidth = (document.all?this.ibody.scrollLeft+this.ibody.clientWidth : pageXOffset+window.innerWidth-15);
  this.Last = null;
  this.globalCounter = 0;
  
  this.add = function() {
    var imgElemnt = null;
    var sc = document.getElementById("scroller_content");
    this.Loop = (this.Loop == this.ImageCount - 1) ? 0 : this.Loop + 1;
    imgElement = document.createElement('img');
    imgElement.className = this.imgClassName;
    imgElement.style.position = "fixed";
    imgElement.style.left = parseInt(this.Last.style.left) + parseInt(this.Last.style.width) + this.imgShift + "px";
    imgElement.style.width = this.Limage[this.Loop].width + "px";
    imgElement.style.bottom = ((this.contentHeight - this.Limage[this.Loop].height) / 2) + "px";
    imgElement.src = this.Limage[this.Loop].name;
    if (imgElement.addEventListener) {
      eval('imgElement.addEventListener ("mouseover", function(event) { ' + this.name+'.stopScrolling(); } , false);' );
      eval('imgElement.addEventListener ("mouseout", function(event) { ' + this.name+'.startScrolling(); } , false);' );
    } else if (imgElement.attachEvent) {
      eval('imgElement.attachEvent("onmouseover", function(event) { ' + this.name+'.stopScrolling(); } );' );
      eval('imgElement.attachEvent("onmouseout", function(event) { ' + this.name+'.startScrolling(); } );' );
    } else {
      imgElement.onmouseover = this.name + '.stopScrolling';
      imgElement.onmouseout = this.name + '.stopScrolling';
    }

    sc.appendChild(imgElement);
    this.Last = imgElement;
  }
  
  this.init = function() {
    var Length;
    var sc = document.getElementById("scroller_content");
        
    for (i = 0, this.Loop = 0; i <= (this.CurrentWidth + this.aditionalShift); i += (parseInt(this.Limage[this.Loop].width) + this.imgShift)) {
        this.Loop = (this.Loop == this.ImageCount - 1) ? 0 : this.Loop + 1;
        document.write('<img class="' + this.imgClassName + '" style="position: fixed; left:' + i + 'px; bottom: '+((this.contentHeight - this.Limage[this.Loop].height) / 2)+'px; width: ' + this.Limage[this.Loop].width + 'px;" src=' + this.Limage[this.Loop].name + ' onMouseOver="' + this.name + '.stopScrolling()" onMouseOut="' + this.name + '.startScrolling()">');
    }

    for (i = 0, Length = sc.childNodes.length; i < Length; i++) {
      if (sc.childNodes[i] && sc.childNodes[i].nodeType == 1 && sc.childNodes[i].className == this.imgClassName) {
        this.Last = sc.childNodes[i];
      }
    }

    if (window.addEventListener)
      eval('window.addEventListener ("resize", function(event) { ' + this.name+'.CurrentWidth = (document.all?this.ibody.scrollLeft+this.ibody.clientWidth : pageXOffset+window.innerWidth-15); } , false);');
    else if (document.body.attachEvent)
      eval('window.attachEvent("onresize", function(event) { ' + this.name+'.CurrentWidth = (document.all?this.ibody.scrollLeft+this.ibody.clientWidth : pageXOffset+window.innerWidth-15); } );');
    else
      eval('window.onresize = ' + this.name + '.CurrentWidth = (document.all?this.ibody.scrollLeft+this.ibody.clientWidth : pageXOffset+window.innerWidth-15);');

    this.timeScroll = setInterval(this.name+".beginScrolling()", this.startDelay);
  }
  
  this.ready = function() {
    var sc = document.getElementById("scroller_content");
    var Length = sc.childNodes.length;
    
    for (i = 0; i < Length; i++) {
      if (sc.childNodes[i] && sc.childNodes[i].nodeType == 1 && sc.childNodes[i].className == this.imgClassName) {
        if (sc.childNodes[i].complete == false) return false;
      }
    }
    this.FinalReady = true;
    return true; 
  }
  
  this.beginScrolling = function() {
  	if (this.ready() == true){	
  		window.clearInterval(this.timeScroll);
  		this.timeScroll = setInterval(this.name+".autoScroll()", this.speed);
  	}
  }

  this.autoScroll = function() {
    var Left;
    var Width;
    var Length;
    
  	this.mode = 1;
    var sc = document.getElementById("scroller_content");
    Length = sc.childNodes.length;
    
    for (i = 0; i < Length; i++) {
      if (sc.childNodes[i] && sc.childNodes[i].nodeType == 1 && sc.childNodes[i].className == this.imgClassName) {
        Left = parseInt(sc.childNodes[i].style.left);
        Width = -1 * parseInt(sc.childNodes[i].style.width);
        
        sc.childNodes[i].style.left = (Left-this.pixelSpeed) + "px";
        
        if (this.Last == sc.childNodes[i] && (Left + (-1 * Width)) < this.CurrentWidth + this.imgShift)
          this.add();

        if (Left < (Width * 4))
          sc.removeChild(sc.childNodes[i]);

      }
    }
  }

  this.stopScrolling = function() {
  		window.clearInterval(this.timeScroll);
  }
  
  this.startScrolling = function() {
    if (this.FinalReady)
  		this.timeScroll = setInterval(this.name+".autoScroll()", this.speed);
    else
  		this.timeScroll = setInterval(this.name+".beginScrolling()", this.startDelay);
  }

}

function close_scroller(ISS_obj) {
  document.getElementById("scroller").style.height="0";
  document.getElementById("scroller").style.visibility="hidden";
  document.getElementById("longtimeago").style.height="0";
  document.getElementById("longtimeago").style.visibility="hidden";
  document.getElementById("space").style.height="0";
  document.getElementById("expand").style.visibility="visible";
  ISS_obj.stopScrolling();
  document.cookie="vega_banner="+escape("visible=0");
}

function show_scroller(ISS_obj) {
  document.getElementById("scroller").style.height="50px";
  document.getElementById("scroller").style.visibility="visible";
  document.getElementById("longtimeago").style.height="72px";
  document.getElementById("longtimeago").style.visibility="visible";  
  document.getElementById("space").style.height="72px";
  document.getElementById("expand").style.visibility="hidden";
  if (!ISS_obj.FinalReady) 
    ISS_obj.startScrolling();
  else
    ISS_obj.beginScrolling();
  document.cookie="vega_banner="+escape("visible=1");
}

function check_Cookie_name(name) {
  var ciacho = unescape(document.cookie);
  if (ciacho.indexOf(name) != -1) {
    var valStartPtr  = ciacho.indexOf(name)+name.length+1;
    var valEndPtr    = (ciacho.indexOf(";", valStartPtr) != -1) ? ciacho.indexOf(";", valStartPtr) : ciacho.length; 
    var retStr = ciacho.substring(valStartPtr+name.length-3, valEndPtr);
    return parseInt(retStr);
    }
  else return -1;
}

function Ibanner(name, width, height, link) {
	this.name = name;
	this.width = width;
	this.height = height;
	this.link = link;
}

