$(function() 
	        {

		
		current_track = 1;
		number_tracks = $('#track_list').children("li").length;
		
		//number_tracks = 11;
		
		//alert(number_tracks);
		
		
		$("a").each(function(){
  			if( $(this).attr('href') &&  $(this).attr('href').slice(-4) == '.mp3') 
  			{
    			$(this).click(function(e){
					//alert('mp3 link');
					
					change_sound($(this).attr('href'),$(this).text(),'');
					play_sound();
    				return false;
    			});
			}
		});



		
		
		$(".scrollable").scrollable({size:3});
		//$(".event_list").scrollable({size: 3, items:"ul", item:"li", vertical:false});
		//$(".event_list").scrollable({size: 3});
		//  $("a[rel^='eventPhoto']").prettyPhoto(/*{allowresize: false }*/);
		  /*
	        $("ul#nav li").hover(function() { //Hover over event on list item
				e = this;
				
	        	if(!$(e).is('.selected'))
	            {
	        		$(e).siblings('.selected').find('li').hide();
	                $(e).find("ul").show(); //Show the subnav
	            }
	        	
	    	} , function() { //on hover out...
				e = this;
	    		if(!$(e).is('.selected'))
	    		{
	    			 $(e).find("ul").fadeOut(500);
	    			 
	    			//$(e).find("ul").hide(); //Hide the subnav
	    			$(e).siblings('.selected').find('li').fadeIn(500);
	    		}
	        			
	    	}); 
*/

			function set_sound_playlist()
			{
				file = $('#track_list li:nth-child(' + current_track + ') a').attr('href');
		    	title = $('#track_list li:nth-child(' + current_track + ') a strong').text();
		    	caption = '';
		    	change_sound(file, title, caption);
		    	
		    	if($('#player_container').hasClass('playing'))
		    		$('#jquery_jplayer').jPlayer("play");
				
			}
			
			
			
			function change_sound(url,title,caption)
			{
				//alert(url + ':' + title + ':' + caption);
				$('#jquery_jplayer').jPlayer("setFile",url);
				$('#track_url').text(url);
				$('#track_info').html("<span class='track_title'>" +  title + "</span><span class='track_caption'>"+ caption + "</span>");
    	    	return false;
			}
			
			
	        function play_sound()
	        {
		    	//$('#jquery_jplayer').jPlayer("setFile",$('#track_url').text());
		    	//alert($('#track_url').text());
		    	$('#jquery_jplayer').jPlayer("play");
				$('#player_container').addClass('playing');
		    	return false;
		        
	        }
			function pause_sound()
			{
				$('#jquery_jplayer').jPlayer("pause");
		    	$('#player_container').removeClass('playing'); 
		    	return false;
			}

			
			function handle_sound_link(url,title,caption)
			{
				change_sound(url,title,caption);
				play_sound();
    	    	return false;
			}
			
			
			function next_sound()
			{
				
				if(current_track<number_tracks)
					current_track++;
				//play_sound();
				set_sound_playlist();
				return false;
			}
			
			function prev_sound()
			{
				if(current_track>1)
					current_track--;
				//play_sound();
				set_sound_playlist();
				return false;
			}
			
			
	     // Stores the value of percentage of track loaded
	    	var global_lp = 0;

	    	$("#jquery_jplayer").jPlayer(
	    	    	{
	    		ready: function () 
	    		{
	    		//alert('test');
	    			//$("#jquery_jplayer").jPlayer("setFile",'http://shinenightclub.com/shine/wp-content/uploads/2010/05/02-vega-no-reasons.mp3');//.volume(40).play();
					//$("#jquery_jplayer").jPlayer("volume",50);
				//	$("#jquery_jplayer").jPlayer("play");
	    			// Draw the control bar

	    		//	$('#player_progress_ctrl_bar').html(ctrlBar);

	    		//	demoInstanceInfo($(this), $("#jplayer_info"));
	    		}, 
	    		swfPath: tdir + '/js',
	    		//errorAlerts: true,
	    		//warningAlerts: true
	    	}
			
	    	)
	    	/*.onProgressChange( function(lp,ppr,ppa,pt,tt) {
	     		var lpInt = parseInt(lp);
	     		var ppaInt = parseInt(ppa);
 
	     		global_lp = lpInt;
	     		$('#player_progress_load_bar').width(lpInt + '%');
	     		$('#player_progress_play_bar').width(ppaInt + '%');
	     		
	    	})
	    	.onSoundComplete( function() {
	    		$(this).play();
	    	})*/;





		$("#player_volume").click(function(e) {
		
		var x = e.pageX - $("#player_volume").offset().left;
		var percent = parseInt(x / $("#player_volume").width() * 100);
		$("#player_volume_level").css("width", percent + '%');
		$("#jquery_jplayer").jPlayer("volume",parseInt(percent));
		});





		$("#player_prev").click( function() {return prev_sound();});
		$("#player_next").click( function() {return next_sound();});


	    	$("#player_play").click( function() { 

		    	//alert(current_track);
		    	//$("#jquery_jplayer").jPlayer("setFile",'http://shinenightclub.com/shine/wp-content/uploads/2010/05/02-vega-no-reasons.mp3');
		    	
		 
		   $('#jquery_jplayer').jPlayer("setFile",String($('#track_url').text()));
		    	
		    	
		    	$("#jquery_jplayer").jPlayer("play");
		    	$('#player_container').addClass('playing');
		    	
		    	//set_sound();
	 
		    	//return play_sound();
		    	return false;

		    	});
	    	$("#player_pause").click( function() { 
		    	return pause_sound(); 
		    });
		    
		    
	    	//$("#player_volume_min").click( function() { $('#jquery_jplayer').volume(0); return false; });
	    	//$("#player_volume_max").click( function() { $('#jquery_jplayer').volume(100); return false; });
	    	
	    	$("#player_progress_ctrl_bar").click(
	    	    	 function(e) 
	    	    	 { 
   	    	 			var x = e.pageX - $(this).offset().left;
        				
						head_position = ( 100 * (x/$('#player_progress').width() )) * (100.0/global_lp); // um , ya ... yuck
						if(head_position > 100)
								head_position = 100; // jplayer cant go past loaded percent so chop it off... 
						$('#jquery_jplayer').playHead(head_position);
						
   	    	 			return false;
   	    	 		}
   	 		);
   	 		/*
	    	$("a.media_play_link").click( 
	    	    	function()  
	    	    	{ 
		    	    	if($(this).is('.playing'))
		    	    	{
		    	    		$(this).addClass('paused');
		    	    		$(this).removeClass('playing');
			    	    	return pause_sound();
		    	    	}
		    	    	else if ($(this).is('.paused'))
		    	    	{
		    	    		$(this).removeClass('paused');
		    	    		$(this).addClass('playing');
		    	    		return play_sound();	
		    	    	}
		    	    	else
		    	    	{
							$('.media_play_link').removeClass('playing').removeClass('paused');
		    	    		$(this).addClass('playing');
		    	    		return handle_sound_link(this.href);
		    	    	}
		    	    }
	    	  );*/
	    	  
	    	  set_sound_playlist();	   
	});
