// Utilizado para evitar de digitar: document.getElementById toda hora, tornando o processo mais prático
function gE(ID) {
	return document.getElementById(ID);
}

// Utilizado para evitar de digitar: document.getElementsByTagName toda hora, tornando o processo mais prático
function gEs(tag) {
	return document.getElementsByTagName(tag);
}

function RodarFlash(path,variaveis,_width,_height)
{
	document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="'+_width+'" height="'+_height+'">')
		document.write('<param name="movie" value="'+path+'?varurl='+location.href+'&'+variaveis+'">')
		document.write('<param name="quality" value="high">')
		document.write('<param name="wmode" value="transparent">')
		document.write('<embed src="'+path+'?varurl='+location.href+'&'+variaveis+'" width="'+_width+'" height="'+_height+'" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" wmode="transparent"></embed>')
	document.write('</object>')
}

function menu()
{
	var divMenu = gE('menu')
	var linksMenu = divMenu.getElementsByTagName('li')
	var divSubMenu1 = gE('submenu1')
	var linksSubMenu1 = divSubMenu1.getElementsByTagName('li')
	var divSubMenu2 = gE('submenu2')
	var linksSubMenu2 = divSubMenu2.getElementsByTagName('li')
	var itemMenu
	
	var barras = Number(String(location.href).split('/').length)
	var local = String(String(String(location.href).split('/')[barras-1]).replace(/#/, "")).replace(/.html/, "")
	if(local == 'productos-por-beneficio' )
	{
		linksMenu[0].className = 'selecionado'
		linksSubMenu1[2].className = 'selecionado'
	}
	if(local == 'productos-por-version' )
	{
		linksMenu[0].className = 'selecionado'
		linksSubMenu1[1].className = 'selecionado'
	}
	if(local == 'todos-los-productos' )
	{
		linksMenu[0].className = 'selecionado'
		linksSubMenu1[0].className = 'selecionado'
	}
	if(local == 'cepillado-correcto' )
	{
		linksMenu[1].className = 'selecionado'
		linksSubMenu2[0].className = 'selecionado'
	}
	if(local == 'consejos-utiles' )
	{
		linksMenu[1].className = 'selecionado'
		linksSubMenu2[1].className = 'selecionado'
	}
	if(local == 'test' )
	{
		linksMenu[1].className = 'selecionado'
		linksSubMenu2[2].className = 'selecionado'
	}
	if(local == 'historia-crest-in-mexico' )
	{
		linksMenu[2].className = 'selecionado'
	}
	if(local == 'contacto.aspx' )
	{
		linksMenu[3].className = 'selecionado'
	}
	for(i=2;i<linksMenu.length;i++)
	{
		itemMenu = linksMenu[i]
		itemMenu.onmouseover = function ()
		{
			
			gE('submenu1').style.display = 'none'
			gE('submenu2').style.display = 'none'
		}
	}	
	gE('conteudo').onmouseout = function ()
	{	
		gE('submenu1').style.display = 'none'	
		gE('submenu2').style.display = 'none'	
	}
	gE('linkprodutos').onmouseover = function ()
	{
		gE('submenu1').style.display = 'block'
		gE('submenu2').style.display = 'none'
	}
	gE('linkcuidados').onmouseover = function ()
	{
		gE('submenu2').style.display = 'block'
		gE('submenu1').style.display = 'none'	
	}
	
}

// Chama a função loadFunctions ao carregar a página
window.onload = loadFunctions;
function loadFunctions ()
{
	menu()
}
function boxProd() {
	// Cria um 'container' que comportará o produto.
	var objBody = gEs('body').item(0);
	var sizesPage = getPageSize();
	var boxCad = document.createElement('div');
	boxCad.setAttribute('id','boxProd');
	boxCad.onclick = function()
	{
		removerDivs()	
	}
	var wPage = arrayPageSize[0]; // Largura total da página
	var hPage = arrayPageSize[1]; // tamanho total da página
	//alert(arrayPageSize[3])
	//boxCad.style.marginTop = Number(arrayPageSize[3]) + 'px'
	objBody.insertBefore(boxCad, objBody.lastChild);
}
// Utilizado para criar o fundo sobre a página (wiewport), body.
function exibirBgBody() {
	var tagBody = gEs('body').item(0);
	var sizesPage = getPageSize();
	var bgBody = document.createElement('div');
	bgBody.setAttribute('id','bgBody');
	bgBody.style.height = arrayPageSize[1] + 'px';
	bgBody.style.width = arrayPageSize[0] + 'px';
	if (!gE('bgBody')) {
		tagBody.insertBefore(bgBody, tagBody.firstChild);
	}	
}
function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth -20;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}


	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight,xScroll,yScroll) 

}

function produto (idProduto,yScroll)
{
	var valorUrl = $('#tit'+idProduto +' a').attr('href');
	
	if ( $('#tit'+idProduto).attr('abrircom') == 'link'){

		window.open(valorUrl,''); 
		return false;
	}

	exibirBgBody();
	boxProd();
	var tagtitulos = gE('tit'+idProduto).getElementsByTagName('span')
	var titulo1 = tagtitulos[0].innerHTML
	var titulo2 = tagtitulos[1].innerHTML
	var _scroll = (Math.ceil(yScroll-1) * 200)
	self.scroll(0,_scroll)
	gE('boxProd').style.marginTop = (_scroll) + 'px' 
	
gE('boxProd').innerHTML ='<div class="desc"><p>'+gE('desc'+idProduto).innerHTML+'</p></div>'+'<object  width=\"754\" height=\"400\" codebase=\"http://www.adobe.com/go/getflashplayer/" classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\"><param value=\"media/swf/produtoMaior.swf\" name=\"movie\"/><param value=\"transparent\" name=\"wmode\"/><param name="FlashVars" value="imgProduto=media/img/produtos/p'+idProduto+'.png&nameProduct='+titulo1+'&nameTitle='+titulo2+'"/><param value=\"high\" name=\"quality\"/><embed width=\"754\" height=\"400\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" quality=\"high\" src=\"media/swf/produtoMaior.swf?imgProduto=media/img/produtos/p'+idProduto+'.png&nameProduct='+titulo1+'&nameTitle='+titulo2+'\" wmode="transparent"/></object>';
}
// Esta função elimina da página o fundo criado sobre o body e o boxCad;
function removerDivs() {
	var bgBody = gE('bgBody');
	var boxProd = gE('boxProd');
	bgBody.parentNode.removeChild(bgBody);
	if (boxProd) { 
		boxProd.parentNode.removeChild(boxProd);
	}
}

function mostraDica(idDica)
{
	var divDica = gE('detalhes');
	var itens = gE('detalhes').getElementsByTagName('div');
	var i=0;
	for(i=0;i<itens.length;i++)
	{
		gE(itens[i].id).style.display = 'none'
	}
	gE('detalhe'+idDica).style.display = 'block'
	
	var tagLink = gE('listaConselhos').getElementsByTagName('a')
	var j=0;
	for(j=0;j<tagLink.length;j++)
	{
		tagLink[j].style.fontWeight = 'normal'
	}
	tagLink[Number(idDica)-1].style.fontWeight = 'bold'
}

function respostaQuiz(idResposta)
{
	gE('resposta'+idResposta).style.display="block"
	gE('questao'+idResposta).style.marginBottom = '5px';
}

function detectBrowser()
{
	var browser=navigator.appName;
	var b_version=navigator.appVersion;
	var version=parseFloat(b_version);
	if (browser=="Netscape")
	{
		var tagBody = gEs('body').item(0);
		tagBody.className = 'home'
	}
}