
(function ($) {
	$.category = {
		showAllCategories: function (e) {
			$('.todascategorias')
				.slideDown('fast');
			$(document).click($.category.hideAllCategories);
			e.stopPropagation();
			e.preventDefault();
		},
		hideAllCategories: function (e) {
			$('.todascategorias')
				.slideUp('fast');
			$(document).unbind('click', $.category.hideAllCategories);
			e.stopPropagation();
		},
		changeView: function (type, elemento){
			//document.forms['frmFiltro'].elements.list_type.value = type;
			var linhadivisao = '<div class="linhadivisao"><img src="/img/pixel.gif" alt="" /></div>';
			var seletor = "#conteudo .produtos";
			$(".visualizacoes a").removeClass('on').addClass('off');
			$(elemento).removeClass('off').addClass('on');
			if(!$(seletor+" #listagem").hasClass("listagem-"+type)){
				$(seletor+" #listagem")
				.slideUp('fast')
				.queue(function (){
					$(this).removeClass();
					$(seletor+" .produto:gt(0)").removeClass('primeiro');
					$(this).addClass('listagem-'+type);
					$(seletor+" .linhadivisao").each(function(){
						$(this).remove();
					});
					switch (type) {
						case "detalhes": {
							$(seletor + " .produto img").each(function () {
								this.src = $(this).attr('imgthumbsmall');
							});
							$(seletor + " .produto").after(linhadivisao);
						} break;
						case "ladoalado": {
							$(seletor + " .produto:nth-child(3n+1)").addClass('primeiro');
							$(seletor + " .produto:nth-child(3n)").after(linhadivisao);
							$(seletor + " .produto img").each(function () {
								this.src = $(this).attr('imgthumbsmall');
							});
							$(seletor + " .produto:last").after(linhadivisao);
						} break;
						case "icones": {
							$(seletor + " .produto:nth-child(4n+1)").addClass('primeiro');
							$(seletor + " .produto:nth-child(4n)").after(linhadivisao);
							if (($(seletor + " .produto").length % 4) != 0) {
								$(seletor + " .produto:last").after(linhadivisao);
							}
							$(seletor + " .produto img").each(function () {
								this.src = $(this).attr('imgicon');
							});
						} break;
						default: {
						} break;
					}
					$(this)
						.dequeue()
						.slideDown("fast");
				});
			}
		},
		ordernar: function(ctg) {
			$('#listaProdutos').load('/index', {
				list_mode: $('#listagem').attr('class').split('-')[1],
				page: 'misc/dynamic',
				content:'listProduct',
				with_price: 1,
				with_extra: 2,
				ctg: ctg,
				order: $('#ordem_val').val(),
				tipos: $('#classificacao_val').val(),
				checkFreeShipping: 1,
				checkAttribute: 1,
				otype: $('#ordem_val').val()+$('#classificacao_val').val(),
				limit: $('#itens_paginas_val').val(),
				templ: 'misc/dynamic_listProduct'
			});
		}
	};
})(jQuery);

$(function () {
	$('.menu .todas_categorias').click($.category.showAllCategories);
});