$(document).ready(function() {

	// do the filtering when page loads
	dofilter( $("#filter_select").val() );

	// do the filtering when <select> changes
	$("#filter_select").bind('change', function(){
		dofilter( $(this).val() );
		return false;
	});

	
	
});


// function to filter show/hide items and to change the links according to the filter type
function dofilter(val){
	//alert(val);
	
	if (val != ''){
	var selval = val;	// value of selected option
	var filterVal = selval.toLowerCase().replace(' ','-');
	
	if(filterVal == 'all') {
		$('ul#cat li.hidden').fadeIn('slow').removeClass('hidden');	//show all list items
		} else {
			// for each item in list
			$('ul#cat li').each(function() {
				if(!$(this).hasClass(filterVal)) {
					$(this).fadeOut('normal').addClass('hidden');	// hide
				} else {
					var link = $(this).find('a').attr("href");					// get the link value:  index.php?x=browse&category=27
					$(this).find('a').attr("href",link + '&filter=' + selval);	//change link value according to filter type
					//this.a.href = this.a.href.replace(/^http:\/\/beta\.stackoverflow\.com/, "http://stackoverflow.com");
					$(this).fadeIn('slow').removeClass('hidden');	// show
				}
			});
		}// end if/else
	}// end if

}// end fn


function select_cat(url,datastr) {
	
	//alert('truc');
	//get the form
	/*
	var html = $.ajax({
		url: url + '?' + datastr,
		async: false
	}).responseText;

	
	// prompt the form
	$("#content_wrap").html(html);
	*/
	
	
	$.ajax({
		type: 'post',
		url: url,   //<?php echo htmlentities($_SERVER['PHP_SELF']);   ?>
		data: datastr + '&filter=pc',	//'user='+ user + '&societe='+ societe+ '&password='+ password,
		success: function() {
			//alert ('adding ok ! \n');
			// message
			$("span#message").text("Validated...").show().fadeOut(2000);
			
			
		}
	});// end ajax
	//return false; //default result is error
	

}
