function changeOpac(opacity, id) {
	var object = document.getElementById(id).style;
	object.opacity = (opacity / 100);
	object.MozOpacity = (opacity / 100);
	object.KhtmlOpacity = (opacity / 100);
	object.filter = "alpha(opacity=" + opacity + ")";
}

function opacity(id, opacStart, opacEnd, millisec) {
   //speed for each frame
	var speed = Math.round(millisec / 100);
	var timer = 0;

	//determine the direction for the blending, if start and end are the same nothing happens
	if(opacStart > opacEnd) {
		for(i = opacStart; i >= opacEnd; i--) {
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	} else if(opacStart < opacEnd) {
		for(i = opacStart; i <= opacEnd; i++)
			{
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	}
} 

function blendimage(divid, imageid, imagefile, millisec) {
	var speed = Math.round(millisec / 100);
	var timer = 0;
	//Coloca a imagem da frente para o background
	document.getElementById(divid).style.backgroundImage = "url(" + document.getElementById(imageid).src + ")";

	//Faz a imagem transparente
	changeOpac(0, imageid);


	//troca a imagem da frente pela próxima imagem, com tempo para nao fazer isso antes dela ficar transparente
	setTimeout("document.getElementById('"+imageid+"').src = '"+imagefile+"'",100);


	//esmaece (fade in) a imagem
	for(i = 0; i <= 100; i++) {
		setTimeout("changeOpac(" + i + ",'" + imageid + "')",(timer * speed));
		timer++;
	}
}


//SCRIPT DOS SEGMENTOS -----------------------------------------------------------------------------------------------
function mostrar_segmento(segmento){
	//coloca os que tao marcados como nao marcados
	var Cells =	document.getElementById("embalagens").getElementsByTagName("li");
	for (i=0; i<Cells.length; i++){
		if (Cells[i].className == "marcado"){
			Cells[i].className = 'desmarcado';
		}
	}
	//muda a imagem do segmento
	blendimage('fotos-embalagens','foto','imagens/embalagens/'+segmento+'.jpg',250);
}
// FIM DO SCRIPT DOS SEGMENTOS --------------------------------------------------------------------------------------








//SCRIPT DO BANNER -----------------------------------------------------------------------------------------------

function atualiza_banner(numero_imagem,max_numero){
	mostra_banner(numero_imagem);

	if (numero_imagem==max_numero){
		numero_imagem = 1;
	}else{numero_imagem++;}
	
	setTimeout("atualiza_banner("+numero_imagem+","+max_numero+")", 10000); // 10 segundos
}

function mostra_banner(banner){
	blendimage('banner','banner-rand','imagens/banners/imagem-banner'+banner+'.jpg',2000);
}

//FIM DO SCRIPT DO BANNER -----------------------------------------------------------------------------------------------









//SCRIPT DOS DISPLAYS -----------------------------------------------------------------------------------------------
var girando_direita = false;
var girando_esquerda = false;

function gira(divid,imageid,tipo,ft,max_numero,millisec,direcao){
	var speed = Math.round(millisec / 100);
	var timer = 0;
	var tam_caminho = document.getElementById(imageid).src;
	var numero_imagem;
	//Coloca a imagem da frente para o background
	document.getElementById(divid).style.backgroundImage = "url(" + document.getElementById(imageid).src + ")";
	//
	//pega o numero da imagem atual
	//alert(document.getElementById(imageid).src.substr((tam_caminho.length -5) ,1));
	numero_imagem = parseInt(document.getElementById(imageid).src.substr((tam_caminho.length -5) ,1));

	//Faz a imagem transparente
	changeOpac(0, imageid);

	if (direcao == 'direita')
	{
		if (numero_imagem==max_numero){
			numero_imagem = 1;
		}else{numero_imagem++;}
	}else{
		if (numero_imagem==1){
			numero_imagem = max_numero;
		}else{numero_imagem = numero_imagem-1;}
	}	

	//troca a imagem da frente pela próxima imagem, com tempo para nao fazer isso antes dela ficar transparente
	setTimeout("document.getElementById('"+imageid+"').src = 'imagens/displays/"+tipo+"/"+ft+"/"+numero_imagem+".jpg'",100);


	//esmaece (fade in) a imagem
	for(i = 0; i <= 100; i++) {
		setTimeout("changeOpac(" + i + ",'" + imageid + "')",(timer * speed));
		timer++;
	}
}

function gira_esquerda(divid,imageid,tipo,ft,max_numero,millisec){

	if (girando_esquerda == true)
	{
		gira(divid,imageid,tipo,ft,max_numero,millisec,'esquerda');
		setTimeout("gira_esquerda('"+divid+"','"+imageid+"','"+tipo+"','"+ft+"',"+max_numero+","+millisec+")",500);
	}
}

function gira_direita(divid,imageid,tipo,ft,max_numero,millisec){	

	if (girando_direita == true)
	{
		gira(divid,imageid,tipo,ft,max_numero,millisec,'direita');
		setTimeout("gira_direita('"+divid+"','"+imageid+"','"+tipo+"','"+ft+"',"+max_numero+","+millisec+")",500);
		//girando_direita = false;
	}
}

//FIM DO SCRIPT DOS DISPLAYS  -----------------------------------------------------------------------------------------------
