// JavaScript Document
// <![CDATA[
$(document).ready(function(){

	$('#flash_player').each(function(){

		var songID;
		var unique = $(this).attr('id');

		songID = $(this).next().find(':first a').attr('href');
		
		$(this).html('<img src=\'/images/loading.gif\' alt=\'\'/>');
		$(this).load('/includes/singlemp3player.php', {'songID': songID, 'autoplay': 'yes', 'id': unique });
	});
		
	jQuery("<img>").attr("src", '/images/loading.gif'); // Preload loading image.
	
		$('.playlist li a').each(function(){
		$(this).click(function() {

			$('.playlist li').each(function(){
				$(this).removeClass('current');
			});
			
			$(this).parent().addClass('current');
			var unique = $(this).parent().parent().prev().attr('id');
			//$(this).parent().parent().prev().html('<img src=\'/images/loading.gif\' alt=\'\'/>');
			$(this).parent().parent().prev().load('/includes/singlemp3player.php', {'songID': $(this).attr('href'), 'id': unique});
			return false;
		});
	});
	

	$('#main_nav li a, #main a').click(function(){
		if( $(this).attr('target') != '_blank' ){
		var href;
		href = $(this).attr('href');
		
		$('#main')
		.html('<div style="padding-left:40px;margin-top:20px;"><img src="/images/loading.gif" alt="" /></div>');
		
		$('#main').fadeOut(500, function(){ //Callback
			
			$('#main').load(href, {'ajax':'true'}, 
				function (){ // Callback
					$('#main').fadeIn(500);
					sendAlert(href);
				});
			});

			$(this).parent().parent().find('li').each(function(){
				$(this).removeClass('current');	
			});
		
			$(this).parent().addClass('current');
			
			$(this).parent().parent().find('li a').each(function(){
				$(this).removeClass('current');	
			});
		
			$(this).addClass('current');
			
			return false;
		}
		})
	
	function sendAlert(href){
		 pageTracker._trackPageview(href);
	}
	

});
// ]]>
