var tooltip=function(){
	var id = 'tt';
	var top = 3;
	var left = 3;
	var maxw = 300;
	var speed = 10;
	var timer = 20;
	var endalpha = 95;
	var alpha = 0;
	var tt,t,c,b,h;
	var ie = document.all ? true : false;
	return{
		show:function(v,w){
			if(tt == null){
				tt = document.createElement('div');
				tt.setAttribute('id',id);
				t = document.createElement('div');
				t.setAttribute('id',id + 'top');
				c = document.createElement('div');
				c.setAttribute('id',id + 'cont');
				b = document.createElement('div');
				b.setAttribute('id',id + 'bot');
				tt.appendChild(t);
				tt.appendChild(c);
				tt.appendChild(b);
				document.body.appendChild(tt);
				tt.style.opacity = 0;
				tt.style.filter = 'alpha(opacity=0)';
				document.onmousemove = this.pos;
			}
			tt.style.display = 'block';
			c.innerHTML = v;
			tt.style.width = w ? w + 'px' : 'auto';
			if(!w && ie){
				t.style.display = 'none';
				b.style.display = 'none';
				tt.style.width = tt.offsetWidth;
				t.style.display = 'block';
				b.style.display = 'block';
			}
			if(tt.offsetWidth > maxw){tt.style.width = maxw + 'px'}
			h = parseInt(tt.offsetHeight) + top;
			clearInterval(tt.timer);
			tt.timer = setInterval(function(){tooltip.fade(1)},timer);
		},
		pos:function(e){
			var u = ie ? event.clientY + document.documentElement.scrollTop : e.pageY;
			var l = ie ? event.clientX + document.documentElement.scrollLeft : e.pageX;
			tt.style.top = (u - h) + 'px';
			tt.style.left = (l + left) + 'px';
		},
		fade:function(d){
			var a = alpha;
			if((a != endalpha && d == 1) || (a != 0 && d == -1)){
				var i = speed;
				if(endalpha - a < speed && d == 1){
					i = endalpha - a;
				}else if(alpha < speed && d == -1){
					i = a;
				}
				alpha = a + (i * d);
				tt.style.opacity = alpha * .01;
				tt.style.filter = 'alpha(opacity=' + alpha + ')';
			}else{
				clearInterval(tt.timer);
				if(d == -1){tt.style.display = 'none'}
			}
		},
		hide:function(){
			clearInterval(tt.timer);
			tt.timer = setInterval(function(){tooltip.fade(-1)},timer);
		}
	};
}();




function Contato(_id, _mensagem){
	this.id = _id;
	this.mensagem = _mensagem;
}

function Categoria(_id, _name, _status, _foto){
	this.id = _id;
	this.name = _name;
	this.status = _status;
	this.foto = _foto;
	
}

function Subcategoria(_id, _name, _status, _categoria){
	this.id = _id;
	this.name = _name;
	this.status = _status;
	this.categoria = _categoria;
}

function Brinde(_id, _name, _status, _preco, _destaque, _description, _subcategoria, _categoria, _foto, _thumb, _zoom, _hexadecimal, _cor){
	this.id = _id;
	this.name = _name;
	this.status = _status;
	this.preco = _preco;
	this.destaque = _destaque;
	this.description = _description;
	this.categoria = _categoria;
	this.subcategoria = _subcategoria;
	this.foto = _foto;
	this.thumb = _thumb;
	this.zoom = _zoom;
	this.sizeP = 0;
	this.sizeM = 0;
	this.sizeG = 0;
	this.color = null;
        this.hexadecimal = _hexadecimal;
        this.cor = _cor;
        
}

function oneChange(){
	
}

function fnValidaContato(){

	var nome = document.getElementById('contato-nome')
	var email = document.getElementById('contato-email')
	var endereco = document.getElementById('contato-endereco')
	var telefone = document.getElementById('contato-telefone')
	var departamento = document.getElementById('contato-departamento')
	var mensagem = document.getElementById('contato-mensagem')
	
	if(nome.value == 'NOME/RAZAO SOCIAL' || nome.value == ''){
		alert('Insira seu Nome ou Razão Social');	
	}else 
	if(email.value == 'E-MAIL' || email.value == ''){
		alert('Insira seu E-Mail');	
	}else 
	if(endereco.value == 'ENDERECO' || endereco.value == ''){
		alert('Insira seu Endereço');	
	}else 
	if(telefone.value == 'TELEFONE' || telefone.value == ''){
		alert('Insira seu Telefonel');	
	}else 
	if(departamento.value == 'DEPARTAMENTO' || departamento.value == ''){
		alert('Escolha um Departamento');	
	}else 
	if(mensagem.value == 'MENSAGEM' || mensagem.value == ''){
		alert('Insira uma Mensagem');	
	}else {
		document.formContato.submit();
		void(0);
		
		//enviaContato(nome.value, email.value, endereco.value, telefone.value, departamento.value, mensagem.value);
	}
	
}

function fnValidaBriefing(){

	
	var nome = document.getElementById('briefing-nome')
	var email = document.getElementById('briefing-email')
	var telefone = document.getElementById('briefing-telefone')
	var tipo = document.getElementById('briefing-tipo-evento')
	var qtd = document.getElementById('briefing-qtd-brindes')
	var verba = document.getElementById('briefing-verba-item')
	
	if(nome.value == 'NOME' || nome.value == ''){
		alert('Insira seu Nome');	
	}else 
	if(email.value == 'E-MAIL' || email.value == ''){
		alert('Insira seu E-Mail');	
	}else 
	if(telefone.value == 'TELEFONE' || telefone.value == ''){
		alert('Insira seu Telefone');	
	}else 
	if(tipo.value == 'TIPO DE EVENTO' || tipo.value == ''){
		alert('Escolha um tipo de Ação ou Evento');	
	}else 
	if(qtd.value == 'QUANTIDADE DE BRINDES' || qtd.value == ''){
		alert('Insira a quantidade de Brindes');	
	}else 
	if(verba.value == 'VERBA POR ITEM' || verba.value == ''){
		alert('Insira a verba por cada item');	
	}else {
		document.formBriefing.submit();
		void(0);
	}
	
}

function enviaContato(nome, email, endereco, telefone, departamento, mensagem){
	
	
	//-- carrega os brindes
	$.ajax({type: "GET", url: "common/inc/contato-envia.php?nome="+nome+"&email="+email+"&endereco="+endereco+"&telefone="+telefone+"&departamento="+departamento+"&mensagem="+mensagem+"", dataType: "html", async: false,
		success: function(xml){	
		
			$(xml).find('resposta').each(function(){
				var id = $(this).attr('id');
				var mensagem = $(this).attr('mensagem');
				
				var contac = new Contato(id, mensagem);
				contatoList.push(contac);
				
			});
		},
		error: function(xml){
			contatoList = null;
		},
		complete: function(xml){
			
			if(contatoList != null && contatoList.length > 0){
				
				$('#gridContato').children().remove();
				
				fnExibeContato();
			
			}else{
				contatoList = null;
			}
		}
	});
						
	
}

var contatoList = new Array();
var categList = new Array();
var subcategList = new Array();
var brindeList = new Array();

var selected_categ = null;
var selected_subcateg = null;
var selected_brinde = null;



$(document).ready(function(){	
		
	$('#sizeP').numeric();
	//$('#sizeM').numeric();
	$('#sizeG').numeric();
	//-- carrega as categorias
	
	var xis ='';		
	$.ajax({type: "GET", url: "common/xml/brindes.php", dataType: "xml",
		success: function(xml){
			///alert('sucess');
			///console.log(xml);
			
			$(xml).find('categoria').each(function(){
							   
				var id = $(this).attr('id');
				var name = $(this).attr('name');
				var status = $(this).attr('ativo');
				var foto = $(this).attr('foto');
				if(status.toString() == 'true'){
					var categ = new Categoria(id, name, status, foto);
					categList.push(categ);
				}
				//xis += name;
					
				$(this).find('subcategoria').each(function(){
					var sub_id = $(this).attr('id');
					var sub_name = $(this).attr('name');
					var sub_status = $(this).attr('ativo');
					
					if(status.toString() == 'true'){
						var subcateg = new Subcategoria(sub_id, sub_name, sub_status, categ);
						subcategList.push(subcateg);
					}
					
						//alert('sucess3');
					$(this).find('brinde').each(function(){
						var bri_id = $(this).attr('id');
						var bri_name = $(this).attr('name');
						var bri_status = $(this).attr('ativo');
						var bri_destaque = $(this).attr('destaque');
						var bri_preco = $(this).attr('preco');
						var bri_description = $(this).attr('description');
						var bri_foto = $(this).attr('foto');
						var bri_thumb = $(this).attr('thumb');
						var bri_zoom = $(this).attr('zoom');
                        var bri_hexadecimal = $(this).attr('hexadecimal');
						var bri_cor = $(this).attr('cor');
						
						
						if(status.toString() == 'true'){
							var brinde = new Brinde(bri_id, bri_name, bri_status, bri_preco, bri_destaque, bri_description, subcateg, subcateg.categoria, bri_foto, bri_thumb, bri_zoom, bri_hexadecimal, bri_cor);
							brindeList.push(brinde);
						}
					});
				});
			});
						
			
		},
		error: function(xml){
			//alert(xml);
			categList = null;
			subcategList = null;
			brindeList = null;
		},
		complete: function(xml){
			//alert('completo: ');
			if(brindeList != null && brindeList.length > 0){
				
				$('#gridCategorias').children().remove();
				$('#gridSubCategorias').children().remove();
				$('#gridProdutos').children().remove();

				
				fnCreateCategoriasGrid();
				
			}else{
				categList = null;
				subcategList = null;
				brindeList = null;
			}
		}
	});
	
	if(categList == null){
		alert('ERR: erro ao carregar o xml.');
		return;
	}
	
	
	
	$('input.miniTextfield').focus(function(){$(this).parent().addClass('on');});
	$('input.miniTextfield').blur(function(){$(this).parent().removeClass('on');});
	
	window.setInterval(function(){
		if(typeof subcateg_mouseover != "undefined"){
			
			if(gridSubCategoriasLength > 7){
				if(subcateg_side == 'left')
					gridSubCategoriasWidthAux += 2;
				else if(subcateg_side == 'right')
					gridSubCategoriasWidthAux -= 2;
				
				if(gridSubCategoriasWidthAux < subCategoriaMaxLeft){
					gridSubCategoriasWidthAux = subCategoriaMaxLeft;
					subcateg_mouseover = false;
				}else if(gridSubCategoriasWidthAux > 0){
					gridSubCategoriasWidthAux = 0;
					subcateg_mouseover = false;
				}else{
					subcateg_mouseover = "undefined";
				}
				
				$('#gridSubCategorias ul').css('left', gridSubCategoriasWidthAux +'px');
				
			}
		}
	},1);
	
	
});

function montaFormulario(){
	
	//
	display = 'toggle';
	
	if(display == 'toggle'){
		display = ($('.contato-content').css('display') == 'block' ? 'none' : 'block');
	}
	
	if(display == 'block'){		
		$('.contato-content').stop(true,true).slideDown('slow');
	}else{
		
			$('.contato-content').children().remove();
			
			var br = document.createElement('br');
			
			var grid = document.createElement('div');
			grid.setAttribute('id','gridContato');
			
			var imagem = document.createElement('div');
			imagem.setAttribute('id','image-endereco');
			
			var image = document.createElement('img');
			image.setAttribute('src','common/img/template/endereco.png');
			image.src = 'common/img/template/endereco.png';
			
			imagem.appendChild(image);
			
			var nome = document.createElement('input');
			nome.setAttribute('type','text');
			nome.setAttribute('name','nome');
			nome.setAttribute('id','contato-nome');
			nome.setAttribute('value', 'NOME/RAZAO SOCIAL');
			
			var email = document.createElement('input');
			email.setAttribute('type','text');
			email.setAttribute('name','email');
			email.setAttribute('id','contato-email');
			email.setAttribute('value', 'E-MAIL');
			
			var endereco = document.createElement('input');
			endereco.setAttribute('type','text');
			endereco.setAttribute('name','endereco');
			endereco.setAttribute('id','contato-endereco');
			endereco.setAttribute('value', 'ENDERECO');
			
			var telefone = document.createElement('input');
			telefone.setAttribute('type','text');
			telefone.setAttribute('name','telefone');
			telefone.setAttribute('id','contato-telefone');
			telefone.setAttribute('value', 'TELEFONE');
			
			var departamento = document.createElement('select');
			departamento.setAttribute('name','departamento');
			departamento.setAttribute('id','contato-departamento');
			departamento.setAttribute('id','contato-departamento');
			
			
			var opt1 = document.createElement('option');
			opt1.setAttribute('value','DEPARTAMENTO');
			opt1.appendChild(document.createTextNode('DEPARTAMENTO'));
			
			var opt2 = document.createElement('option');
			opt2.setAttribute('value','comercial');
			opt2.appendChild(document.createTextNode('COMERCIAL'));
			
			var opt3 = document.createElement('option');
			opt3.setAttribute('value','financeiro');
			opt3.appendChild(document.createTextNode('FINANCEIRO'));
			
			var opt4 = document.createElement('option');
			opt4.setAttribute('value','geral');
			opt4.appendChild(document.createTextNode('GERAL'));
			
			departamento.appendChild(opt1);
			departamento.appendChild(opt2);
			departamento.appendChild(opt3);
			departamento.appendChild(opt4);
			
			
			var mensagem = document.createElement('textarea');
			mensagem.setAttribute('name','mensagem');
			mensagem.setAttribute('id','contato-mensagem');
			mensagem.appendChild(document.createTextNode('MENSAGEM'));
			
			var div = document.createElement('div');
			div.setAttribute('class','buttons');
			
			var href1 = document.createElement('a');
			href1.setAttribute('href','javascript:void(0);');
			href1.setAttribute('onclick','fnValidaContato()');
			href1.setAttribute('class','btn-mandar');
			href1.href = 'javascript:void(0);';
			href1.onclick = function(){fnValidaContato();}
			href1.appendChild(document.createTextNode('MANDAR'));
			div.appendChild(href1);
			
			var href2 = document.createElement('a');
			href2.setAttribute('href','javascript:void(0);');
			href2.setAttribute('onclick','contatoToggle("toggle")');
			href2.setAttribute('class','btn-cancelar');
			href2.href = 'javascript:void(0);';
			href2.onclick = function(){contatoToggle('toggle');}
			href2.appendChild(document.createTextNode('CANCELAR'));
			div.appendChild(href2);
			
			grid.appendChild(nome);
			grid.appendChild(email);
			grid.appendChild(endereco);
			grid.appendChild(telefone);
			grid.appendChild(departamento);
			grid.appendChild(mensagem);
			grid.appendChild(div);
		
			$('.contato-content').stop(true,true).slideUp('slow');
			
			$('.contato-content').append(br);
			$('.contato-content').append(grid);
			$('.contato-content').append(imagem);
			
			
			$('.contato-content').stop(true,true).slideDown('slow');
		
		
		
		
	}
	
}

function cestaToggle(display){
	if(cestaList.length > 0){
		$('a.menu-cesta').addClass('menu-cesta-on');
		$('#itensCount').show().text((cestaList.length > 1 ? cestaList.length + ' itens' : cestaList.length + ' item'));
	}else{
		$('a.menu-cesta').removeClass('menu-cesta-on');
		$('#itensCount').hide().text('');
	}
	
	if(display == 'toggle'){
		display = ($('.cesta-content').css('display') == 'block' ? 'none' : 'block');
	}
	
	if(display == 'block'){
		$('.cesta-content').children().remove();
		
		if(cestaList != undefined && cestaList != null && cestaList.length > 0){
			for(i in cestaList){
				var brinde = cestaList[i];
				
				var table = document.createElement('table');
				table.setAttribute('border',0);
				table.setAttribute('width','100%');
				table.setAttribute('cellpadding','0');
				table.setAttribute('cellspacing','0');
				
				var tr1 = document.createElement('tr');
				var th1 = document.createElement('th');
				th1.setAttribute('width','130');
				th1.setAttribute('text-align','left');
				th1.align = 'left';
				th1.setAttribute('colspan','2');
				th1.innerHTML = 'Produto';
				tr1.appendChild(th1);
				
				var th2 = document.createElement('th');
				th2.setAttribute('width','190');
				th2.setAttribute('text-align','left');
				th2.align = 'left';
				th2.innerHTML = 'Gravação';
				tr1.appendChild(th2);
				
				var th3 = document.createElement('th');
				th3.setAttribute('width','130');
				th3.setAttribute('text-align','left');
				th3.align = 'left';
				th3.innerHTML = 'Quantidade';
				tr1.appendChild(th3);
				
				var th3_new = document.createElement('th');
				th3_new.setAttribute('width','130');
				th3_new.setAttribute('text-align','left');
				th3_new.align = 'left';
				th3_new.innerHTML = 'Cor';
				tr1.appendChild(th3_new);
				
				var th4 = document.createElement('th');
				th4.setAttribute('width','300');
				th4.setAttribute('text-align','left');
				th4.align = 'left';
				th4.innerHTML = 'Descrição';
				tr1.appendChild(th4);
				
				
				var th5 = document.createElement('th');
				th5.innerHTML = '&nbsp;';
				tr1.appendChild(th5);
				
				table.appendChild(tr1);
				
				var tr2 = document.createElement('tr');
				
				var td1 = document.createElement('td');
				td1.setAttribute('valign','middle');
				td1.vAlign = 'middle';
				td1.setAttribute('width','50');
								
				td1.innerHTML = '<img src="admin/upload_pic/produtos/'+ brinde.foto+'" height="68" alt="" />';
				tr2.appendChild(td1);
				
				var td2 = document.createElement('td');
				td2.setAttribute('valign','middle');
				td2.vAlign = 'middle';
				td2.setAttribute('width','80');
				td2.innerHTML = '<span class="prodName">'+ brinde.name +'</span>';
				tr2.appendChild(td2);
				
				var td3 = document.createElement('td');
				td3.innerHTML = brinde.sizeM;
				td3.setAttribute('valign','middle');
				td3.vAlign = 'middle';
				tr2.appendChild(td3);
				
				var td4 = document.createElement('td');
				//td4.innerHTML = '<strong>'+ (parseInt(brinde.sizeP) + parseInt(brinde.sizeM) + parseInt(brinde.sizeG)) +'</strong>';
				td4.innerHTML = '<strong>'+ (parseInt(brinde.sizeP)) +'</strong>';
				td4.setAttribute('valign','middle');
				td4.vAlign = 'middle';
				tr2.appendChild(td4);
				
					var td4 = document.createElement('td');
				//td4.innerHTML = '<strong>'+ (parseInt(brinde.sizeP) + parseInt(brinde.sizeM) + parseInt(brinde.sizeG)) +'</strong>';
				td4.innerHTML = '<strong>'+ (brinde.color) +'</strong>';
				td4.setAttribute('valign','middle');
				td4.vAlign = 'middle';
				tr2.appendChild(td4);
				
				var td5 = document.createElement('td');
				td5.innerHTML = brinde.description;
				td5.setAttribute('valign','middle');
				td5.vAlign = 'middle';
				tr2.appendChild(td5);
				
				var td6 = document.createElement('td');
				td6.setAttribute('align','center');
				td6.setAttribute('valign','middle');
				td6.vAlign = 'middle';
				td6.innerHTML = '<a href="javascript:void(0);" onclick="fnRemoveProduto(\'' + brinde.id + '\','+ i +');" class="btn-apagar">APAGAR</a>';
				tr2.appendChild(td6);
				
				table.appendChild(tr2);
				
				$('.cesta-content').append(table);
				
				var hidden = document.createElement('input');
				hidden.setAttribute('type','hidden');
				hidden.setAttribute('name','brinde' + i);
				hidden.setAttribute('value',brinde.id + "#" + brinde.name + "#" + brinde.categoria.id + "#" + brinde.subcategoria.id + "#" + brinde.sizeP + "#" + brinde.sizeM + "#" + brinde.sizeG + "#" + brinde.color);
				$('.cesta-content').append(hidden);
			}
			var qtd = document.createElement('input');
			qtd.setAttribute('type','hidden');
			qtd.setAttribute('name','qtd');
			qtd.setAttribute('value', cestaList.length);
			$('.cesta-content').append(qtd);
			
			
				var tableform = document.createElement('table');
				tableform.setAttribute('border',0);
				tableform.setAttribute('width','100%');
				tableform.setAttribute('cellpadding','0');
				tableform.setAttribute('cellspacing','0');
				
				var nome = document.createElement('input');
				nome.setAttribute('type','text');
				nome.setAttribute('name','nome');
				nome.setAttribute('value','SEU NOME');
				nome.setAttribute('id','cesta-nome');
				
				var email = document.createElement('input');
				email.setAttribute('type','text');
				email.setAttribute('name','email');
				email.setAttribute('value','SEU E-MAIL');
				email.setAttribute('id','cesta-email');
				
				var mensagem = document.createElement('textarea');
				mensagem.setAttribute('name','mensagem');
				mensagem.setAttribute('id','cesta-mensagem');
				
				var span = document.createElement('span');
				span.setAttribute('class','comentarios');
				span.innerHTML = 'COMENTÁRIOS';
				
				
				
				var tr11 = document.createElement('tr');
				var th11 = document.createElement('td');
				th11.setAttribute('width','200');
				th11.setAttribute('valign','middle');
				th11.align = 'left';
				th11.innerHTML = '&nbsp;';
				
				var th12 = document.createElement('td');
				th12.appendChild(nome);
				tr11.appendChild(th11);
				tr11.appendChild(th12);
				
				
				var tr22 = document.createElement('tr');
				var th22 = document.createElement('td');
				th22.setAttribute('width','200');
				th22.setAttribute('valign','middle');
				th22.align = 'left';
				th22.innerHTML = '&nbsp;';
				
				var th23 = document.createElement('td');
				th23.appendChild(email);
				tr22.appendChild(th22);
				tr22.appendChild(th23);
				
				
				var tr33 = document.createElement('tr');
				var th33 = document.createElement('td');
				th33.setAttribute('width','200');
				th33.setAttribute('valign','middle');
				th33.align = 'left';
				th33.innerHTML = '&nbsp;';
				
				var th34 = document.createElement('td');
				th34.appendChild(span);
				tr33.appendChild(th33);
				tr33.appendChild(th34);
				
				
				var tr44 = document.createElement('tr');
				var th44 = document.createElement('td');
				th44.setAttribute('width','200');
				th44.setAttribute('valign','middle');
				th44.align = 'left';
				th44.innerHTML = '&nbsp;';
				
				var th45 = document.createElement('td');
				th45.appendChild(mensagem);
				tr44.appendChild(th44);
				tr44.appendChild(th45);
				
				
				var tr55 = document.createElement('tr');
				var th55 = document.createElement('td');
				th55.setAttribute('width','200');
				th55.setAttribute('valign','middle');
				th55.align = 'left';
				th55.innerHTML = '&nbsp;';
				
				var th56 = document.createElement('td');
				th56.innerHTML = '<div class="buttons"><a href="javascript:void(0);" onclick="fnMandarCesta();" class="btn-mandar">MANDAR</a><a href="javascript:void(0);" onclick="fnCancelarCesta();" class="btn-limpar">CANCELAR</a></div>';
				tr55.appendChild(th55);
				tr55.appendChild(th56);
				
				
				
				
				tableform.appendChild(tr11);
				tableform.appendChild(tr22);
				tableform.appendChild(tr33);
				tableform.appendChild(tr44);
				tableform.appendChild(tr55);
				
				
			$('.cesta-content').append(tableform);
			
			
			//$('.cesta-content').append('<div class="buttons"><a href="javascript:void(0);" onclick="fnMandarCesta();" class="btn-mandar">MANDAR</a><a href="javascript:void(0);" onclick="fnCancelarCesta();" class="btn-limpar">CANCELAR</a></div>');
			$('.cesta-content').stop(true,true).slideDown('slow');
		}
	}else{
		$('.cesta-content').stop(true,true).slideUp('slow');
	}
}


function fnSelecionaProduto(prod){
	var brindeDestaque = getBrinde($(prod).attr('id').split('#')[1]);
	selected_brinde = brindeDestaque;
	
	if(brindeDestaque.destaque == 'true')
		$('#produto-grid .produto-description').addClass('new');
	else
		$('#produto-grid .produto-description').removeClass('new');
	
	$('#sizeP').val('');
	$('#sizeM').val('');
	$('#sizeG').val('');
	$('.color-content a img').removeClass('on');
	//alert('hexa: '+brindeDestaque.hexadecimal);
	if(brindeDestaque.zoom && brindeDestaque.zoom == "default.jpg"){
		$('#produto-grid .produto-image img:eq(1)').attr('class','lupa_hidden');
		$('#produto-grid .produto-image a:eq(0)').attr('href','javascript:void(0);');
		$('#produto-grid .produto-image a:eq(0)').removeClass('lightbox');
	}else{
		$('#produto-grid .produto-image img:eq(1)').attr('class','lupa');
		$('#produto-grid .produto-image a:eq(0)').attr('href','admin/upload_pic/produtos/'+ brindeDestaque.zoom);
		$('#produto-grid .produto-image a:eq(0)').attr('class','lightbox');
		$('#produto-grid .produto-image a:eq(0)').attr('rel', Math.random(999));
	}
	
	$('#produto-grid .produto-image img:eq(0)').attr('src','admin/upload_pic/produtos/'+ brindeDestaque.foto);
	$('#produto-grid .produto-description .name').html(brindeDestaque.name);
	//$('#produto-grid .produto-description .price span').html('R$ ' +  brindeDestaque.preco + ' / ');
	$('#produto-grid .produto-description .price span').html('<br />');
	$('#produto-grid .produto-description .description').html(brindeDestaque.description);
		
		var str = brindeDestaque.hexadecimal;
        var str2 = brindeDestaque.cor;
        
		$('#titulo-cor').html('');
		
        var array_hexa = Array();
		if(str){
        	array_hexa = str.split(",");
			$('#titulo-cor').html('COR');
		}
        var array_cor = Array();
        if(str2){
			array_cor = str2.split(",");
		}
        $('#cores').html('');
        var ul = document.createElement('ul');
        for(i in array_hexa){
            if(array_hexa[i] && array_hexa[i] != '')
            //alert(array_hexa[i]);
               
            var li = document.createElement('li');
                ul.appendChild(li);
            
            var div = document.createElement('div');
			    div.setAttribute('id','cor_'+i);
                div.setAttribute('class','box_cor');
                div.id = 'cor_'+i;
				div.className = 'box_cor';
                div.style.backgroundColor = array_hexa[i];
                li.appendChild(div);
            
            var href = document.createElement('a');
                href.setAttribute('href','javascript:void(0);');
                href.setAttribute('onclick',"selectColor('"+array_cor[i]+"','"+array_hexa[i]+"','cor_"+i+"')");
                href.setAttribute('id','teste');
                href.href = 'javascript:void(0);';
                //href.onclick = function(){selectColor("'"+array_cor[i]+"','"+array_hexa[i]+"','cor_"+i+"'");}
                href.id = 'teste';
                div.appendChild(href);
            
            var newtext = document.createTextNode(array_cor[i]);
                //li.appendChild(newtext);
		}
       $('#cores').append(ul);
        
        //$('#cores').html(brindeDestaque.hexadecimal);
        
	$('html,body').animate({
		scrollTop: $('#produto-grid').offset().top
	});
}

function selectColor(cor, hexadecimal, div){
		//alert(cor);
		//alert("seleciona cor: "+cor+" - "+hexadecimal+" - "+div);
		//document.getElementById(div)
		//$("'#"+div+"'").addClass("box_ativo");
		
		var obj = document.getElementById(div);
		
		//alert(obj);
		$('#cores').find('ul li div').removeClass('box_ativo');
		$(obj).addClass('box_ativo');
		selected_brinde.color = cor;
	}

/*
var brinde = selected_brinde;
function fnSelecionaCor(obj, cor){
	selected_brinde.color = cor;
	$('.color-content').find('a img').removeClass('on');
	$(obj).find('img').addClass('on');
}
*/


function contatoToggle(display){
	
	
	if(display == 'toggle'){
		display = ($('.contato-content').css('display') == 'block' ? 'none' : 'block');
	}
	
	if(display == 'block'){
		//$('.contato-content').children().remove();
		
		// abre
		$('.contato-content').stop(true,true).slideDown('slow');
			
		
	}else{
		// fecha
		$('.contato-content').stop(true,true).slideUp('slow');
		$('html,body').animate({
			//scrollTop: $('.aempresa-content').offset().top
			scrollTop: 0
		});
	}
}


function fnAdicionaProduto(){
	var brinde = selected_brinde;
	
	brinde.sizeP = ($('#sizeP').val().trim() != '' ? $('#sizeP').val() : 0);
	brinde.sizeM = ($('#sizeM').val().trim() != '' ? $('#sizeM').val() : '');
	brinde.sizeG = ($('#sizeG').val().trim() != '' ? $('#sizeG').val() : 0);
	
	/*var found = false;
	for(i in cestaList){
		if(cestaList[i].categoria.id == brinde.categoria.id && cestaList[i].subcategoria.id == brinde.subcategoria.id && cestaList[i].id == brinde.id){
			found = true;
			break;
		}
	}*/
	

	//if((parseInt(brinde.sizeP) + parseInt(brinde.sizeM) + parseInt(brinde.sizeG)) == 0){
	if((parseInt(brinde.sizeP) ) == 0){
		alert('Informe a quantidade de itens que deseja.');
		$('#sizeP').focus();
		return;
	}
	
	if(brinde.color == null){
		//alert('Informe a cor desejada.');
		//return;
		brinde.color = 'nao escolhida';
	}
	
	//if(found != true){
		cestaList.push(brinde);
		cestaToggle('block');
	//}else{
	//	alert('Este item já está na cesta.');
	//}
	
	$('#sizeP').val('');
	$('#sizeM').val('');
	$('#sizeG').val('');
	$('.color-content a img').removeClass('on');
	$('#cores').find('ul li div').removeClass('box_ativo');
	selected_brinde = getBrinde(brinde.id);
	
	$('html,body').animate({
		scrollTop: $('.cesta-content').offset().top
	});
}

function fnRemoveProduto(brindeId, pos){
	//var brinde = getBrinde(brindeId);
	var cestaAux = new Array();
	for(i in cestaList){
		if(cestaList[i].id == brindeId && i == pos){
			continue;
		}
		cestaAux.push(cestaList[i]);
	}
	cestaList = cestaAux;
	cestaToggle('block');
}

function fnSelecionaCor(obj, cor){
	selected_brinde.color = cor;
	$('.color-content').find('a img').removeClass('on');
	$(obj).find('img').addClass('on');
}

function fnMandarCesta(){
	var nome = document.getElementById('cesta-nome');
	var email = document.getElementById('cesta-email');
	var mensagem = document.getElementById('cesta-mensagem');
	
	if(nome.value == 'SEU NOME' || nome.value == ''){
		alert('Insira seu Nome');	
	}else 
	if(email.value == 'SEU E-MAIL' || email.value == ''){
		alert('Insira seu E-Mail');	
	}else 
	if(mensagem.value == ''){
		alert('Insira uma Mensagem');	
	}else {
		document.formCesta.submit();
		void(0);
	}
	
}

function fnCancelarCesta(){
	$('.cesta-content').stop(true,true).slideUp('slow',function(){
		cestaList = new Array();
		cestaToggle('block');
	});
}
