// JavaScript Document
/**********************************************************************/
/* Efeito fadeout, fadein											     										*/
/**********************************************************************/
$(document).ready(function(){
	$('#masc').fadeOut(1000);
	
	$("a[rel='change_link']").click(function(){		
		$('#masc').fadeIn(1000);
		return true;
	});
	
	$('.efeito_fade').append('<span class="hover"></span>').each(function () {
		var $span = $('> span.hover', this).css('opacity', 0);
		$(this).hover(function () {
			$(this).find(".hover").stop().fadeTo(500, 1);
		}, function () {
			$(this).find(".hover").stop().fadeTo(500, 0);
		});
	});
});
/**********************************************************************/
/* Fim da Função                                                      */
/**********************************************************************/
/**********************************************************************/
/* Função para manipular AJAX									     										*/
/**********************************************************************/
function openAjax() {
	var ajax;
	try {
		ajax = new XMLHttpRequest();
	} catch(ee) {
		try {
			ajax = new ActiveXObject("Msxml2.XMLHTTP");
		} catch(e) {
			try {
				ajax = new ActiveXObject("Microsoft.XMLHTTP");
			} catch(E) {
				ajax = false;
			}
		}
	}
	return ajax;
}
/**********************************************************************/
/* Fim da Função                                                      */
/**********************************************************************/
/**********************************************************************/
/* Função para adicionar ou remover produto do carrinho								*/
/**********************************************************************/
function editCart(id,action) {
	/* Inicia o Objeto Ajax */
	var obj_ajax = openAjax();

	/* Verifica se o navegador da suporte a Ajax */
	if (obj_ajax == null) {
		alert("Ops! Seu navegador não dá suporte a este tipo de ação.");
		return false;
	}
	
	/* Cria um identificador para o link, para evitar cache */
	var datahora = new Date();
	var dia 	 = datahora.getDay();
	var mes 	 = datahora.getMonth();
	var ano 	 = datahora.getYear();
	var hora 	 = datahora.getHours();
	var minuto 	 = datahora.getMinutes();
	var segundos = datahora.getSeconds();
	var id_link  = ano+mes+dia+hora+minuto+segundos;
	if (document.getElementById("start_cart"))
		document.getElementById("start_cart").className = "hide";
	document.getElementById("cart").className = "show_cart";
	
	if (id == "") {
		alert("Please try again later");
		return false;
	}	
	if ((action != "add_cart") && (action != "remove_cart"))
		action = "remove_cart";
	var params = "id_link="+id_link;	
	params += "&id="+id;	
	
	obj_ajax.open("GET", action+".php?"+params, true);
	obj_ajax.onreadystatechange = function() {
		if (obj_ajax.readystate == 1) {
			document.getElementById("cart_itens").innerHTML = '<span style="color=#993366">Atualizando...</span>';
		}else if (obj_ajax.readyState == 4) {
			document.getElementById('cart_itens').innerHTML = obj_ajax.responseText;
		}
	}
	obj_ajax.send(null);
	return false;
}
/**********************************************************************/
/* Fim da Função                                                      */
/**********************************************************************/
/**********************************************************************/
/* Função para mostrar ou ocultar o carrinho													*/
/**********************************************************************/
function showCart(){
	if (document.getElementById("cart").className == "show_cart"){
		document.getElementById("cart").className = "hide" ;
	}else{
		document.getElementById("cart").className = "show_cart";
	}
	return false;
}
/**********************************************************************/
/* Fim da Função                                                      */
/**********************************************************************/
/**********************************************************************/
/* Função para mostrar imagens da página how to apply 								*/
/**********************************************************************/
function showHowToApply(img){
	
	/* Inicia o Objeto Ajax */
	var obj_ajax = openAjax();

	/* Verifica se o navegador da suporte a Ajax */
	if (obj_ajax == null) {
		alert("Ops! Seu navegador não dá suporte a este tipo de ação.");
		return false;
	}
	
	/* Cria um identificador para o link, para evitar cache */
	var datahora = new Date();
	var dia 	 = datahora.getDay();
	var mes 	 = datahora.getMonth();
	var ano 	 = datahora.getYear();
	var hora 	 = datahora.getHours();
	var minuto 	 = datahora.getMinutes();
	var segundos = datahora.getSeconds();
	var id_link  = ano+mes+dia+hora+minuto+segundos;	
	
	var params = "id_link="+id_link;	
	params += "&img="+img;
	
	obj_ajax.open("GET", "request_how_to_apply.php?"+params, true);
	obj_ajax.onreadystatechange = function() {
		if (obj_ajax.readyState == 4) {							
				document.getElementById('carousel').innerHTML = obj_ajax.responseText;
		}
	}
	obj_ajax.send(null);
	return false;
	
}
/**********************************************************************/
/* Fim da Função                                                      */
/**********************************************************************/
/**********************************************************************/
/* Função para limpar campos do formulário		     										*/
/**********************************************************************/
function clearForm(form){	

	for(i=0;i<form.elements.length;i++){
		if (form.elements[i].name != "form")
			form.elements[i].value = "";
	}
	return false;

}
/**********************************************************************/
/* Fim da Função                                                      */
/**********************************************************************/
/**********************************************************************/
/* Função para mostrar as categorias na página categories			*/
/**********************************************************************/
function displayCategory(n){
	var id_category = 'category_'+n;
	$("#categories").find(".category_img").each(function(){	
		if ($(this).attr("id") != id_category) {		
			$(this).stop().fadeTo(500, 0.2);																											
		}	
	});	

}
/**********************************************************************/
/* Fim da Função                                                      */
/**********************************************************************/

/**********************************************************************/
/* Função para mostrar os nomes dos produtos na página products				*/
/**********************************************************************/
function displayName(n){
	/*for(i = 1;i <= 7;i++) {

		if(i == n)
			document.getElementById('prod'+i).className = 'product'+i+'_name';

		else
			document.getElementById('prod'+i).className = 'hide_product'+i+'_name';
	}	*/
	var id_product_name = "prod"+n;
	var id_product = "product_"+n;
	var description = $("#products").find("#intro_description");
	description.hide();
	$("#products").find(".hide_product_name").each(function(){
		if ($(this).attr("id") == id_product_name) {		
			$(this).show();
		}
	});
	$("#products").find(".product_img").each(function(){		
		if ($(this).attr("id") != id_product) {		
			$(this).stop().fadeTo(500, 0.2);																											
		}	
	});
	if (n < 5)
		$('.description').css('top',107+'px');
	displayProduct(n);

}
/**********************************************************************/
/* Fim da Função                                                      */
/**********************************************************************/
/**********************************************************************/
/* Função para esconder as categorias na página categories						*/
/**********************************************************************/
function hideCategories(){

	$("#categories").find(".category_img").each(function(){	
		$(this).stop().fadeTo(500, 1);
	});

}
/**********************************************************************/
/* Função para ocultar os nomes dos produtos na página products				*/
/**********************************************************************/
function hideName(n){

	$("#products").find(".hide_product_name").each(function(){	
		$(this).hide();																								
	});
	$("#products").find(".product_img").each(function(){	
		$(this).stop().fadeTo(500, 1);
	});		
}
/**********************************************************************/
/* Fim da Função                                                      */
/**********************************************************************/
/**********************************************************************/
/* Função para mostrar a imagem grande dos produtos na página products*/
/**********************************************************************/
function displayProduct(product){
	$('#product_bg').show();
	/*var id_img = "product"+product;	
	var scrollbar = "scrollbar"+product;
	var overview = "overview"+product;
	var product_title = "product_title"+product;
	var product_text = "product_text"+product;
	$("#products").find(".product_large").each(function(){
		if ($(this).attr("id") == id_img) {		
			$(this).show();
		}else{
			$(this).hide();
		}
	});
	$("#products").find(".scroll_product").each(function(){
		if ($(this).attr("id") == scrollbar) {		
			$(this).show();
		}else{
			$(this).hide();
		}
	});
	$("#products").find(".overview").each(function(){
		if ($(this).attr("id") == overview) {		
			$(this).show();
		}else{
			$(this).hide();
		}
	});
	$("#products").find(".title").each(function(){
		if ($(this).attr("id") == product_title) {		
			$(this).show();
		}else{
			$(this).hide();
		}
	});
	$("#products").find(".text").each(function(){
		if ($(this).attr("id") == product_text) {		
			$(this).show();
		}else{
			$(this).hide();
		}
	});*/
	var link_back = $("#products").find("#back");
	for(i=1;i<=11;i++){			
		if(document.getElementById('product'+i)){
			if(i==product){				
				if(product >= 7){
					document.getElementById('product'+i).className = 'product_large_7';					
					if (product == i)
						$('#product'+i).show();
					else
						$('#product'+i).hide();
					document.getElementById('product_title'+i).className = 'title';
					if (product == i)
						$('#product_title'+i).show();
					else
						$('#product_title'+i).hide();
					document.getElementById('scrollbar'+i).className = 'show';
					if (product == i)
						$('#scrollbar'+i).show();
					else
						$('#scrollbar'+i).hide();					
					$("#scrollbar1 .viewport").css('height',220+'px');
					$(".description").css('height',220+'px');
					if (product > 7){
						$(".description").css('top',218+'px');	
						$(".product_bg").css('top',191+'px');	
						link_back.css('top',460+'px');
						link_back.css('left',810+'px');
					}else{
						link_back.css('top',345+'px');
						link_back.css('left',820+'px');
					}
				}else{	
					document.getElementById('product'+i).className = 'product_large';					
					if (product == i)
						$('#product'+i).show();
					else
						$('#product'+i).hide();
		
					document.getElementById('product_title'+i).className = 'title';
					if (product == i)
						$('#product_title'+i).show();
					else
						$('#product_title'+i).hide();
					document.getElementById('scrollbar'+i).className = 'show';					
					if (product == i)
						$('#scrollbar'+i).show();
					else
						$('#scrollbar'+i).hide();
					$("#scrollbar1 .viewport").css('height',268+'px');					
					link_back.css('top',450+'px');
					link_back.css('left',815+'px');
					
					$(".description").css('height',325+'px');
				}
				$('#scrollbar'+product).tinyscrollbar();
				$(".back").css('top',440+'px');
				var intro_shadow = $('#products').find('#intro_shadow');
				var description_shadow = $('#products').find('#description_shadow');
				intro_shadow.hide();
				description_shadow.show();
				if ((product == 5) || (product == 6)){
					description_shadow.css('top',325+'px');
				} else if (product == 7){
					description_shadow.css('top',220+'px');
				}
			}else{
	
				document.getElementById('product'+i).className = 'hide';
				$('#product'+i).hide();
				document.getElementById('product_title'+i).className = 'hide';
				$('#product_title'+i).hide();
				document.getElementById('scrollbar'+i).className = 'hide';
				$('#scrollbar'+i).hide();
			}
		}
	}
	return false;

}

/**********************************************************************/
/* Fim da Função                                                      */
/**********************************************************************/
function CategoryFaq(){ /* Função hideandshow / Function hideandshow  */ 
 
 if(document.getElementById('scrollbar1').style.display == 'block'){ 
	 $("#scrollbar2").show(0700);	
	 $('#scrollbar2').tinyscrollbar();
	 document.getElementById('scrollbar2').style.display == 'block'
	 document.getElementById('scrollbar1').style.display = 'none';
	 $('#keratin').removeClass('cinza_escuro');
	 $('#keratin').addClass('cinza');
	 $('#seriseal').removeClass('cinza');
	 $('#seriseal').addClass('cinza_escuro');
 }else{ 
	 $("#scrollbar1").show(0700);
	 document.getElementById('scrollbar1').style.display = 'block';
	 document.getElementById('scrollbar2').style.display = 'none';
	 $('#keratin').removeClass('cinza');
	 $('#keratin').addClass('cinza_escuro');
	 $('#seriseal').removeClass('cinza_escuro');
	 $('#seriseal').addClass('cinza');
 } 
  return false;
} 
function AboutTroca(content){ /* Função hideandshow / Function hideandshow  */ 
 
 if(content == "2"){ 
	 $("#about_seriseal").show(0700);	
	 document.getElementById('about_seriseal').style.display == 'block'
	 document.getElementById('about_keratin').style.display = 'none';

 }else{ 
	 $("#about_keratin").show(0700);
	 document.getElementById('about_keratin').style.display = 'block';
	 document.getElementById('about_seriseal').style.display = 'none';
 } 
  return false;
} 

function clearInput(campo, acao, valor) {
	if (acao == 'in') {
		if (campo.value == valor) {
			campo.value = '';
		}
	} else {
		if (campo.value == '') {
			campo.value = valor;
		}
	}
	return false;
}

/**********************************************************************/
/* Fim da Função                                                      */
/**********************************************************************/
