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

$(document).ready(function()
{	
	oTable=$("#membres").dataTable( {
			"bPaginate": false,
			"bLengthChange": false,
			"bFilter": false,
			"bSort": true,
			"bJQueryUI": true,
			"bInfo": true,
			"bAutoWidth": true,
			"aoColumns": [
			  			{ "sType": "html" },
			  			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) );
	} );
	
	
	$(".wymeditor").wymeditor({
		lang: 'fr',
		skin: 'silver',
		stylesheet: '/styles.css',
		updateSelector: "#new",
		updateEvent:    "click",
		containersItems: [
		                  {'name': 'P', 'title': 'Paragraph', 'css': 'wym_containers_p'},
		                  {'name': 'H4', 'title': 'Heading_4', 'css': 'wym_containers_h4'}
		                ],
			toolsItems: [{'name': 'Bold', 'title': 'Strong', 'css': 'wym_tools_strong'}, 
	                     {'name': 'Italic', 'title': 'Emphasis', 'css': 'wym_tools_emphasis'},
	                     {'name': 'InsertUnorderedList', 'title': 'Unordered_List', 'css': 'wym_tools_unordered_list'},
	                     {'name': 'Undo', 'title': 'Undo', 'css': 'wym_tools_undo'},
	                     {'name': 'Redo', 'title': 'Redo', 'css': 'wym_tools_redo'},
	                     {'name': 'InsertImage', 'title': 'Image', 'css': 'wym_tools_image'},
	                     {'name': 'CreateLink', 'title': 'Link', 'css': 'wym_tools_link'},
	                     {'name': 'Unlink', 'title': 'Unlink', 'css': 'wym_tools_unlink'},
	                     {'name': 'ToggleHtml', 'title': 'HTML', 'css': 'wym_tools_html'},
	                     {'name': 'Preview', 'title': 'Preview', 'css': 'wym_tools_preview'}
	                    ]});

	
	/*
	 * 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'
	    });

	  });

	});	
    			