/*

function FadeEffect () {

  this.timer = 0;

  this.speed = 7;



  window.changeOpacity = function (opacity) {

    window.obj.opacity=(opacity/100);

    window.obj.MozOpacity=(opacity/100);

    window.obj.KhtmlOpacity=(opacity/100);

  }


x
  this.Execute = function (obj, change_cb) {

    window.obj = obj;

    this.Start();

    window.setTimeout(change_cb, this.timer++ * this.speed);

    this.Stop();

  }



  this.Start = function (obj) {

    for(i = 185; i > 0;  i-=2) {

      var call = 'window.changeOpacity('+i+')';

      window.setTimeout(call, this.timer++ * this.speed);

    }

  }



  this.Stop = function (obj) {

    for(i = 0; i <= 185; i+=2) {

      var call = 'window.changeOpacity('+i+')';

      window.setTimeout(this.changeOpacity, this.timer++ * this.speed, obj, i);

    }

  }

}

*/

function BannerPanel1 (id) {

  this.moduleId = '';

  this.container = null;

  this.images = null;

  this.current = 0;

  //this.Effect = new FadeEffect();



  this.initialize = function (id) {

	/*  	

    var divs = document.getElementsByTagName('div');



    for (var i=1; i<divs.length; i++) {

      if (divs[i].className.split(' ').contains('banner')) {

        this.container = divs[i];

        break;

      }

    }

    */

	

	this.container = document.getElementById(id);

	if (!this.container) return;

	

	this.moduleId = id.toString().replace('banner', '');



    this.loadImages();

  }



  this.setCurrentImage = function () {

    //FIX pra IE6

    if (!window.BannerPanel1.images.length) {

      //if (window.navigator.appVersion.split('; ')[1] == 'MSIE 60') window.BannerPanel1.container.innerHTML = 'nenhum banner selecionado';

      var r = new ajaxRequest();

      eval ('window.BannerPanel1.images = ' + r.get(baseURL + '/admin/banners' + window.BannerPanel1.moduleId + '/banners.php') + ';');

    }



    var img = document.createElement('img');

    img.setAttribute('src', window.BannerPanel1.images[this.current].src);

    //img.setAttribute('height', window.BannerPanel1.container.getAttribute('height'));

    //img.setAttribute('width',  window.BannerPanel1.container.getAttribute('width'));



    window.BannerPanel1.setImage(img);

  }



  this.ChangeImage = function () {

    window.BannerPanel1.current = ( window.BannerPanel1.current + 1 > window.BannerPanel1.images.length-1) ? 0 : window.BannerPanel1.current + 1;

    //window.BannerPanel1.Effect.Execute(window.BannerPanel1.container, window.BannerPanel1.setCurrentImage);

    //window.BannerPanel1.Effect.Start(window.BannerPanel1.container);

    window.BannerPanel1.setCurrentImage();

    //window.BannerPanel1.Effect.Stop(window.BannerPanel1.container);

  }



  this.setImage = function (img) {

    var lastImg = null;



    for (var i=0; i<window.BannerPanel1.container.childNodes.length; i++) {

      if (window.BannerPanel1.container.childNodes[i].nodeType == 1) {

        lastImg = window.BannerPanel1.container.childNodes[i];

      }

    }



    if (lastImg) {

      // troca a image

      //alert(lastImg); alert(img);

      window.BannerPanel1.container.replaceChild(img, lastImg);

    } else {

      // adiciona a imagem

      window.BannerPanel1.container.appendChild(img);

    }

  }



  this.loadImages = function () {

    this.images = new Array();

    var r = new ajaxRequest();

    r.get(baseURL + '/admin/banners' + this.moduleId + '/banners.xml', this.loadImages_Response);

  }



  this.loadImages_Response = function (doc) {

    var imgs = doc.getElementsByTagName('banner');



    for (var i=0; i<imgs.length; i++) {

      var im = new Image();

      im.src = imgs[i].getAttribute('src');



      //IE fix!

      if (window.BannerPanel1 && ! window.BannerPanel1.images) window.BannerPanel1.images = new Array();



      window.BannerPanel1.images.add(im);

    }



    window.BannerPanel1.setCurrentImage();

  }



  this.initialize(id);

}



function BannerPanel1_OnLoad() {

  if (! document.getElementById('banner1') ) return;

  

  window.BannerPanel1 = new BannerPanel1('banner1');



  window.setInterval(window.BannerPanel1.ChangeImage, 10000);

}



addEvent(window, 'load', BannerPanel1_OnLoad);



