$(document).ready(function() {

	//sliders da calculadora da Home

	var val40 = 0.00;
	var val60 = 0.00;
	var val100 = 0.00;
	var tot40 = 0;
	var tot60 = 0;
	var tot100 = 0;
	var horas = 1460;

	//buttonset da calculadora da Home
	$( "#radio" ).buttonset().change(function() {
		$("#radio label").each(function(){
			if($(this).attr('aria-pressed') == 'true')
				horas = $('#' + $(this).attr('for')).val();
				valmes = 0.00;
				valano = 0.00;
				valvida = 0.00;			
				switch($(this).children('input').attr('id')) {
					case 'lamp40w':
						val40 = ui.value;
						tot40 = ui.value;
						break;
					case 'lamp60w':
						val60 = ui.value;
						tot60 = ui.value;
						break;
					case 'lamp100w':
						val100 = ui.value;
						tot100 = ui.value;
						break;
			}
			compWattage = val100 * 75 + val60 * 45 + val40 * 31;
			valvida = 0.4 * horas / 1000 * compWattage;

			//console.log(valvida);

			

			if(val40 != 0.00) {

				valmes += val40 * 1.51;

				valano = valmes * 12;

				//valvida = valmes * 24.66;

				//tot40  = tot40;

			}

			

			if(val60 != 0.00) {

				valmes += val60 * 2.19;

				valano = valmes * 12;

				//valvida = valmes * 24.66;

				//tot60 = tot60;

			}

			

			if(val100 != 0.00) {

				valmes += val100 * 3.65;

				valano = valmes * 12;

				//valvida = valmes * 24.66;

				//tot100 = tot100;

			}

			



			

				

			//console.log(valmes);

			//console.log(valano);

			//valorMes += ui.value

			$( "#mes" ).html( "R$" + valmes.toFixed(2).replace('.', ','));

			$( "#ano" ).html( "R$" + valano.toFixed(2).replace('.', ','));

			$( "#vida" ).html( "R$" + valvida.toFixed(2).replace('.', ','));

			

			$( "#t40" ).html(tot40);

			$( "#t60" ).html(tot60);

			$( "#t100" ).html(tot100);

			

		});

		

		

	});	

	

	

	$( ".sliders-lampadas li div" ).slider({

		value: 0,

		orientation: "horizontal",

		range: "min",

		min: 0,

		max: 100,

		step: 1,

		animate: true,

		slide: function( event, ui ) {

			//console.log();

		

			valmes = 0.00;

			valano = 0.00;

			valvida = 0.00;			

			

			switch($(this).children('input').attr('id')) {

				case 'lamp40w':

						val40 = ui.value;

						tot40 = ui.value;

						break;

				case 'lamp60w':

						val60 = ui.value;

						tot60 = ui.value;

						break;

				case 'lamp100w':

						val100 = ui.value;

						tot100 = ui.value;

						break;

			}

			

			compWattage = val100 * 75 + val60 * 45 + val40 * 31;

			valvida = 0.4 * horas / 1000 * compWattage;

			

			if(val40 != 0.00) {

				valmes += val40 * 1.51;

				valano = valmes * 12;

				//valvida = valmes * 24.66;

				//tot40  = tot40;

			}

			

			if(val60 != 0.00) {

				valmes += val60 * 2.19;

				valano = valmes * 12;

				//valvida = valmes * 24.66;

				//tot60 = tot60;

			}

			

			if(val100 != 0.00) {

				valmes += val100 * 3.65;

				valano = valmes * 12;

				//valvida = valmes * 24.66;

				//tot100 = tot100;

			}

			

				

			//console.log(valmes);

			//console.log(valano);

			//valorMes += ui.value

			$( "#mes" ).html( "R$" + valmes.toFixed(2).replace('.', ','));

			$( "#ano" ).html( "R$" + valano.toFixed(2).replace('.', ','));

			$( "#vida" ).html( "R$" + valvida.toFixed(2).replace('.', ','));

			

			$( "#t40" ).html(tot40);

			$( "#t60" ).html(tot60);

			$( "#t100" ).html(tot100);

			

			//console.log(event);

		}



	});


	//slider simulador engine

	$(".carrousel_representantes li:first-child").addClass('selected');

	$(".carrousel_representantes li div").live("click",function(){

		$(".carrousel_representantes li").removeClass('selected');

		$(this).parent('li').addClass('selected');
		var id_estado = $(this).attr("id_estado");
		var estado = $(this).attr("class");
		$("#wrapper-mapa").attr("class",estado);

		$.ajax({

			url: '/pt/representantes/getrepresentantes/id_estado/'+id_estado,

			success: function(result){

				$("#set_representantes").html(result);

			},

			dataType: 'html'

		});	

	});
	
	$("#wrapper-mapa area").click(function(){
		var estado = $(this).attr("title");
		$("#wrapper-mapa").attr("class",estado);
		$("ul#mycarousel li").removeClass("selected");
		var id_estado = $(this).attr("id_estado");
		$("#mycarousel li div."+estado).parents("li").addClass("selected")

		$.ajax({

			url: '/pt/representantes/getrepresentantes/id_estado/'+id_estado,

			success: function(result){

				$("#set_representantes").html(result);

			},

			dataType: 'html'

		});
	});


	$(".contato li div").live("click",function(){

		var departamento = $(this).html();

		$("#setdepartamento").val(departamento);

		return false;		

	});
	//drop-down do menu

	$('.drop:not(selecionado)').hover(function(){

		$('.down').toggleClass('active');

	});

	$('.down').mouseenter(function(){

		$(this).addClass('active');

		$('.drop:not(selecionado)').addClass('habilitado');

	});

	$('.down').mouseleave(function(){

		$(this).removeClass('active');

		$('.drop:not(selecionado)').removeClass('habilitado');

	});

	

	//accordion da p�gina Produtos

	$( ".accordion" ).accordion({

		autoHeight: false,

		navigation: true,
		
		collapsible: true

	});

	

	//Setas rolantes da p�gina Produtos //var y_fixo = $(".arrow").offset().top;

	$(window).scroll(function () {

		if($(document).scrollTop() > 32 && $(document).scrollTop() < 1100){

			$(".arrow").animate({

				top: 75+$(document).scrollTop()+"px"

				},{duration:500,queue:false}

			);

		}

	});

	

	///slider engine da pagina representantes

	$(".representantes .paineis li:first-child").addClass('active');

	$(".representantes #mycarousel li").each(function(){

		$(this).data("index", index);

		index++;

	}).click(function () {

		$(".representantes #mycarousel li").removeClass('selected');

		$(this).addClass('selected');

		var i = $(this).data("index");

		$(".representantes .paineis li").removeClass('active');

		$(".representantes .paineis li:eq(" + i.toString() + ")").addClass('active');

	});

	

	//slider engine do simulador da PRODUTOS

	$(".mycarousel li:first-child").addClass('selected');

	$(".produtos .produtos_lista li").hide();

	$(".produtos .produtos_lista li").css('height', '1px');

	

	var click = false;

	var index = 0;

	$('.produtos .mycarousel li').each(function(){
		$(this).data("index", index);
		index++;
		}).hover(function () {
			if(click === true)
				return false;
			$(".produtos .activePage .paineis li").hide();
			
			$(".produtos .activePage .mycarousel li, .produtos .produtos_carrocel li").removeClass('selected');
			$(this).addClass('selected');
			var i = $(this).data("index");
			$(".produtos .activePage .paineis li:not(:eq(" + i.toString() + "))").hide();
			$(".produtos .paineis li:eq(" + i.toString() + ")").show();
			$(".produtos .activePage .produtos_lista li:not(:eq(" + i.toString() + "))").hide();
			$(".produtos .produtos_lista li:eq(" + i.toString() + ")").show();
			if (i == 2){
				if ($("ul.anythingBase li.panel:nth-of-type(2)").hasClass("activePage") == true){
					$("div.anythingSlider").height(1560);
				}
				else if ($("ul.anythingBase li.panel:nth-of-type(3)").hasClass("activePage") == true){
					$("div.anythingSlider").height(1190);
				}
				else if ($("ul.anythingBase li.panel:nth-of-type(4)").hasClass("activePage") == true){
					$("div.anythingSlider").height(1310);
				}
				else if ($("ul.anythingBase li.panel:nth-of-type(5)").hasClass("activePage") == true){
					$("div.anythingSlider").height(1220);
				}
				else if ($("ul.anythingBase li.panel:nth-of-type(6)").hasClass("activePage") == true){
					$("div.anythingSlider").height(1200);
				}
				else if ($("ul.anythingBase li.panel:nth-of-type(7)").hasClass("activePage") == true){
					$("div.anythingSlider").height(1210);
				}
				else if ($("ul.anythingBase li.panel:nth-of-type(8)").hasClass("activePage") == true){
					$("div.anythingSlider").height(1210);
				}
				else if ($("ul.anythingBase li.panel:nth-of-type(9)").hasClass("activePage") == true){
					$("div.anythingSlider").height(1240);
				}
				else if ($("ul.anythingBase li.panel:nth-of-type(10)").hasClass("activePage") == true){
					$("div.anythingSlider").height(1270);
				}
				else if ($("ul.anythingBase li.panel:nth-of-type(11)").hasClass("activePage") == true){
					$("div.anythingSlider").height(1365);
				}
				else if ($("ul.anythingBase li.panel:nth-of-type(12)").hasClass("activePage") == true){
					$("div.anythingSlider").height(1250);
				}
			}
		});

	$('.produtos .mycarousel li').bind('click', function(){
		click = true;		
		$('html, body').animate({
			scrollTop: $(".produtos_lista").offset().top
		}, {duration: 1000, complete: function() {
				click = false;
			}
		});
	});
	
	
	$(".voltar_topo").bind('click',function(){

		$('html, body').animate({

			   scrollTop: $("#pag2").offset().top

			}, {duration: 1000, complete: function() {

				return false;

				}

			});

	});

	$(".home .paineis li:first-child, .produtos .paineis li:first-child, .produtos .produtos_lista li:first-child, .produtos .produtos_carrocel li:first-child").show();

	var index = 0;

	$(".home .mycarousel li,  .contato .mycarousel li").each(function(){		

	$(this).data("index", index);

	index++;

	}).click(function () {
		$(".produtos .activePage .paineis li").hide();
		$(".home .mycarousel li, .produtos .activePage .mycarousel li, .contato .mycarousel li, .produtos .produtos_carrocel li").removeClass('selected');
		$(this).addClass('selected');
		var i = $(this).data("index");
		$(".home .paineis li:not(:eq(" + i.toString() + ")), .produtos .activePage .paineis li:not(:eq(" + i.toString() + "))").fadeOut();
		$(".home .paineis li:eq(" + i.toString() + "), .produtos .paineis li:eq(" + i.toString() + ")").fadeIn();
		$(".produtos .activePage .produtos_lista li:not(:eq(" + i.toString() + "))").fadeOut();
		$(".produtos .produtos_lista li:eq(" + i.toString() + ")").fadeIn();
		$(".produtos .activePage .produtos_carrocel li:not(:eq(" + i.toString() + "))").fadeOut();
		$(".produtos .produtos_carrocel li:eq(" + i.toString() + ")").fadeIn();
		//console.log(i);

		});//

 //slider engine do simulador da home

	$("#mycarousel li:first-child").addClass('selected');

	$(".home .paineis li.slide:first-child, .produtos .paineis li:first-child").show();

	var index = 0;

	$(".home #mycarousel li, .produtos #mycarousel li, .contato #mycarousel li").each(function(){

	$(this).data("index", index);

	index++;

	}).click(function () {

		$(".home #mycarousel li, .produtos #mycarousel li, .contato #mycarousel li").removeClass('selected');

		$(this).addClass('selected');

		var i = $(this).data("index");

		$(".produtos .paineis li").hide();

		$(".home .paineis li.slide:not(:eq(" + i.toString() + ")), .produtos .paineis li:not(:eq(" + i.toString() + "))").fadeOut();

		$(".home .paineis li.slide:eq(" + i.toString() + "), .produtos .paineis li:eq(" + i.toString() + ")").fadeIn();

	});

	setTimeout("carroselInfo()", 500);

	setTimeout("loading_produtos()", 1000);
	
	
});

function loading_produtos(){

	$("#loading_produtos").remove();

}

	function carroselInfo(){

		var count = $(".carroselInfo").length;

		$(".carroselInfoUl").css('width', (count*150)+'px');

	}


