// Jplayer JavaScript Document

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

	var Playlist = function(instance, playlist, options) {
		var self = this;

		this.instance = instance; // String: To associate specific HTML with this playlist
		this.playlist = playlist; // Array of Objects: The playlist
		this.options = options; // Object: The jPlayer constructor options for this playlist

		this.current = 0;

		this.cssId = {
			jPlayer: "jquery_jplayer_",
			interface: "jp_interface_",
			playlist: "jp_playlist_"
		};
		this.cssSelector = {};

		$.each(this.cssId, function(entity, id) {
			self.cssSelector[entity] = "#" + id + self.instance;
		});

		if(!this.options.cssSelectorAncestor) {
			this.options.cssSelectorAncestor = this.cssSelector.interface;
		}

		$(this.cssSelector.jPlayer).jPlayer(this.options);

		$(this.cssSelector.interface + " .jp-previous").click(function() {
			self.playlistPrev();
			$(this).blur();
			return false;
		});

		$(this.cssSelector.interface + " .jp-next").click(function() {
			self.playlistNext();
			$(this).blur();
			return false;
		});
		//Create track select links on the page//
		$(".track_select").click(function() { 
   			index = parseInt($(this).attr('rel'));
			self.playlistChange(index);
			return false;
		});
		///////////////////////////////////////
		
	};

	Playlist.prototype = {
		displayPlaylist: function() {
			var self = this;
			$(this.cssSelector.playlist + " ul").empty();
			for (i=0; i < this.playlist.length; i++) {
				var listItem = (i === this.playlist.length-1) ? "<li class='jp-playlist-last'>" : "<li>";
				listItem += "<a href='#' id='" + this.cssId.playlist + this.instance + "_item_" + i +"' tabindex='1'>"+ this.playlist[i].name +"</a>";

				// Create links to free media
				if(this.playlist[i].free) {
					var first = true;
					listItem += "<div class='jp-free-media'>(";
					$.each(this.playlist[i], function(property,value) {
						if($.jPlayer.prototype.format[property]) { // Check property is a media format.
							if(first) {
								first = false;
							} else {
								listItem += " | ";
							}
							listItem += "<a id='" + self.cssId.playlist + self.instance + "_item_" + i + "_" + property + "' href='" + value + "' tabindex='1'>" + property + "</a>";
						}
					});
					listItem += ")</span>";
				}

				listItem += "</li>";
	
				// Associate playlist items with their media
				$(this.cssSelector.playlist + " ul").append(listItem);
				$(this.cssSelector.playlist + "_item_" + i).data("index", i).click(function() {
					var index = $(this).data("index");
					if(self.current !== index) {
						self.playlistChange(index);
					} else {
						$(self.cssSelector.jPlayer).jPlayer("play");
					}
					$(this).blur();
					return false;
				});

				// Disable free media links to force access via right click
				if(this.playlist[i].free) {
					$.each(this.playlist[i], function(property,value) {
						if($.jPlayer.prototype.format[property]) { // Check property is a media format.
							$(self.cssSelector.playlist + "_item_" + i + "_" + property).data("index", i).click(function() {
								var index = $(this).data("index");
								$(self.cssSelector.playlist + "_item_" + index).click();
								$(this).blur();
								return false;
							});
						}
					});
				}
			}
		},
	
		playlistInit: function(autoplay) {
			if(autoplay) {
				this.playlistChange(this.current);
			} else {
				this.playlistConfig(this.current);
			}
		},
		playlistConfig: function(index) {
			$(this.cssSelector.playlist + "_item_" + this.current).removeClass("jp-playlist-current").parent().removeClass("jp-playlist-current");
			$(this.cssSelector.playlist + "_item_" + index).addClass("jp-playlist-current").parent().addClass("jp-playlist-current");
			this.current = index;
			//Add Current Track to Player//
			$('#name').text(this.playlist[this.current].name);
			//////////////////////////////
			$(this.cssSelector.jPlayer).jPlayer("setMedia", this.playlist[this.current]);
		},
		playlistChange: function(index) {
			this.playlistConfig(index);
			$(this.cssSelector.jPlayer).jPlayer("play");
		},
		playlistNext: function() {
			var index = (this.current + 1 < this.playlist.length) ? this.current + 1 : 0;
			this.playlistChange(index);
		},
		playlistPrev: function() {
			var index = (this.current - 1 >= 0) ? this.current - 1 : this.playlist.length - 1;
			this.playlistChange(index);
		}
	};


	var audioPlaylist = new Playlist("2", [
		
		{
			name:"DJ Miller - It's The Little Things",
			mp3:"music/mp3/DJ Miller - It's The Little Things.mp3",
			oga:"music/ogg/DJ Miller - It's The Little Things.ogg"
		},
		{
			name:"DJ Miller - A Little Naughty is Nice",
			mp3:"music/mp3/DJ Miller - A Little Naughty is Nice.mp3",
			oga:"music/ogg/DJ Miller - A Little Naughty is Nice.ogg"
		},
		{
			name:"DJ Miller - A Snowman In Birmingham",
			mp3:"music/mp3/DJ Miller - A Snowman In Birmingham.mp3",
			oga:"music/ogg/DJ Miller - A Snowman In Birmingham.ogg"
		},
		{
			name:"DJ Miller - Whatever It Takes",
			mp3:"music/mp3/DJ Miller - Whatever It Takes.mp3",
			oga:"music/ogg/DJ Miller - Whatever It Takes.ogg"
		},
		{
			name:"Suite Caroline & DJ Miller - Sisters & Brothers",
			free:false,
			mp3:"music/mp3/Suite Caroline & DJ Miller - Sisters & Brothers.mp3",
			oga:"music/ogg/Suite Caroline & DJ Miller - Sisters & Brothers.ogg"
		},
		{
			name:"Suite Caroline - A Lil Love",
			mp3:"music/mp3/Suite Caroline - A Lil Love.mp3",
			oga:"music/ogg/Suite Caroline - A Lil Love.ogg"
		},
		{
			name:"Suite Caroline - Angels With Dirty Faces",
			mp3:"music/mp3/Suite Caroline - Angels With Dirty Faces.mp3",
			oga:"music/ogg/Suite Caroline - Angels With Dirty Faces.ogg"
		},
		{
			name:"Suite Caroline - Did You Have To Pick Her",
			free:false,
			mp3:"music/mp3/Suite Caroline - Did You Have To Pick Her.mp3",
			oga:"music/ogg/Suite Caroline - Did You Have To Pick Her.ogg"
		},
		{
			name:"Suite Caroline - I Fly",
			free:false,
			mp3:"music/mp3/Suite Caroline - I Fly.mp3",
			oga:"music/ogg/Suite Caroline - I Fly.ogg"
		},
		{
			name:"Suite Caroline - I Wasn't Ready",
			mp3:"music/mp3/Suite Caroline - I Wasn't Ready.mp3",
			oga:"music/ogg/Suite Caroline - I Wasn't Ready.ogg"
		},
		{
			name:"Suite Caroline - Old Enough To Love",
			mp3:"music/mp3/Suite Caroline - Old Enough To Love.mp3",
			oga:"music/ogg/Suite Caroline - Old Enough To Love.ogg"
		},
		{
			name:"Suite Caroline - Rock N' Roll Shoes",
			free:false,
			mp3:"music/mp3/Suite Caroline - Rock N' Roll Shoes.mp3",
			oga:"music/ogg/Suite Caroline - Rock N' Roll Shoes.ogg"
		},
		{
			name:"Suite Caroline - Who Won",
			mp3:"music/mp3/Suite Caroline - Who Won.mp3",
			oga:"music/ogg/Suite Caroline - Who Won.ogg"
		},
		{
			name:"Brad Wolf - Too Many Mondays (Not Enough Saturday Nights)",
			mp3:"music/mp3/Too Many Mondays Not Enough Saturday Nights Brad Master 11-30-11.mp3",
			oga:"music/ogg/Too Many Mondays Not Enough Saturday Nights Brad Master 11-30-11.ogg"
		},
		{
			name:"Brad Wolf - Love Oughta Be Perfect",
			mp3:"music/mp3/Brad Wolf - Love Oughta Be Perfect.mp3",
			oga:"music/ogg/Brad Wolf - Love Oughta Be Perfect.ogg"
		},
		{
			name:"Brad Wolf - I Make A Difference",
			free:false,
			mp3:"music/mp3/Brad Wolf - I Make A Difference.mp3",
			oga:"music/ogg/Brad Wolf - I Make A Difference.ogg"
		},
		{
			name:"Brad Wolf - Back To When We Had It All",
			free:false,
			mp3:"music/mp3/Brad_Wolf_-_Back_To_When_We_Had_It_All.mp3",
			oga:"music/ogg/Brad_Wolf_-_Back_To_When_We_Had_It_All.ogg"
		},
		{
			name:"Brad Wolf - Tan Lines",
			mp3:"music/mp3/Brad_Wolf_-_Tan Lines.mp3",
			oga:"music/ogg/Brad_Wolf_-_Tan Lines.ogg"
		},
		{
			name:"Abby Boykin - Faces of Love",
			free:false,
			mp3:"music/mp3/Abby_Boykin_-_Faces_of_Love.mp3",
			oga:"music/ogg/Abby_Boykin_-_Faces_of_Love.ogg"
		},
		{
			name:"Alabama - I Want To Know You Before We Make Love",
			mp3:"music/mp3/Alabama_-_I_Want_To_Know_You_Before_We_Make_Love.mp3",
			oga:"music/ogg/Alabama_-_I_Want_To_Know_You_Before_We_Make_Love.ogg"
		},
		{
			name:"Alecia Nugent - Just Another Alice",
			mp3:"music/mp3/Alecia_Nugent_-_Just_Another_Alice.mp3",
			oga:"music/ogg/Alecia_Nugent_-_Just_Another_Alice.ogg"
		},
		{
			name:"Baby Washington and The Plants - Congratulations Honey",
			free:false,
			mp3:"music/mp3/Baby Washington and The Plants - Congratulations Honey.mp3",
			oga:"music/ogg/Baby Washington and The Plants - Congratulations Honey.ogg"
		},
		{
			name:"Blake Shelton - Ol' Red",
			mp3:"music/mp3/Blake_Shelton_-_Ol'_Red.mp3",
			oga:"music/ogg/Blake_Shelton_-_Ol'_Red.ogg"
		},
		{
			name:"Bob Johnson - Walking on the Moon",
			mp3:"music/mp3/Bob_Johnson_-_Walking_on_the_Moon.mp3",
			oga:"music/ogg/Bob_Johnson_-_Walking_on_the_Moon.ogg"
		},
		{
			name:"Burns and Poe - It's Always A Woman",
			mp3:"music/mp3/Burns_and_Poe_-_It's_Always_A_Woman.mp3",
			oga:"music/ogg/Burns_and_Poe_-_It's_Always_A_Woman.ogg"
		},
		{
			name:"Cerrito - They Know You're Gone",
			free:false,
			mp3:"music/mp3/Cerrito_-_They_Know_You're_Gone.mp3",
			oga:"music/ogg/Cerrito_-_They_Know_You're_Gone.ogg"
		},
		{
			name:"Chad Austin - I Need An Angel",
			mp3:"music/mp3/Chad Austin - I Need An Angel.mp3",
			oga:"music/ogg/Chad Austin - I Need An Angel.ogg"
		},
		{
			name:"George Strait - Lovebug",
			free:false,
			mp3:"music/mp3/George Strait - Lovebug.mp3",
			oga:"music/ogg/George Strait - Lovebug.ogg"
		},
		{
			name:"Gordon Mote - Carry Me Away",
			free:false,
			mp3:"music/mp3/Gordon Mote - Carry Me Away.mp3",
			oga:"music/ogg/Gordon Mote - Carry Me Away.ogg"
		},
		{
			name:"Ha-ash - Malas Costumbres [Real Bad Habit]",
			mp3:"music/mp3/Ha-ash - Malas Costumbres [Real Bad Habit].mp3",
			oga:"music/ogg/Ha-ash - Malas Costumbres [Real Bad Habit].ogg"
		},
		{
			name:"Howard Lips - American Hamburger Way",
			free:false,
			mp3:"music/mp3/Howard_Lips_-_American_Hamburger_Way.mp3",
			oga:"music/ogg/Howard_Lips_-_American_Hamburger_Way.ogg"
		},
		{
			name:"Jamie Buckley - Wes Tyrell",
			free:false,
			mp3:"music/mp3/Jamie Buckley - Wes Tyrell.mp3",
			oga:"music/ogg/Jamie Buckley - Wes Tyrell.ogg"
		},
		{
			name:"Jaron Boyer - Believe",
			mp3:"music/mp3/Jaron Boyer - Believe.mp3",
			oga:"music/ogg/Jaron Boyer - Believe.ogg"
		},
		{
			name:"Jaron Boyer - I Will",
			mp3:"music/mp3/Jaron Boyer - I Will.mp3",
			oga:"music/ogg/Jaron Boyer - I Will.ogg"
		},
		{
			name:"John Berry - Change My Mind",
			free:false,
			mp3:"music/mp3/John_Berry_-_Change_My_Mind.mp3",
			oga:"music/ogg/John_Berry_-_Change_My_Mind.ogg"
		},
		{
			name:"John & Todd - A Better Light",
			mp3:"music/mp3/A_Better_Light.mp3",
			oga:"music/ogg/A_Better_Light.ogg"
		},
		{
			name:"Johnnie & Joe - Warm Soft and Lovely",
			mp3:"music/mp3/Johnnie_&_Joe_-_Warm_Soft_and_Lovely.mp3",
			oga:"music/ogg/Johnnie_&_Joe_-_Warm_Soft_and_Lovely.ogg"
		},
		{
			name:"Kristina Cornell - Little Red Balloon",
			mp3:"music/mp3/Kristina_Cornell_-_Little_Red_Balloon.mp3",
			oga:"music/ogg/Kristina_Cornell_-_Little_Red_Balloon.ogg"
		},
		{
			name:"Linda Davis - I Make A Difference",
			mp3:"music/mp3/Linda Davis - I Make A Difference.mp3",
			oga:"music/ogg/Linda Davis - I Make A Difference.ogg"
		},
		{
			name:"Linda Davis - My Amazing Grace",
			mp3:"music/mp3/Linda_Davis_-_My_Amazing_Grace.mp3",
			oga:""
		},
		{
			name:"Mark Cooke - Can't Cheat In a Small Town",
			free:false,
			mp3:"music/mp3/Mark Cooke - Can't Cheat In a Small Town.mp3",
			oga:"music/ogg/Mark Cooke - Can't Cheat In a Small Town.ogg"
		},
		{
			name:"Megan Conner - Barbed Wire",
			mp3:"music/mp3/Megan Conner - Barbed Wire.mp3",
			oga:"music/ogg/Megan Conner - Barbed Wire.ogg"
		},
		{
			name:"Megan Conner - He Don't Love Me (Like You Do)",
			mp3:"music/mp3/Megan Conner - He Don't Love Me (Like You Do).mp3",
			oga:"music/ogg/Megan Conner - He Don't Love Me (Like You Do).ogg"
		},
		{
			name:"Megan Conner - Little Redneck Riding Hood",
			free:false,
			mp3:"music/mp3/Megan Conner - Little Redneck Riding Hood.mp3",
			oga:"music/ogg/Megan Conner - Little Redneck Riding Hood.ogg"
		},
		{
			name:"Megan Conner - Midnight Lonely",
			free:false,
			mp3:"music/mp3/Megan Conner - Midnight Lonely.mp3",
			oga:"music/ogg/Megan Conner - Midnight Lonely.ogg"
		},
		{
			name:"Megan Conner - Quicksand",
			mp3:"music/mp3/Megan Conner - Quicksand.mp3",
			oga:"music/ogg/Megan Conner - Quicksand.ogg"
		},
		{
			name:"Megan Conner - Who Won",
			mp3:"music/mp3/Megan Conner - Who Won.mp3",
			oga:"music/ogg/Megan Conner - Who Won.ogg"
		},
		{
			name:"Megan Conner - Dandelions",
			free:false,
			mp3:"music/mp3/Megan_Conner_-_Dandelions.mp3",
			oga:"music/ogg/Megan_Conner_-_Dandelions.ogg"
		},
		{
			name:"Megan Conner - Drink One For Me",
			mp3:"music/mp3/Megan_Conner_-_Drink_One_For_Me.mp3",
			oga:"music/ogg/Megan_Conner_-_Drink_One_For_Me.ogg"
		},
		{
			name:"Megan Conner - One More Story",
			mp3:"music/mp3/Megan_Conner_-_One_More_Story.mp3",
			oga:"music/ogg/Megan_Conner_-_One_More_Story.ogg"
		},
		{
			name:"Megan Conner - Red, White and Blue Night in Georgia",
			free:false,
			mp3:"music/mp3/Megan_Conner_-_Red,_White_and_Blue_Night_in_Georgia.mp3",
			oga:""
		},
		{
			name:"Megan Conner - Turn Off The Night",
			mp3:"music/mp3/Megan_Conner_-_Turn_Off_The_Night.mp3",
			oga:"music/ogg/Megan_Conner_-_Turn_Off_The_Night.ogg"
		},
		{
			name:"MJ2 - You Can't Say Love Enough",
			free:false,
			mp3:"music/mp3/MJ2_-_You_Can't_Say_Love_Enough.mp3",
			oga:"music/ogg/MJ2_-_You_Can't_Say_Love_Enough.ogg"
		},
		{
			name:"Pete Rose Liner (5/16/11)",
			mp3:"music/mp3/PeteRose5-16-11.mp3",
			oga:"music/ogg/PeteRose5-16-11.ogg"
		},
		{
			name:"Pirates of the Mississippi - Gravy",
			free:false,
			mp3:"music/mp3/Pirates_of_the_Mississippi_-_Gravy.mp3",
			oga:"music/ogg/Pirates_of_the_Mississippi_-_Gravy.ogg"
		},
		{
			name:"Rio Grand - God's Got a Bigger Plan",
			mp3:"music/mp3/Rio_Grand_-_Bigger_Plan.mp3",
			oga:"music/ogg/Rio_Grand_-_Bigger_Plan.ogg"
		},
		{
			name:"Shawn Hammonds - Daddy [Was A Tranny]",
			free:false,
			mp3:"music/mp3/Shawn Hammonds - Daddy.mp3",
			oga:"music/ogg/Shawn Hammonds - Daddy.ogg"
		},
		{
			name:"Shawn Hammonds - Everything",
			mp3:"music/mp3/Shawn_Hammonds_-_Everything.mp3",
			oga:"music/ogg/Shawn_Hammonds_-_Everything.ogg"
		},
		{
			name:"Shawn Hammonds - Somebody Mama Would Like",
			mp3:"music/mp3/Shawn_Hammonds_-_Somebody_Mama_Would_Like.mp3",
			oga:"music/ogg/Shawn_Hammonds_-_Somebody_Mama_Would_Like.ogg"
		},
		{
			name:"The Capris - Morse Code of Love",
			mp3:"music/mp3/The Capris - Morse Code of Love.mp3",
			oga:"music/ogg/The Capris - Morse Code of Love.ogg"
		},
		{
			name:"The Kac-Ties - Let Your Love Light Shine",
			free:false,
			mp3:"music/mp3/The Kac-Ties - Let Your Love Light Shine.mp3",
			oga:"music/ogg/The Kac-Ties - Let Your Love Light Shine.ogg"
		},
		{
			name:"The Roys - Absolutely, Positively, Maybe",
			mp3:"music/mp3/The Roys - Absolutely, Positively, Maybe.mp3",
			oga:"music/ogg/The Roys - Absolutely, Positively, Maybe.ogg"
		},
		{
			name:"The Clickettes - Lover's Prayer",
			mp3:"music/mp3/The_Clickettes_-_Lover's_Prayer.mp3",
			oga:"music/ogg/The_Clickettes_-_Lover's_Prayer.ogg"
		},
		{
			name:"Tommy Lee Snyder - Touchdown Jesus",
			free:false,
			mp3:"music/mp3/Tommy Lee Snyder_-_Touchdown_Jesus.mp3",
			oga:"music/ogg/Tommy Lee Snyder_-_Touchdown_Jesus.ogg"
		},
		{
			name:"Tommy Lee Snyder - Jesus on the Radio",
			mp3:"music/mp3/Tommy_Lee_Snyder_-_Jesus_on_the_Radio.mp3",
			oga:"music/ogg/Tommy_Lee_Snyder_-_Jesus_on_the_Radio.ogg"
		},
		{
			name:"Tommy Lee Snyder - What Have You Done",
			mp3:"music/mp3/Tommy_Lee_Snyder_-_What_Have_You_Done.mp3",
			oga:"music/ogg/Tommy_Lee_Snyder_-_What_Have_You_Done.ogg"
		},
		{
			name:"Reba - I'll Still Be Loving You",
			mp3:"music/mp3/Reba - I'll Still Be Loving You.mp3",
			oga:"music/ogg/Reba - I'll Still Be Loving You.ogg"
		}
		
		
	], {
		ready: function() {
			audioPlaylist.displayPlaylist();
			audioPlaylist.playlistInit(false); // Parameter is a boolean for autoplay.
		},
		ended: function() {
			audioPlaylist.playlistNext();
		},
		play: function() {
			$(this).jPlayer("pauseOthers");
		},
		swfPath: "js",
		supplied: "oga, mp3"
	});
	
});
//]]>
