jQuery(document).ready(function($){
	
	// HANDLES THE NAVIGATION
	function nav_handler(id){
		$('div#playlist li.selected').removeClass('selected');
		$('div#playlist li#'+id).addClass('selected');		
	}
	
	// HANDLES THE VIDEO
    // replace these default settings with your own
    $.playlist = {
        path_to_template: 'http://tomdreesen.com/wordpress/wp-content/themes/tomdreesen_2011/includes/js/',
        number_of_posts: 1,
        category_name: 'media',
		first_video: $('div#playlist li.selected').attr('id')
    }

    // do the initial load.
    $("#media").load(
		$.playlist.path_to_template + 'player.php' + 
		'?p=' + $.playlist.first_video + '&query=showposts%3D' + $.playlist.number_of_posts + 
		'%26category_name%3D'+ $.playlist.category_name +
		'%26p%3D'+$.playlist.first_video
	);

    //functions for the sorter
    $("div#playlist li").click(function(){
	
        var post_id = $(this).attr("id");
        var query = '?query=&p=' + post_id;

		nav_handler(post_id);
		
		$("div#media").fadeOut(function() {
			$("div#media").load($.playlist.path_to_template + 'player.php' + query, function() {
				$("div#media").fadeIn();
			});
		});
       return false;
    });	

	
});

