/*
 * flash()
 * Função que insere o flash no html
 *
 * @param	arquivo		string		Nome do arquivo do flash
 * @param	id			string		Id do elemento onde que o flash irá ser mostrado
 * @param	width		number		Largura do arquivo flash
 * @param	height		number		Altura do arquivo flash
 * @param	wmode		boolean		Indica se o flash terá fundo transparente ou não
 *
 */
function flash(arquivo, id, width, height, wmode){
	// Pega a url atual
	var url = window.location.toString();
	url = url.split('/');
	switch(url[url.length-1]){
		case 'index.php':
			url = 'index';
			break;
		case 'empresa.php':
			url = 'empresa';
			break;
		case 'servicos.php':
			url = 'servicos';
			break;
		case 'trabalhos.php':
			url = 'trabalhos';
			break;
		case 'contato.php':
			url = 'contato';
			break;
	}
	// Insere o Flash
	if(!document.getElementById(id))
		return;
	var so = new SWFObject(arquivo, id, width, height, "8", "#FFFFFF");
	so.useExpressInstall('expressinstall.swf');
	so.addVariable('page', url);
	if(wmode){
		so.addParam('wmode', 'transparent');
	}
	so.write(id);
}

/*
 * servicos()
 * Função que troca a lista de serviços, quase um ajax, mazááá
 * 
 *
 */

function servicos(){
	if(!document.getElementById('descricao'))
		return;
	var lista;
	var links;
	var url	= window.location;
	url 	= url.search;
	url 	= url.substring(9);
	url 	= url.split("&");

	var h3 			= document.getElementById('descricaoServicos').getElementsByTagName('h3')[0];
	var ul 			= document.getElementById('descricao');
	var personal 	= document.getElementById('servicoPersonal');
	var exclusive 	= document.getElementById('servicoExclusive');
	url = url[url.length-1];
	switch(url){
		default:
		case 'personal':
			mudaServico('personal');
			h3.innerHTML = 'Personal';
			break;
		case 'exclusive':
			mudaServico('exclusive');
			h3.innerHTML = 'Exclusive';
			break;
	}
	
	personal.onclick = function(){
		ul.innerHTML = '';
		mudaServico('personal');
		h3.innerHTML = 'Personal';
		return false;
	}
	exclusive.onclick = function(){
		ul.innerHTML = '';
		mudaServico('exclusive');
		h3.innerHTML = 'Exclusive';
		return false;
	}
	
}

function _mudaServico(servico){
	
	var ul = document.getElementById('descricao');
	
	switch(servico){
		case 'personal':
			lista = new Array("Espelhamento de Pintura", "Martelinho de Ouro", "Higienização Interna", "Pequenos Reparos", "Reparos de Colisões", "Manutenção Preventiva/Corretiva");
			links = new Array('servicos.php?st=1', 'servicos.php?st=1', '#3', '#4', '#5', '#6');
			break;
		case 'exclusive':
			lista = new Array("Restauração de Carros Antigos e Raridades", "Serviços para carros especiais", "Acessoria para Colecionadores e Antigomobilistas");
			links = new Array('#1', '#2', '#3');
			break;
		default:
			lista = new Array("Espelhamento de Pintura", "Martelinho de Ouro", "Higienização Interna", "Pequenos Reparos", "Reparos de Colisões", "Manutenção Preventiva/Corretiva");
			links = new Array('#1', '#2', '#3', '#4', '#5', '#6');
			break;
	}

	for(var i = 0; i < lista.length; i++){
		var li		= document.createElement('li');
		var a		= document.createElement('a');
		a.innerHTML = lista[i];
		a.href 		= links[i];
		a.title 	= lista[i];
		li.appendChild(a);
		ul.appendChild(li);
	}
}

window.onload = function(){
	flash('swf/topo.swf', 'animacaoTopo', 748, 251, true);
	flash('swf/subcategoria.swf', 'flashTrabalhos', 265, 515);
	servicos();
}
