// JavaScript Document
$(function(){
	
		$('.filtro_plataformas').click(function(){
			
				if ($(this).is(':checked')){
					$('.plataformas').each(function(){
						$(this).attr('checked','checked');
					})
				}else{
					$('.plataformas').each(function(){
						$(this).attr('checked','');
					})
				}
			list_apps();
		})
		
		$('.filtro_Tipo').click(function(){
			
				if ($(this).is(':checked')){
					$('.tipo').each(function(){
						$(this).attr('checked','checked');
					})
				}else{
					$('.tipo').each(function(){
						$(this).attr('checked','');
					})
				}
			list_apps();
		})
		
		$('.filtro').click(function(){
			list_apps();
		})
	
		
})

list_apps = function(){
	
	var filtro='';
	
	$('.filtro').each(function(){
			if ($(this).is(':checked')){
				filtro += (!filtro) ? this.value : ','+this.value;
			}
	})
	

	$.ajax({
		   beforeSend : function(){
				$('#app_list > ul').fadeOut(500,function(){
					$('#app_list .loading').fadeIn();
					$('.swControls').hide();
																		 
				});  
		   },
		   type: "POST",
		   url: "../ajax.php",
		   data: "opc=listApp&filter="+filtro,
		   success: function(msg){
			  $('#app_list').html(msg);
			  $('#holder').sweetPages({perPage:25});
				var controls = $('.swControls').detach();
				controls.appendTo('#app_list');
			},
			complete : function(){
				ajustImage();
				$('.swControls').show();
			}
	})
	//alert(filtro);

}
