
var tags = ['jquery','proto','moo','yui','nolib','images','sets','inline','iframes','ajax','flash','video'];
var tagslib = ['jquery','proto','moo','yui','nolib'];
var tagsfeat = ['images','sets','inline','iframes','ajax','flash','video'];
var checked = [];
var controls = 'desc';

jQuery(document).ready(function() {
	$(tagslib).each(function(i,e){
		$('#'+e).attr('checked', 'checked');
	});
        $(tagsfeat).each(function(i,e){
                $('#'+e).attr('checked', false);
        });


	$("#sortmeplease").tablesorter( {sortList:[[0,0]],widgets: ['zebra']});

	get_checks();
	
	$('#minmax').click(function(){
		$('#toggle').slideToggle(120, function(){
			controls = (controls == 'desc' ) ? 'asc' : 'desc' ;
			$('#minmax').css('background-image', 'url(images/'+controls+'.gif)');
		});
		
	});
	
	jQuery(tags).each(function(){
		jQuery('#'+this).click(function() {
			get_checks();
		});
	});
	
	$('#controls .oscar span').click(function(){
		toggle_checks($(this).parent().parent().parent().attr('id'), $(this).attr('class'))
	});
	
} 
);

function toggle_checks(div, action) {
	$('#'+div + ' :input').each(function() {
		switch(action) {
		case 'toggle':
			var _action = $(this).attr('checked') == true ? false : true;
		break;    
		default:
			var _action = (action == 'none') ? false : true;
		}
		$(this).attr('checked', _action );
	});
	get_checks();
}

// Better function by nicholas@oxhoej.dk. Thanks!
function get_checks() {
	var feature_exp = $('#feat input:checked').map(function() {return '.'+$(this).attr('id')}).get().join('');

	var filter_exp = $('#lib input:checked').map(function() {return '.'+$(this).attr('id')+feature_exp}).get().join(',');

	var table = $('#sortmeplease tbody tr');

	// Hide non-matches
	table.not(filter_exp).hide();

	// Show and count matches
	var count = table.filter(filter_exp).show().size();

	// Re-zebra visible rows
	table.filter(':visible')
		.filter(':even')
			.addClass('odd')
		.end()
		.filter(':odd')
			.removeClass('odd');

	// Update count
	$('#count').html(count + ' found. ');
}

function get_books(json) {
        $(document).ready(function(){
        var books = json[0].total_posts.toString();
        $('#delbooks').html('<img border="1" src="http://static.delicious.com/img/delicious.gif"/> <b>'+books+'</b> bookmarks');
        });
}

