var playlist_ffw = [
	// object {url:string url, title:string title, artist: string artist]
	// or
	// string url
	{url:'http://s3.amazonaws.com/cash_users/50footwave/catalog/50FootWave/01Bug.mp3',title:'Bug',artist:'50footwave'},
	{url:'http://s3.amazonaws.com/cash_users/50footwave/catalog/50FootWave/02ClaraBow.mp3',title:'Clara Bow',artist:'50footwave'},
	{url:'http://s3.amazonaws.com/cash_users/50footwave/catalog/50FootWave/03LongPainting.mp3',title:'Long Painting',artist:'50footwave'},
	{url:'http://s3.amazonaws.com/cash_users/50footwave/catalog/50FootWave/04GloryWeed.mp3',title:'Glory Weed',artist:'50footwave'},
	{url:'http://s3.amazonaws.com/cash_users/50footwave/catalog/50FootWave/05Lavender.mp3',title:'Lavender',artist:'50footwave'},
	{url:'http://s3.amazonaws.com/cash_users/50footwave/catalog/50FootWave/06DogDays.mp3',title:'Dog Days',artist:'50footwave'}
];

var playlist_go = [
	// object {url:string url, title:string title, artist: string artist]
	// or
	// string url
	{url:'http://s3.amazonaws.com/cash_users/50footwave/catalog/GoldenOcean/01BoneChina.mp3',title:'Bone China',artist:'50footwave'},
	{url:'http://s3.amazonaws.com/cash_users/50footwave/catalog/GoldenOcean/02Pneuma.mp3',title:'Pneuma',artist:'50footwave'},
	{url:'http://s3.amazonaws.com/cash_users/50footwave/catalog/GoldenOcean/03Petal.mp3',title:'Petal',artist:'50footwave'},
	{url:'http://s3.amazonaws.com/cash_users/50footwave/catalog/GoldenOcean/04SallyIsAGirl.mp3',title:'Sally Is A Girl',artist:'50footwave'},
	{url:'http://s3.amazonaws.com/cash_users/50footwave/catalog/GoldenOcean/05ElDorado.mp3',title:'El Dorado',artist:'50footwave'},
	{url:'http://s3.amazonaws.com/cash_users/50footwave/catalog/GoldenOcean/06GingerPark.mp3',title:'Ginger Park',artist:'50footwave'},
	{url:'http://s3.amazonaws.com/cash_users/50footwave/catalog/GoldenOcean/07Diving.mp3',title:'Diving',artist:'50footwave'},
	{url:'http://s3.amazonaws.com/cash_users/50footwave/catalog/GoldenOcean/08Golden%20Ocean.mp3',title:'Golden Ocean',artist:'50footwave'}
];

var playlist_fm = [
	// object {url:string url, title:string title, artist: string artist]
	// or
	// string url
	{url:'http://s3.amazonaws.com/cash_users/50footwave/catalog/FreeMusic/01HotPink_Distorted.mp3',title:'Hot Pink, Distorted',artist:'50footwave'},
	{url:'http://s3.amazonaws.com/cash_users/50footwave/catalog/FreeMusic/02VenaCava.mp3',title:'Vena Cava',artist:'50footwave'},
	{url:'http://s3.amazonaws.com/cash_users/50footwave/catalog/FreeMusic/03PrettyUgly.mp3',title:'Pretty Ugly',artist:'50footwave'},
	{url:'http://s3.amazonaws.com/cash_users/50footwave/catalog/FreeMusic/04Animal.mp3',title:'Animal',artist:'50footwave'},
	{url:'http://s3.amazonaws.com/cash_users/50footwave/catalog/FreeMusic/05TheFuchsiaWall.mp3',title:'The Fuchsia Wall',artist:'50footwave'}
];

var player_ffw = new SoundPlayer({
	playlist:playlist_ffw,
	injectInto:"soundplayer_ffw",
	swfLocation:"../scripts/SoundPlayer.swf",
	controlImages:{previous:"images/previous.png",next:"images/next.png",play:"images/play.png",pause:"images/pause.png"},
	seekbarSpcStyle: {'position':'relative','background-color':'#666','height':'3px','width':'100%','margin-top':'4px','overflow':'hidden'},
	seekbarStyle: {'position':'absolute','background-color':'#fff','height':'3px','width':'0%','cursor':'pointer','z-index':'10'},
	positionStyle: {'position':'absolute','left':'0%','width':'3px','height':'3px','background-color':'#000','z-index':'15'}
});

var player_go = new SoundPlayer({
	playlist:playlist_go,
	injectInto:"soundplayer_go",
	swfLocation:"../scripts/SoundPlayer.swf",
	controlImages:{previous:"images/previous.png",next:"images/next.png",play:"images/play.png",pause:"images/pause.png"},
	seekbarSpcStyle: {'position':'relative','background-color':'#666','height':'3px','width':'100%','margin-top':'4px','overflow':'hidden'},
	seekbarStyle: {'position':'absolute','background-color':'#fff','height':'3px','width':'0%','cursor':'pointer','z-index':'10'},
	positionStyle: {'position':'absolute','left':'0%','width':'3px','height':'3px','background-color':'#000','z-index':'15'}
});

var player_fm = new SoundPlayer({
	playlist:playlist_fm,
	injectInto:"soundplayer_fm",
	swfLocation:"../scripts/SoundPlayer.swf",
	controlImages:{previous:"images/previous.png",next:"images/next.png",play:"images/play.png",pause:"images/pause.png"},
	seekbarSpcStyle: {'position':'relative','background-color':'#666','height':'3px','width':'100%','margin-top':'4px','overflow':'hidden'},
	seekbarStyle: {'position':'absolute','background-color':'#fff','height':'3px','width':'0%','cursor':'pointer','z-index':'10'},
	positionStyle: {'position':'absolute','left':'0%','width':'3px','height':'3px','background-color':'#000','z-index':'15'}
});

function addTracklist(player,playerspc,playertracklistspc) {
	player.addEvent('ready', function() {
		$(playerspc).getElement('div.title').set('html','&nbsp;');
		
		var mainUl = new Element('ol',{'styles':{'padding':0,'margin':0,'padding':'0 0 0.75em 3em','background-color':'#000'}}).inject(this.controls);
		this.options.playlist.each(function(track,index) { 
			var tmpLi = new Element('li').inject(mainUl);
			var tmpSpan = new Element('span',{
				html:track.title+' &nbsp;•&nbsp; ',
				'styles':{'cursor':'pointer'},
				'events':{
					'click': function(){
						if (this.currentSound) {
							this.stopCurrentSound();
						}
			        	allSoundKeys = this.sounds.getKeys();
						sound = this.sounds.get(track.url);
						this.currentKey = allSoundKeys.indexOf(track.url);
						this.currentSound = sound;
						this.currentSound.sound.position = 0;
						this.playCurrentSound();
			        }.bind(this)
				}
			}).inject(tmpLi);
			
			var tmpA = new Element('a',{
				text:'mp3',
				href:track.url
			}).inject(tmpSpan);
					
		},this);
		mainUl.inject($(playertracklistspc));
	});
}

function addPauseOnPlay(player,otherplayer){
	player.addEvent('ready', function() {
		player.addEvent('play',function() {
			if (otherplayer.currentSound !== null) {
				otherplayer.stopCurrentSound();
			}
		});
	});
}

addTracklist(player_ffw,'soundplayer_ffw','soundplayer_ffw_playlist');
addTracklist(player_go,'soundplayer_go','soundplayer_go_playlist');
addTracklist(player_fm,'soundplayer_fm','soundplayer_fm_playlist');

addPauseOnPlay(player_fm,player_ffw);
addPauseOnPlay(player_fm,player_go);
addPauseOnPlay(player_go,player_ffw);
addPauseOnPlay(player_go,player_fm);
addPauseOnPlay(player_ffw,player_go);
addPauseOnPlay(player_ffw,player_fm);
