//Criando objeto foto
function foto(id,estilo,url,legenda,width,height,left,top){
	
	try{
		this.id = id;
		this.estilo = estilo;
		this.url = url;
		this.legenda = legenda;
		this.width = width;
		this.height = height;
		this.top = top;
		this.left = left;
	
		//Criando a DIV que será a foto
		var divFoto = document.createElement('DIV');
		
		//Criando nova imagem
		var objImg = new Image();
		objImg.src = this.url;
		if(this.legenda)objImg.alt = this.legenda;
		
		divFoto.appendChild(objImg);
		
		//Definindo seus atributos
		divFoto.style.width = intToPixel(this.width);
		divFoto.style.height = intToPixel(this.height);
		divFoto.style.top = intToPixel(this.top);
		divFoto.style.left = intToPixel(this.left);
		

		//Criando a DIV que será o container da foto + legenda
		var divFotoContainer = document.createElement('DIV');

		divFotoContainer.id = this.id;
		divFotoContainer.className = this.estilo;

		divFotoContainer.style.width = intToPixel(this.width);
		divFotoContainer.style.height = intToPixel(this.height);
		divFotoContainer.style.top = intToPixel(this.top);
		divFotoContainer.style.left = intToPixel(this.left);

		divFotoContainer.appendChild(divFoto);
	
		//Criando a legenda, caso necessário
		if(this.legenda){
			
			divFotoContainer.style.width = intToPixel(this.width+230);

			divLegenda = document.createElement('DIV');
			
			divLegenda.id = this.id + 'Legenda';
			divLegenda.className = 'fotoLegenda';
			divLegenda.style.top = '0px'
			divLegenda.style.left = intToPixel(this.width+60);

			
			divLegenda.innerHTML = this.legenda;
			
			divFotoContainer.appendChild(divLegenda);
		}
	
		this.toDiv = divFotoContainer;
		
	}catch(e){
		
		erro(e);		
	}
	
}

//Criando objeto slide
function slide(arrayFotos,divAlvo,tempo,fotoContador){
	
	try{

		//Capturando os objetos
		this.divAlvo = divAlvo;
		this.arrayFotos = arrayFotos;
		this.tempo = tempo;
		this.numFoto = 0;
		this.fotoContador = fotoContador;
		this.zindex = 0;
		
		this.proximo();
		
		var oThis = this;
		
		//Fazendo slide automático das fotos
		if(this.arrayFotos.length > 1)setInterval(function () { oThis.proximo(1); }, tempo*1500);

	}catch(e){
		
		erro(e);	
	}
	
}

//Adicionando o metodo proximo ao objeto slide
slide.prototype.proximo = function(incremento){
		
	try{
		
		if(!incremento)incremento = 1;
		
		var novaPosicao = this.numFoto + parseInt(incremento);

		//Caso tenha chegado ao fim da lista, voltar para o início
		if(novaPosicao > this.arrayFotos.length)novaPosicao = 1;

		if( (novaPosicao >= 1) && (novaPosicao <= this.arrayFotos.length) ){
			
			this.numFoto = novaPosicao;
			
			var novaFoto = this.arrayFotos[this.numFoto-1].toDiv;

			this.zindex ++;

			//Verificando se já existe alguma DIV com este nome para remover
			if( getObject(novaFoto.id) )getObject(this.divAlvo).removeChild( getObject(novaFoto.id) );
			
			setAlpha(novaFoto,0)
						
			//Adicionando a DIV foto ao alvo
			getObject(this.divAlvo).appendChild(novaFoto);
			
			//Criando efeito Fade na DIV
			fade(novaFoto.id,'+',1);

			//Verificando se existe contador das fotos e atualizando
			if(getObject(this.fotoContador)){
			
				getObject(this.fotoContador).innerHTML = "Foto "+this.numFoto+" de "+this.arrayFotos.length;
				
			}

		}

	}catch(e){
		
		erro(e);	
	}

}

/* Produz o efeito de fadeOut na div */
function fade(nome,sinal,alpha){
	
	try{
	
		if(document.getElementById(nome)){
	
			if(alpha > 0 && alpha <= 100){
		
				eval('alpha'+sinal+'= 10;');
				
				var obj = document.getElementById(nome);
				
				if(isIe()){
					
					// IE/Win
					obj.style.filter = "alpha(opacity:"+alpha+")";
				}else{
				
					// Safari<1.2, Konqueror
					obj.style.KHTMLOpacity = alpha/100;
					
					// Older Mozilla and Firefox
					obj.style.MozOpacity = alpha/100;
					
					// Safari 1.2, newer Firefox and Mozilla, CSS3
					obj.style.opacity = alpha/100;
				}
				
				setTimeout("fade('"+nome+"','"+sinal+"',"+alpha+")",100);
		
			}else{
				
				if(this.onReturn)eval(this.onReturn);
				
				return alpha;
			}
		}

	}catch(e){
	
		erro(e); 
	
	}
}

function abreIdioma(objLink){
	
	if(objLink){
		getObject('boxIdioma').style.top = intToPixel(getTop(objLink)-5);
		getObject('boxIdioma').style.left = intToPixel(getLeft(objLink)-5);
	}

	getObject('boxIdioma').style.display = 'block';
}

function fechaIdioma(){
	
	getObject('boxIdioma').style.display = 'none';
}


function abreStarwoodBrands(objLink){
	
	if(objLink){
		getObject('starwoodBrands').style.top = intToPixel(getTop(objLink) - 180);
		getObject('starwoodBrands').style.left = intToPixel(getLeft(objLink) - 9);
	}

	getObject('starwoodBrands').style.display = 'block';
}

function fechaStarwoodBrands(){
	
	getObject('starwoodBrands').style.display = 'none';
}

function isIe(){
	
	try{
	
		return (navigator.appVersion.indexOf("MSIE") != -1) ? (navigator.appVersion.indexOf("Mac") != -1) ? false : true  : false;

	}catch(e){
		erro(e);	
	}
}

//Define o Alpha do elemento
function setAlpha(objeto,valor){

	try{
		//Definindo o alpha inicial de acordo com o browser
		if(isIe()){
			// IE/Win
			getObject(objeto).style.filter = "alpha(opacity:"+valor+")";
			
		}else{
			// Safari 1.2, newer Firefox and Mozilla, CSS3
			getObject(objeto).style.opacity = valor/100;
		}

	}catch(e){
		erro(e);
	}

}

//Retorna o objeto passado verificando o método
function getObject(objeto){

	try{

		var objAlvo;
	
		if(isObject(objeto)){
		
			objAlvo = objeto;
		
		}else{
		
			objAlvo = document.getElementById(objeto);
		
		}
		
		return objAlvo;

	}catch(e){
		erro(e);
	}
}

//Retorna o objeto passado verificando o método
function getArray(objeto,separador){

	try{

		var objAlvo;
	
		if(isArray(objeto)){
		
			objAlvo = objeto;
		
		}else{
		
			if(!separador){
				objAlvo = objeto.split(',');
			}else{
				objAlvo = objeto.split(separador);
			}
		
		}
		
		return objAlvo;

	}catch(e){
		erro(e);
	}
}

//Verifica se o objeto é do tipo Object
function isObject(objeto){

	try{
		if(typeof(objeto) == 'object')return true;

	}catch(e){
		erro(e);
	}
	
}

//Verifica se o objeto é do tipo Array
function isArray(objeto){

	try{

		if(isObject(objeto) && objeto.constructor == Array)return true;

	}catch(e){
		erro(e);
	}

}

//Retorna a distancia do objeto ao Topo da página
function getTop(objeto){

	try{
		var objeto = getObject(objeto); 
	
		var top  = 0;
	
		while (objeto.offsetParent){
			top  += objeto.offsetTop;
			objeto = objeto.offsetParent;
		}
	
		top  += objeto.offsetTop;
	
		return top;
		
	}catch(e){
		erro(e);
	}
}

//Retorna a distancia do objeto a Esquerda da página
function getLeft(objeto){

	try{
		var objeto = getObject(objeto); 
	
		var left = 0;
	
		while (objeto.offsetParent){
			left += objeto.offsetLeft;
			objeto = objeto.offsetParent;
		}
	
		left += objeto.offsetLeft;
	
		return left;
	
	}catch(e){
		erro(e);
	}
}

//Trata erro
function erro(e,construtor){

	alert(construtor);

	for (var i in e) alert(i + ' = ' + e[i]);

}

function pixelToInt(valor){

	try{
	
		return parseInt(valor.replace('px',''));
			
	}catch(e){
		erro(e);
	}
	
}

function intToPixel(valor){
	
	try{
		
		return String(valor).concat('px');

	}catch(e){
		erro(e);
	}
	
}

function getElementsByClassName(classe,objetoBase){
	
	if(objetoBase){
	
		var colecao = objetoBase.getElementsByTagName('*');
	}else{
		
		var colecao = document.getElementsByTagName('*');
	}
	
	var arrayElements = new Array();
	
	for(var x=0; x < colecao.length; x++){
		
		if(colecao[x].className == classe)arrayElements.push(colecao[x]);
	}
	
	return arrayElements;
	
}

function getPageScroll(){
	
	var yScroll;
	
	if(self.pageYOffset){
		yScroll = self.pageYOffset;
		
	}else if(document.documentElement && document.documentElement.scrollTop){
		yScroll = document.documentElement.scrollTop;
	
	}else if(document.body){
		yScroll = document.body.scrollTop;
	}

	arrayPageScroll = {yScroll:yScroll};
	
	return arrayPageScroll;

}

