/**
 * @author fsweb
 */
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}
function selectedStickie(obj)
{
	obj = document.getElementById(obj);
	var arr = obj.children;
	for(var i=0; i<arr.length; i++)
	{
		arr[i].onclick= function(){
			for(var j=0; j<arr.length; j++)
				arr[j].className='menuTop_li_1';
			this.className='menuTop_li_1_selected';
		}
	}
}

//Create namespace
if (at == undefined) var at = {};
if (at.jer == undefined) at.jer = {};

//Newsticker Class
at.jer.fadescrpt = Class.create();
at.jer.fadescrpt.prototype = {
	initialize: function(){
		$arg = $A(arguments);
		this.d = document;
		this.imgs = new Array();
		this.zInterval = null;
		this.current = 0;
		var rand_no = Math.random();

		this.tempodefade=3000;
		this.pause = false;
		if (!this.d.getElementById || !this.d.createElement) 
			return;
		this.container= $($arg[0]);
		this.elementos = "img";
		if($arg[1] != null)
			this.elementos=$arg[1];		
		if($arg[2] != null)
			this.tempodefade=$arg[2];
		this.imgs = $A(this.container.getElementsByTagName(this.elementos));
		if (this.imgs.length > 0) {
			for (this.i = 1; this.i < this.imgs.length; this.i++) 
			{
				this.imgs[this.i].xOpacity = 0;
				this.imgs[this.i].style.visibility = 'hidden';
				this.imgs[this.i].style.position = 'absolute';
				this.imgs[this.i].style.top = '0px';
				this.imgs[this.i].style.right = '0px';
				this.setOpacity(this.imgs[this.i]);
			}
			
			this.imgs[0].style.visibility = 'visible';
			this.imgs[0].style.position = 'relative';
			this.imgs[0].xOpacity = .99;
			setTimeout(this.so_xfade.bind(this), this.tempodefade);
		}
	},
	so_xfade: function(){
		this.cOpacity = this.imgs[this.current].xOpacity;
		this.nIndex = this.imgs[this.current + 1] ? this.current + 1 : 0;
		this.nOpacity = this.imgs[this.nIndex].xOpacity;
		
		this.cOpacity -= .05;
		this.nOpacity += .05;
		
		this.imgs[this.nIndex].style.visibility = 'visible';
		this.imgs[this.current].xOpacity = this.cOpacity;
		this.imgs[this.nIndex].xOpacity = this.nOpacity;
		
		this.setOpacity(this.imgs[this.current]);
		this.setOpacity(this.imgs[this.nIndex]);
		
		if (this.cOpacity <= 0) {
			this.imgs[this.current].style.visibility = 'hidden';
			this.current = this.nIndex;
			setTimeout(this.so_xfade.bind(this), this.tempodefade);
		}
		else {
			setTimeout(this.so_xfade.bind(this), 50);
		}
	},
	setOpacity: function(obj){
		if (obj.xOpacity > .99) {
			obj.xOpacity = .99;
			return;
		}
		
		obj.style.opacity = obj.xOpacity;
		obj.style.MozOpacity = obj.xOpacity;
		obj.style.filter = 'alpha(opacity=' + (obj.xOpacity * 100) + ')';
	}
}

