$(document).ready(function(){

		// Auto-populate form fields with their titles
		$('.populate').each(function(){
			var e = $(this);
			if (!e.val()) { e.val(e.attr('title')); }
			e.focus(function(){
				var e = $(this);
				if (e.attr('title') == e.val()) { e.val(''); }
			});
					
			e.blur(function(){
				var e = $(this);
				if (!e.val()) { e.val(e.attr('title')); }
			});
		});	
		
		// Simple animation for #top links
		$("a[href=#top]").click(function(){
			$("html, body").animate(
				{ scrollTop:0 }, 500
			);
			return false;
		});
					
		// Make external links open in new windows	
		$('a').each(function(){
			if (this.href.match('^https?://(?!'+document.location.hostname+')')) {
				this.target = '_blank';
			}
		});
		
		$("li#player a").click(function()
		{
			var player = $(this).attr("href");
			window.open(player, "audioplayer", "width=420,height=340,toolbar=0,location=0,scrollbars=0,resizable=0");
			return false;
		});
		
		// Catalog Page
		$('.panel').hide();
		$('.panel:first').show();
		$('p.cat-nav a:first').addClass('current');
		$('p.cat-nav a').click(function()
		{
			target = $(this).attr('href');
			$('p.cat-nav a').removeClass('current');
			$('.panel').hide();
			$(this).addClass('current');
			$(target).fadeIn();
			return false;
		});
	     
        $("#shows").tablesorter({ 
            headers: { 
                0: { 
                    sorter:'dates' 
                } 
            },
            sortList: [[0,0], [1,0]]
        });      
		
});

// add parser through the tablesorter addParser method 
$.tablesorter.addParser({ 
    // set a unique id 
    id: 'dates', 
    is: function(s) { 
        return false; 
    }, 
    format: function(s) { 
        return s.replace(/<span>.*<\/span>/,''); 
    },
    // set type, either numeric or text 
    type: 'text' 
});   
