$(function(){
	
	

	// Lightbox
	$("a[rel='lightbox']").lightBox({
		imageLoading: 'images/lightbox-ico-loading.gif',
		imageBtnClose: 'images/lightbox-btn-close.gif',
		imageBtnPrev: 'images/lightbox-btn-prev.gif',
		imageBtnNext: 'images/lightbox-btn-next.gif',
		txtImage: 'Imagem',
		txtOf: 'de'
	});
	
	
	// Máscaras
	$("input[name='cpf']").mask("999.999.999-99");
	$("input[name='cnpj']").mask("99.999.999/9999-99");
	$("input[name='cep']").mask("99999-999");
	$("input[name='telefone']").mask("(99) 9999-9999");
	$("input[name='data']").mask("99/99/9999");
	
	
	// Desativa clique direito
	//$("img").noContext();
	
	
	
	// Álbum
	$(".album.carousel > ul").jcarousel({
		scroll: 4
    });
	$(".album2.carousel > ul").jcarousel({
		scroll: 3
    });
	
	
	
	// fecha banner popup
	$("#fecharFlutuante").click(function(){
		$(this).closest(".banner_popup").hide();
	});


	
	// Chat
	$(".open_window_chat").click(function(){
		window.open('http://settings.messenger.live.com/Conversation/IMMe.aspx?invitee=f2d6dddb858247ee@apps.messenger.live.com&mkt=pt-BR','chat','width=530,height=400,left=0,top=0,scrollbars=no');
	});
	
	
	
	
	// Cadastro
	$(".cadastro input[name='pessoa']").change(function(){
		if ($(this).val() == 'PF') {
			$(".cadastro input[name='cpf']").closest("tr").show();
			$(".cadastro input[name='cnpj'], .cadastro input[name='empresa']").closest("tr").hide();
		} else {
			$(".cadastro input[name='cpf']").closest("tr").hide();
			$(".cadastro input[name='cnpj'], .cadastro input[name='empresa']").closest("tr").show();
		}
	});
	
	
	
	
	// Modal
	$("a[rel='modal']").fancybox({
		'width'				: '100%',
		'height'			: '100%',
		'autoScale'     	: false,
		'showNavArrows'     : false,
		'type'				: 'iframe'
	});

	
	
	
	// Produto
	$("a[rel='produto']").click(function() {
		$.fancybox({
			'padding'		: 0,
			'href'			: this.href,
			'type'			: 'ajax',
			'onComplete'    : function() {
				$("a[rel='lightbox']").lightBox({
					imageLoading: 'images/lightbox-ico-loading.gif',
					imageBtnClose: 'images/lightbox-btn-close.gif',
					imageBtnPrev: 'images/lightbox-btn-prev.gif',
					imageBtnNext: 'images/lightbox-btn-next.gif',
					txtImage: 'Imagem',
					txtOf: 'de'
				});
				$(".album2.carousel > ul").jcarousel({
					scroll: 3
			    });
			}
		});
	
		return false;
	});

	
	
	
	// Promoção
	$("a[rel='promocao']").click(function() {
		$.fancybox({
			'padding'		: 0,
			'href'			: this.href,
			'type'			: 'ajax',
			'onComplete'    : function() {
			}
		});
	
		return false;
	});
	
	
	
	// Adiciona ao carrinho
	$("form[name='addcarrinho']").live('submit', function(){
		var $action = $(this).attr('action');
		var $qtd = $(this).find("input[name='qtd']").val();

		$.ajax({
			url: $action,
			dataType: 'text',
			type: 'POST',
			cache: false,
			data: {'addcarrinho': 1, 'qtd': $qtd},
			beforeSend: function() {
				$(".produtoview_adicionando").show();
			},
			success: function($text) {
				$(".produtoview_adicionando").hide();
				if ($text == 'ok') {
					window.location.href = 'carrinho';
				} else {
					alert($text);
				}
			}
		});
		return false;
	});

	
	
	
	
	// Youtube
	$("a[rel='youtube']").live('click', function() {
		$.fancybox({
				'padding'		: 0,
				'autoScale'		: false,
				'transitionIn'	: 'none',
				'transitionOut'	: 'none',
				'title'			: this.title,
				'width'	    	: 640,
				'height'		: 390,
				'href'			: this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
				'type'			: 'swf',
				'swf'			: {
					'wmode'		: 'transparent',
					'allowfullscreen'	: 'true'
				}
			});
	
		return false;
	});
	
	
	
	
	// Player
	$("a[rel='player']").live('click', function() {
		$.fancybox({
				'padding'		: 0,
				'autoScale'		: false,
				'transitionIn'	: 'none',
				'transitionOut'	: 'none',
				'title'			: this.title,
				'width'	    	: 640,
				'height'		: 390,
				'href'			: 'http://static.4shared.com/flash/player.swf',
				'type'			: 'swf',
				'swf'			: {
					'wmode'		: 'transparent',
					'allowfullscreen'	: 'true',
					'flashVars' : 'file='+this.href+'&controlbar=over&stretching=uniform'
				}
			});
	
		return false;
	});

	
	



	// Banner topo
	var $bd_current;
	bd(0);	
	setTimeout(bd_pula, 5000);

	
	
});



function bd($k) {
	$("#destaque .btns_bd a:eq("+$k+")").addClass("selected").siblings("a").removeClass("selected");
	$("#destaque .bd:eq("+$k+")").fadeIn('slow').siblings(".bd").hide();
	$bd_current = $k;
}

function bd_pula() {
	var $bd_count = $("#destaque .bd").length;
	if (($bd_current+1) == $bd_count) {
		bd(0);
	} else {
		bd($bd_current+1);
	}
	setTimeout(bd_pula, 5000);
}

function bd_next() {
	var $bd_count = $("#destaque .bd").length;
	if (($bd_current+1) == $bd_count) {
		bd(0);
	} else {
		bd($bd_current+1);
	}
}

function bd_prev() {
	var $bd_count = $("#destaque .bd").length;
	if ($bd_current == 0) {
		bd($bd_count-1);
	} else {
		bd($bd_current-1);
	}
}


