(function($){
	
// The DOM is now ready
$(function() {
		
		var playItem = 0;

		var myPlayList = [
			{name:"Levitate - Out with the Drought<br />http://www.myspace.com/levitatehiphop",mp3:"http://voiceof2million.com/mp3/out_with_the_drought.mp3"},
			{name:"David Leland Horton - Stay in Cleveland<br />http://www.myspace.com/therarebirds",mp3:"http://voiceof2million.com/mp3/stay_in_cleveland.mp3"},
			{name:"Scars Define – Citizen James",mp3:"http://voiceof2million.com/mp3/citizen_james.mp3"},
			{name:"Ajax Major - Ring for the King",mp3:"http://voiceof2million.com/mp3/ring_for_the_king.mp3"},
			{name:"Cleveland Celebrities - We Are LeBron",mp3:"http://voiceof2million.com/mp3/we_are_lebron.mp3"},
			{name:"M.A.P.M. – Next Year's Our Year",mp3:"http://voiceof2million.com/mp3/next_year.mp3"}
		];

		// Local copy of jQuery selectors, for performance.
		var jpPlayTime = $("#jplayer_play_time");
		var jpTotalTime = $("#jplayer_total_time");

		var swfpathBrowser = 'js/jPlayer';
		if($.browser.msie){
			var swfpathBrowser = '/js/jPlayer';
		}
		
		$("#jquery_jplayer").jPlayer({
			swfPath: swfpathBrowser,
			ready: function() {
				displayPlayList();
				playListInit(false); // Parameter is a boolean for autoplay.
			}
		})
		.jPlayer("onProgressChange", function(loadPercent, playedPercentRelative, playedPercentAbsolute, playedTime, totalTime) {
			jpPlayTime.text($.jPlayer.convertTime(playedTime));
			jpTotalTime.text($.jPlayer.convertTime(totalTime));
		})
		.jPlayer("onSoundComplete", function() {
			playListNext();
		});


		$("#jplayer_previous").click( function() {
			playListPrev();
			$(this).blur();
			return false;
		});

		$("#jplayer_next").click( function() {
			playListNext();
			$(this).blur();
			return false;
		});

		function displayPlayList() {
			$("#jplayer_playlist ul").empty();
			for (i=0; i < myPlayList.length; i++) {
				var listItem = (i == myPlayList.length-1) ? "<li class='jplayer_playlist_item_last'>" : "<li>";
				listItem += "<a href='#' id='jplayer_playlist_item_"+i+"' tabindex='1'>"+ myPlayList[i].name +"</a></li>";
				$("#jplayer_playlist ul").append(listItem);
				$("#jplayer_playlist_item_"+i).data( "index", i ).click( function() {
					var index = $(this).data("index");
					if (playItem != index) {
						playListChange( index );
					} else {
						$("#jquery_jplayer").jPlayer("play");
					}
					$(this).blur();
					return false;
				});
			}
		}

		function playListInit(autoplay) {
			if(autoplay) {
				playListChange( playItem );
			} else {
				playListConfig( playItem );
			}
		}

		function playListConfig( index ) {
			$("#jplayer_playlist_item_"+playItem).removeClass("jplayer_playlist_current").parent().removeClass("jplayer_playlist_current");
			$("#jplayer_playlist_item_"+index).addClass("jplayer_playlist_current").parent().addClass("jplayer_playlist_current");
			playItem = index;
			$("#jquery_jplayer").jPlayer("setFile", myPlayList[playItem].mp3);
		}

		function playListChange( index ) {
			playListConfig( index );
			$("#jquery_jplayer").jPlayer("play");
		}

		function playListNext() {
			var index = (playItem+1 < myPlayList.length) ? playItem+1 : 0;
			playListChange( index );
		}

		function playListPrev() {
			var index = (playItem-1 >= 0) ? playItem-1 : myPlayList.length-1;
			playListChange( index );
		}
		
		var breakRule = '<br class="clearer" />';
		
		$('.tubepress_container,.tubepress_thumbs,.tubepress_thumbnail_area').append(breakRule);
		
		$('ul.commentlist li .comment-meta a').click(function(){
			return false;
		});
		
		// var commentHeight = $("div.comment_copy");
		// for (z=0; z < commentHeight.length; z++) {
		// 	alert(commentHeight.height());
		// }
		
		var flashvars = { flash_page:'false' };
		var params = { wmode:'transparent' }; 
		var attributes = {};
		attributes.id = "flash_header";
		if ($('body').hasClass('page-id-5')){
			swfobject.embedSWF("/flash/people.swf", "flashAlt", "300", "200", "9.0.0", false, flashvars, params, attributes);
		} else if ($('body').hasClass('page-id-8')){
			swfobject.embedSWF("/flash/music.swf", "flashAlt", "300", "200", "9.0.0", false, flashvars, params, attributes);
		} else if ($('body').hasClass('page-id-20')){
				swfobject.embedSWF("/flash/discussion.swf", "flashAlt", "300", "200", "9.0.0", false, flashvars, params, attributes);
		} else {
				swfobject.embedSWF("/flash/home.swf", "flashAlt", "300", "200", "9.0.0", false, flashvars, params, attributes);
		}
	});

	})( jQuery.noConflict() ); // Pass in jQuery so we can safely use the $ alias within this block

