jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        // CAUTION: Needed to parenthesize options.path and options.domain
        // in the following expressions, otherwise they evaluate to undefined
        // in the packed version for some reason...
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};

$(document).ready(function(){
	
		var tipo = $('#tipo').find('option[selected]').text();
		var cor = $('#cor').find('option[selected]').text();
		var ci = $('#densidade').find('option[selected]').text();
		var prod = $('#produto').find('option[selected]').text();
			   
	var carregando = "<option value=''>Carregando...</option>";
	
	/*$("#cor, #densidade, #produto").hide();*/
	
	/**********TIPO*************/
	$("#cor, #densidade, #produto").attr("disabled","disabled");
	
	$('#tipo').change(function(){
		
		if($(this).val() == 4){
			var url ="http://www.triplicecor.com.br/pigmento-efeito-perolizado.html";
			pageTracker._trackPageview('tipo/'+tipo);
			window.location= url;
		}
		
		if($(this).val() == 5){
			var url ="http://www.triplicecor.com.br/pigmentos-fluorescentes.html";
			pageTracker._trackPageview('tipo/'+tipo);
			window.location= url;
		}
		
		
		$('#cor').removeAttr("disabled");
		$('#cor').html(carregando);					   
		$('#densidade, #produto').attr("disabled","disabled");

		$.post('selectAjax.php',{id : $('#tipo').val(),	acao : 1},function(response){
			$('#cor').empty();
			$('#cor').append("<option value=''>Selecione</option>"+response);
			pageTracker._trackPageview('tipo/'+tipo);
		});
	});
	
	/***************COR**************/
	$('#cor').change(function(){
		$('#densidade').removeAttr("disabled");
		$('#densidade').html(carregando);					  
		$('#produto').attr("disabled","disabled");
		$.post('selectAjax.php',{
			id : $('#cor').val(),
			acao : 2
		},function(response){
			$('#densidade').empty();
			$('#densidade').append("<option value=''>Selecione</option>"+response);
			pageTracker._trackPageview('cor/'+cor);
		});
	});
	$('#densidade').change(function(){
		$('#produto').removeAttr("disabled");
		$('#produto').html(carregando);
		$.post('selectAjax.php',{
			id : $('#densidade').val(),
			acao : 3
		},function(response){
			$('#produto').empty();
			$('#produto').append("<option value=''>Selecione</option>"+response);
			pageTracker._trackPageview('CI/'+ci);
		});
	});
	
	
	
	$('#produto').change(function(){
		pageTracker._trackPageview('produto/'+produto);
		$.cookie('filtro_produto',produto, { expires: 2 });
		if ( $.cookie('filtro_cor') != null){
				$('#densidade').removeAttr("disabled");
				$('#densidade').empty().append($.cookie('filtro_ci'));
				$.cookie('filtro_produto',produto, { expires: 2 });
			}
		var url =$(this).val();
		window.location=url;
	})
	
	$('.relacionados').append('[+]Linhas Relacionadas');
	$('#descri li ul').hide();
	$('.relacionados').toggle(
		function(){
		$(this).next().slideDown('slow'); 
		$(this).empty().append('[-]Linhas Relacionadas');
		$(this).next().css('display','block')
		}, 
		
		function(){
		$(this).next().slideUp('slow'); 
		$(this).empty().append('[+]Linhas Relacionadas');
		}
	)
	
	/**************hover banners***********/
	
	$('.cosmetic').hover(function(){$(this).attr({src:"img/Banner_03_resth-Cosmetic_2.gif"})},function(){$(this).attr({src:"img/Banner_03_resth-Cosmetic.gif"}) })
	
	$('.print').hover(function(){$(this).attr({src:'img/Banner_04_Resth-Print_2.gif'})}, function(){$(this).attr({src:'img/Banner_04_Resth-Print.gif'})} )
	
	$('.plast').hover(function(){$(this).attr({src:'img/Banner_02_Resth-Plast_2.gif'})}, function(){$(this).attr({src:'img/Banner_02_Resth-Plast.gif'})} )
	
	$('.tint-e').hover(function(){$(this).attr({src:'img/Banner_06_resth-Tint-E_2.gif'})}, function(){$(this).attr({src:'img/Banner_06_resth-Tint-E.gif'})} )
	
	$('.ecodisper').hover(function(){$(this).attr({src:'img/Banner_01_Ecodisper_2.gif'})}, function(){$(this).attr({src:'img/Banner_01_Ecodisper.gif'})} )
	
	$('.fluor').hover(function(){$(this).attr({src:'img/Banner_05_resth-Fluor_2.gif'})}, function(){$(this).attr({src:'img/Banner_05_resth-Fluor.gif'})} )
	
	$('.oxido').hover(function(){$(this).attr({src:'img/Banner_oxido_02.gif'})}, function(){$(this).attr({src:'img/Banner_oxido_01.gif'})} )
	
	$('.paint').hover(function(){$(this).attr({src:'img/banner_paint_02.gif'})}, function(){$(this).attr({src:'img/banner_paint_01.gif'})} )
	
	$('.ultramar').hover(function(){$(this).attr({src:'img/Banner_ultramar_02.gif'})}, function(){$(this).attr({src:'img/Banner_ultramar_01.gif'})} )
	
	$('.resthdisper').hover(function(){$(this).attr({src:'img/Banner_disper_02.gif'})}, function(){$(this).attr({src:'img/Banner_disper_01.gif'})} )
	
	$('.flex').hover(function(){$(this).attr({src:'img/Banner_flex_02.gif'})}, function(){$(this).attr({src:'img/Banner_flex_01.gif'})} )
	
	$('.pearl').hover(function(){$(this).attr({src:'img/Banner_pearl_02.gif'})}, function(){$(this).attr({src:'img/Banner_pearl_01.gif'})} )
	
	/***************HOVER CONTATO***************/
	
	$('#fale').hover(function(){$(this).attr({src:"img/botao_fale_conosco2.gif"})},function(){$(this).attr({src:"img/botao_fale_conosco.gif"}) })
	
	$('#orcamento').hover(function(){$(this).attr({src:'img/orcamento_01.jpg'})}, function(){$(this).attr({src:'img/orcamento_02.jpg'})} )
	
	$('#duvidas').hover(function(){$(this).attr({src:'img/tirar_duvidas_01.jpg'})}, function(){$(this).attr({src:'img/tirar_duvidas_00.jpg'})} )
	
	$('.amostra').hover(function(){$(this).attr({src:'img/bt_amostra_01.gif'})}, function(){$(this).attr({src:'img/bt_amostra_00.gif'})} )
	
	$('#outros-prod').hover(function(){$(this).attr({src:'img/bt_buscar_outro_01.gif'})}, function(){$(this).attr({src:'img/bt_buscar_outro.gif'})} )
	
	/***************HOVER Banners2***************/
	
	$('.blog').hover(function(){$(this).attr({src:"img/banner_blog_02.gif"})},function(){$(this).attr({src:"img/banner_blog_01.gif"}) })
	
	$('.tv').hover(function(){$(this).attr({src:'img/banner_tv_02.gif'})}, function(){$(this).attr({src:'img/banner_tv_01.gif'})} )
	
	$('.faq').hover(function(){$(this).attr({src:'img/banner_faq_02.gif'})}, function(){$(this).attr({src:'img/banner_faq_01.gif'})} )
	
	$('.lab').hover(function(){$(this).attr({src:'img/Banner_laboratorio_02.gif'})}, function(){$(this).attr({src:'img/Banner_laboratorio_01.gif'})} )
	
	$('.tweet').hover(function(){$(this).attr({src:'img/Banner_Twitter_02.gif'})}, function(){$(this).attr({src:'img/Banner_Twitter_01.gif'})} )
	
	$('.responsabilidade').hover(function(){$(this).attr({src:'img/Banner_REsponsabilidade_02.gif'})}, function(){$(this).attr({src:'img/Banner_REsponsabilidade_01.gif'})} )
	
	$('#bt-tabela img').hover(function(){$(this).attr({src:'img/bt_tabela-de-cores-2.gif'})}, function(){$(this).attr({src:'img/bt_tabela-de-cores.gif'})} )
	
	/*******************hover mercado******************************/
	
	/*$('li.box-plastico a').hover(function(){$('li.box-plastico a span.bg-txt-mercado').css({background:'url(img/back_box_orange.gif) no-repeat'})}, function(){$('li.box-plastico a span.bg-txt-mercado').css({background:'url("img/bg-txt-mercado.gif") no-repeat'})} )
	
	$('li.box-tintas-vernizes a').hover(function(){$('li.box-tintas-vernizes a span.bg-txt-mercado').css({background:'url(img/back_box_yellow.gif) no-repeat'})}, function(){$('li.box-tintas-vernizes a span.bg-txt-mercado').css({background:'url("img/bg-txt-mercado.gif") no-repeat'})} )
	
	$('li.box-tintas-graficas a').hover(function(){$('li.box-tintas-graficas a span.bg-txt-mercado').css({background:'url(img/back_box_red.gif) no-repeat'})}, function(){$('li.box-tintas-graficas a span.bg-txt-mercado').css({background:'url("img/bg-txt-mercado.gif") no-repeat'})} )
	
	$('li.box-mercado-especiais a').hover(function(){$('li.box-mercado-especiais a span.bg-txt-mercado').css({background:'url(img/back_box_green.gif) no-repeat'})}, function(){$('li.box-mercado-especiais a span.bg-txt-mercado').css({background:'url("img/bg-txt-mercado.gif") no-repeat'})} )*/
	
	/******************BREADCRUMB***************/
	
	var produto = $('h1.titulo-produtos span').text();
	var mercado = $('#contenth1 h1:eq(0)').text();
	var institucional = $("#menuInst li.ativo").text();
	
	$('#breadcrumb.produtos ul li:last').empty().text(produto);
	$('#breadcrumb.mercado ul li:last').text(mercado);
	$('#breadcrumb.institucional ul li:last').text(institucional);
	
	/********************PRODUTOS*********************/
	
		
		
		
	

});