/**
 * @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();
    }
  }
}
// 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();
		rand_no = rand_no * 20000;

		this.tempodefade=1000+rand_no;
		this.pause = false;
		if (!this.d.getElementById || !this.d.createElement) 
			return;
		if($($arg[0]) == null)
			return false;
		this.imgs = $($arg[0]).getElementsByTagName('img');
		if(this.imgs.length>1)
		{
			if(this.imgs[0])
			{
			if (this.imgs.length > 0) {
			for (this.i = 1; this.i < this.imgs.length; this.i++) 
				this.imgs[this.i].xOpacity = 0;
			
			this.imgs[0].style.display = 'block';
			this.imgs[0].xOpacity = .99;
			setTimeout(this.so_xfade.bind(this), this.tempodefade);
			}
			}
		}
	},
	so_xfade: function(){
		if(!this.imgs[this.current])
			return;
		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.display = 'block';
		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.display = 'none';
			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) + ')';
	}
}
var mainfades;
//addLoadEvent( function(){ setInterval( function() {new at.jer.fadescrpt("imgProdListImg2")},2000)});
//addLoadEvent( function(){ setInterval( function() {new at.jer.fadescrpt("imgProdListImg9")},3000)});




	function destaquefade(limite){
		if(contd==limite)
		{
			for(var i=1; i<=limite; i++)
			{
				$('l_produto'+i).style.display='block';
			}
		}
		if(contd==0)
		{
			contd=limite;
			efeito = new Effect.toggle('l_produto'+contd, 'appear');
		}
		else
		{
		efeito = new Effect.toggle('l_produto'+contd, 'appear');
		contd--;
		}
	}

var contd = 4;
//addLoadEvent( function(){ setInterval( function() {destaquefade(4)},3000)});



//GETELEMENTSBYCLASSNAME CROSSBROWSER

function getElementsByClassName(container, tagname, classname) {
	 
	 /* only execute in 5+ browsers. */
	 if (!document.getElementById) return false;

	 /* get all elements with the tag name tagname. */

	 var TagElements = container.getElementsByTagName(tagname);

	 /* define an array which will hold the elements with the class name classname. */
	 var elementsByClassName = new Array();

	 /* Look at all the elements in TagElements, and find the ones with the class name classname. */

	 for (i=0; i<TagElements.length; i++) {
	  if (TagElements[i].className == classname) {
	    elementsByClassName[elementsByClassName.length] = TagElements[i];
	    }
	 }
	  return elementsByClassName;
	}
function menuTopoSelect(id)
{
    var lisMenuTop = $('menuTop').getElementsByTagName('li');
    var found = false;
    for(i=0; i<lisMenuTop.length; i++)
    {
        if(lisMenuTop[i].id == id)
        {
        	lisMenuTop[i].style.background = "url(../images/btSelected_1.jpg) no-repeat left center";
        	lisMenuTop[i].getElementsByTagName('a')[0].style.background = "url(../images/btSelected_2.jpg) no-repeat right center";
        	lisMenuTop[i].getElementsByTagName('a')[0].style.color = "#040404";
        	found=true;
        }
        else
        {
        	lisMenuTop[i].style.background = "none";
    		lisMenuTop[i].getElementsByTagName('a')[0].style.background = "none";
        	lisMenuTop[i].getElementsByTagName('a')[0].style.color = "#b7b8b8";
        }
    }
    if(found==false)
    {
    	//lisMenuTop[0].style.background = "url(../images/btSelected_1.jpg) no-repeat left center";
		//lisMenuTop[0].getElementsByTagName('a')[0].style.background = "url(../images/btSelected_2.jpg) no-repeat right center";
    	//lisMenuTop[0].getElementsByTagName('a')[0].style.color = "#040404";
    } 
    if(id=="home")
    {
    	lisMenuTop[0].style.background = "url(../images/btSelected_1.jpg) no-repeat left center";
		lisMenuTop[0].getElementsByTagName('a')[0].style.background = "url(../images/btSelected_2.jpg) no-repeat right center";
    	lisMenuTop[0].getElementsByTagName('a')[0].style.color = "#040404";
    }
}
function trocaVideo(caller, video)
{
	var cnt = 0;
	while($('flashMovie'+cnt)){
	$('flashMovie'+cnt).style.display='none';
	$('videoCaller'+cnt).className='videoCallerEsperando';
	cnt++;
	}
	$('flashMovie'+video).style.display='block';
	$('flashMovie'+video).style.visibility='visible';
	caller.className = 'videoCallerSeleccionado';
}

