//Global variable definitions
//DB column numbers
var oTable;
var asInitVals = new Array();

$(document).ready(function()
{	
	$(".pwd2").nakedPassword({path: "include/naked/images/"}); 
	
	oTable=$(".membres").dataTable( {
			"bPaginate": false,"bLengthChange": false,"bFilter": false,"bSort": false,"bJQueryUI": true,"bInfo": false,"bAutoWidth": true,
			"aoColumns": [null,null,null,{ "asSorting": [  ] },null,{ "asSorting": [  ] },{ "asSorting": [  ] }] ,
			"oLanguage": {"sInfo": "Affichage de _START_ ŕ _END_ sur _TOTAL_ membres","sInfoFiltered": "(Filtré ŕ partir de _MAX_ enregistrements)"}});



	$(".searchBox input").keyup( function () {
		/* Filter on the column (the index) of this element */
		oTable.fnFilter( this.value, $(".searchBox input").index(this) );
	} );
	
	/*
	 * Support functions to provide a little bit of 'user friendlyness' to the textboxes in 
	 * the footer
	 */
	$(".searchBox input").each( function (i) {
		asInitVals[i] = this.value;
	} );
	
	$(".searchBox input").focus( function () {
		if ( this.className == "search_init" )
		{
			this.className = "";
			this.value = "";
		}
	} );
	
	$(".searchBox input").blur( function (i) {
		if ( this.value == "" )
		{
			this.className = "search_init";
			this.value = asInitVals[$(".searchBox input").index(this)];
		}
	} );
	$(".award *").tooltip({
		showURL: false
	});
	$(".imgaward").tooltip({
		showURL: false
	});

	
});
(function($) {
	  $.fn.sorted = function(customOptions) {
	    var options = {
	      reversed: false,
	      by: function(a) { return a.text(); }
	    };
	    $.extend(options, customOptions);
	    $data = $(this);
	    arr = $data.get();
	    arr.sort(function(a, b) {
	      var valA = options.by($(a));
	      var valB = options.by($(b));
	      if (options.reversed) {
	        return (valA < valB) ? 1 : (valA > valB) ? -1 : 0;				
	      } else {		
	        return (valA < valB) ? -1 : (valA > valB) ? 1 : 0;	
	      }
	    });
	    return $(arr);
	  };
	})(jQuery);
$(function() {

	  // bind radiobuttons in the form
	  var $filterType = $('#filter input[name="type"]');
	  var $filterSort = $('#filter input[name="sort"]');

	  // get the first collection
	  var $applications = $('#applications');

	  // clone applications to get a second collection
	  var $data = $applications.clone();

	  // attempt to call Quicksand on every form change
	  $filterType.add($filterSort).change(function(e) {
	    if ($($filterType+':checked').val() == 'all') {
	      var $filteredData = $data.find('li');
	    } else {
	      var $filteredData = $data.find('li[data-type=' + $($filterType+":checked").val() + ']');
	    }

	    // if sorted by size
	    if ($('#filter input[name="sort"]:checked').val() == "size") {
	      var $sortedData = $filteredData.sorted({
	        by: function(v) {
	          return parseFloat($(v).find('span[data-type=size]').text());
	        }
	      });
	    } else {
	      // if sorted by name
	      var $sortedData = $filteredData.sorted({
	        by: function(v) {
	          return $(v).find('strong').text().toLowerCase();
	        }
	      });
	    }   

	    // finally, call quicksand
	    $applications.quicksand($sortedData, {
	      duration: 800,
	      easing: 'easeInOutQuad'
	    });

	  });

	});	
    			
