var playlist_trees = [
	// object {url:string url, title:string title, artist: string artist]
	// or
	// string url
	{url:'http://throughthetrees.s3.amazonaws.com/stream/01Hero.mp3',title:'Hero',artist:'Family of the Year'},
	{url:'http://throughthetrees.s3.amazonaws.com/stream/02Chugjug.mp3',title:'Chugjug',artist:'Family of the Year'},
	{url:'http://throughthetrees.s3.amazonaws.com/stream/03TheBarn.mp3',title:'The Barn',artist:'Family of the Year'},
	{url:'http://throughthetrees.s3.amazonaws.com/stream/04ThePrincessThePea.mp3',title:'Princess & The Pea',artist:'Family of the Year'},
	{url:'http://throughthetrees.s3.amazonaws.com/stream/05Stairs.mp3',title:'Stairs',artist:'Family of the Year'}
];

var playlist_ep = [
	// object {url:string url, title:string title, artist: string artist]
	// or
	// string url
	{url:'http://wheresthesun.s3.amazonaws.com/128/01%20Lets%20Go%20Down.mp3',title:'Let’s Go Down',artist:'Family of the Year'},
	{url:'http://wheresthesun.s3.amazonaws.com/128/02%20Castoff.mp3',title:'Castoff',artist:'Family of the Year'},
	{url:'http://wheresthesun.s3.amazonaws.com/128/03%20Summer%20Girl.mp3',title:'Summer Girl',artist:'Family of the Year'},
	{url:'http://wheresthesun.s3.amazonaws.com/128/04%20Surprise.mp3',title:'Surprise',artist:'Family of the Year'},
	{url:'http://wheresthesun.s3.amazonaws.com/128/05%20Psyche%20Or%20Like%20Scope.mp3',title:'Psyche Or Like Scope',artist:'Family of the Year'}
];

var playlist = [
	// object {url:string url, title:string title, artist: string artist]
	// or
	// string url
	{url:'audio.php?w=0',title:'Feel Good Track Of Rosemead',artist:'Family of the Year'},
	{url:'audio.php?w=1',title:'Let\'s Be Honest',artist:'Family of the Year'},
	{url:'audio.php?w=2',title:'Treehouse',artist:'Family of the Year'},
	{url:'audio.php?w=3',title:'Putting Money And Stuff',artist:'Family of the Year'},
	{url:'audio.php?w=4',title:'Stupidland',artist:'Family of the Year'},
	{url:'audio.php?w=5',title:'Summer Girl',artist:'Family of the Year'},
	{url:'audio.php?w=6',title:'Surprise',artist:'Family of the Year'},
	{url:'audio.php?w=7',title:'No Good At Nothing',artist:'Family of the Year'},
	{url:'audio.php?w=8',title:'Charlie Song',artist:'Family of the Year'},
	{url:'audio.php?w=9',title:'Intervention (Staple Jeans)',artist:'Family of the Year'},
	{url:'audio.php?w=10',title:'I Played Drums On This',artist:'Family of the Year'},
	{url:'audio.php?w=11',title:'Castoff',artist:'Family of the Year'},
	{url:'audio.php?w=12',title:'Psyche Or Like Scope',artist:'Family of the Year'},
	{url:'audio.php?w=13',title:'Let\'s Go Down',artist:'Family of the Year'},
	{url:'audio.php?w=14',title:'Jamesy',artist:'Family of the Year'}
];

var player_ep = new SoundPlayer({
	playlist:playlist_ep,
	injectInto:"soundplayer_ep",
	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':'#f0c15a','height':'8px','width':'100%','margin-top':'4px','overflow':'hidden'},
	seekbarStyle: {'position':'absolute','background-color':'#d8660e','height':'8px','width':'0%','cursor':'pointer','z-index':'10'},
	positionStyle: {'position':'absolute','left':'0%','width':'3px','height':'8px','background-color':'#c55600','z-index':'15'}
});

var player_songbook = new SoundPlayer({
	playlist:playlist,
	injectInto:"soundplayer_songbook",
	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':'#f0c15a','height':'12px','width':'100%','margin-top':'4px','overflow':'hidden'},
	seekbarStyle: {'position':'absolute','background-color':'#d8660e','height':'12px','width':'0%','cursor':'pointer','z-index':'10'},
	positionStyle: {'position':'absolute','left':'0%','width':'3px','height':'12px','background-color':'#c55600','z-index':'15'}
});

player_songbook.addEvent('ready', function() {
	$('soundplayer_songbook').getElement('div.title').set('text','Press Play');
	
	showHidePlaylist = new Fx.Slide('soundplayer_songbook_playlist');
	showHidePlaylist.hide();
	
	var leftCol = new Element('div',{'styles':{'float':'left','width':'43%','padding-left':'1%','padding-bottom':'16px'}});
	var rightCol = new Element('div',{'styles':{'float':'right','width':'53%','padding-bottom':'16px'}});
	var leftUl = new Element('ol',{'styles':{'padding':0,'margin':0,'list-style-type':'decimal-leading-zero','line-height':'1.35em'}}).inject(leftCol);
	var rightUl = new Element('ol',{'styles':{'padding':0,'margin':0,'list-style-type':'decimal-leading-zero','line-height':'1.35em'}}).inject(rightCol);
	rightUl.start = 9;
	
	this.options.playlist.each(function(track,index) { 
		var tmpLi = new Element('li',{'styles':{'list-style-position':'inside'}});
		var tmpSpan = new Element('span',{
			html:track.title,
			'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);
		if (index < 8) {
			tmpLi.inject(leftUl);
		} else {
			tmpLi.inject(rightUl);
		}
	},this);
	leftCol.inject($('soundplayer_songbook_playlist'));
	rightCol.inject($('soundplayer_songbook_playlist'));
	
	var clearDiv = new Element('div',{'styles':{'clear':'both','height':'1px','overflow':'hidden','visibility':'hidden'}});
	clearDiv.set('text','.');
	clearDiv.inject($('soundplayer_songbook_playlist'));
	
	togglePlaylistLink =  new Element('a',{'styles':{'margin-right':'18px','position':'relative','top':'-6px','font-style':'italic'},text:'show/hide tracklist',href:'#',id:'tracklistToggle'});
	togglePlaylistLink.addEvent('click', function(e){
		e.stop();
		showHidePlaylist.toggle();
	});
	togglePlaylistLink.inject(this.controls,'top');
});






var player_trees = new SoundPlayer({
	playlist:playlist_trees,
	injectInto:"soundplayer_trees",
	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':'#f0c15a','height':'12px','width':'100%','margin-top':'4px','overflow':'hidden'},
	seekbarStyle: {'position':'absolute','background-color':'#d8660e','height':'12px','width':'0%','cursor':'pointer','z-index':'10'},
	positionStyle: {'position':'absolute','left':'0%','width':'3px','height':'12px','background-color':'#c55600','z-index':'15'}
});

player_trees.addEvent('ready', function() {
	$('soundplayer_trees').getElement('div.title').set('text','Press Play');
});






player_ep.addEvent('ready', function() {
	$('soundplayer_ep').getElement('div.title').set('text','Press Play');
});

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

addPauseOnPlay(player_ep,player_songbook);
addPauseOnPlay(player_ep,player_trees);
addPauseOnPlay(player_songbook,player_ep);
addPauseOnPlay(player_songbook,player_trees);
addPauseOnPlay(player_trees,player_songbook);
addPauseOnPlay(player_trees,player_ep);