function showOverlay(whichOverlay) {
	$(whichOverlay).setStyle('zIndex',500);
	$(whichOverlay).setStyle('visibility','visible');
	$(whichOverlay + 'bg').get('tween', {property:'opacity',duration:125}).start(0,0.85).chain(function(){
		$(whichOverlay + 'content').get('tween', {property:'opacity',duration:350}).start(0,1);
	});
}

function hideOverlay(whichOverlay) {
	$(whichOverlay + 'content').get('tween', {property:'opacity',duration:350}).start(1,0);
	$(whichOverlay + 'bg').get('tween', {property:'opacity',duration:125}).start(0.85,0).chain(function(){
		$(whichOverlay).setStyle('zIndex',20);
		$(whichOverlay).setStyle('visibility','hidden');
	});
}

function fixIe6Fixed(whichOverlay) {
	$(whichOverlay).setStyles({
		'position': 'absolute',
		'overflow': 'hidden',
		'top': window.getScroll().y+'px',
		'left': window.getScroll().x+'px',
		'width': '100%',
		'height': '100%'
	});
}

window.addEvent('domready', function(){
	
	if ($('showstreamover')) {
		$('showstreamover').addEvent('click', function(e){
			showOverlay('streamover');
			e.stop();
		});
		
		$('streamoverbg').addEvent('click', function(e){
			hideOverlay('streamover');
			e.stop();
		});
		
		$('closestream').addEvent('click', function(e){
			hideOverlay('streamover');
			e.stop();
		});
		
		if (Browser.Engine.trident4) {
			fixIe6Fixed('streamover');
			window.addEvent('scroll', fixIe6Fixed.bind(this,'streamover'));
		}
	}
	
//
//
//
//
//

	if ($('downloadform')) {
		$('downloadform').onsubmit = function(){
			var resultsfx = new Fx.Slide($('formresultspc001'));
			resultsfx.hide();
			new Request.HTML({url:'/scripts/fundraiser2009/tryemail.php',update: $('formresultspc001')}).post($('downloadform')).chain(function(){
				if ($('formresultspc001').get('text').substr(0,5) != "Sorry") {			
					var formfx = new Fx.Slide($('formspc001'));
					formfx.toggle().chain(function(){
						resultsfx.toggle();	
					});
				} else {
					resultsfx.toggle();	
				}
			});
			return false;
		}
	}
	
	$('downloadsubmit').addEvent('click', function(e) {
		$('downloadform').onsubmit();
		e.stop();	
	});
	
});

var playlist = [
	// object {url:string url, title:string title, artist: string artist]
	// or
	// string url
	{url:'http://s3.amazonaws.com/cash_users/cashmusic/thankyou/stream/01%20FacesOnFilm_FamousLastWords.mp3',title:'Famous Last Words',artist:'Faces On Film'},
	{url:'http://s3.amazonaws.com/cash_users/cashmusic/thankyou/stream/02%2050FOOTWAVE_Lavender.mp3',title:'Lavender',artist:'50FOOTWAVE'},
	{url:'http://s3.amazonaws.com/cash_users/cashmusic/thankyou/stream/03%20PortugalTheMan_DoYou.mp3',title:'Do You',artist:'Portugal. The Man'},
	{url:'http://s3.amazonaws.com/cash_users/cashmusic/thankyou/stream/04%20SydneyWayser_LaDiDa.mp3',title:'La Di Da',artist:'Sydney Wayser'},
	{url:'http://s3.amazonaws.com/cash_users/cashmusic/thankyou/stream/05%20TheFranks_NeonPolitik.mp3',title:'Neon Politik',artist:'The Franks'},
	{url:'http://s3.amazonaws.com/cash_users/cashmusic/thankyou/stream/06%20FormerGhosts_AndWhenYouKissMe.mp3',title:'And When You Kiss Me',artist:'Former Ghosts'},
	{url:'http://s3.amazonaws.com/cash_users/cashmusic/thankyou/stream/07%20FamilyOfTheYear_Bawitdaba.mp3',title:'Bawitdaba',artist:'Family Of The Year'},
	{url:'http://s3.amazonaws.com/cash_users/cashmusic/thankyou/stream/08%20EarlGreyhound_GhostAndTheWitness.mp3',title:'Ghost And The Witness',artist:'Earl Greyhound'},
	{url:'http://s3.amazonaws.com/cash_users/cashmusic/thankyou/stream/09%20MeanesManContest_SomePeople.mp3',title:'Some People [Touane Mix]',artist:'Meanest Man Contest'},
	{url:'http://s3.amazonaws.com/cash_users/cashmusic/thankyou/stream/10%20LearningMusic_FurthestCityLight.mp3',title:'Furthest City Light [vosotros Remix]',artist:'Learning Music'},
	{url:'http://s3.amazonaws.com/cash_users/cashmusic/thankyou/stream/11%20RENMINBI_Portland.mp3',title:'Portland [Demo]',artist:'RENMINBI'},
	{url:'http://s3.amazonaws.com/cash_users/cashmusic/thankyou/stream/12%20Lushlfe_GoodnightHotelInternacional.mp3',title:'Goodnight Hotel Internacional',artist:'Lushlife'}
];

var player = new SoundPlayer({
	playlist:playlist,
	swfLocation:"scripts/fundraiser2009/SoundPlayer.swf",
	loopPlaylist:false,
	controlImages:{previous:"images/fundraiser2009/previous.png",next:"images/fundraiser2009/next.png",play:"images/fundraiser2009/play.png",pause:"images/fundraiser2009/pause.png"},
	seekbarSpcStyle: {'display':'none'},
	seekbarStyle: {'display':'none'},
	positionStyle: {'display':'none'}
});

player.addEvent('ready', function() {
	$('soundplayerspc').getElement('div.title').setStyle('display','none');
	this.controls.setStyle('text-align','left');
	
	var leftCol = new Element('div',{'styles':{'float':'left','width':'43%','padding-left':'1%'}});
	var rightCol = new Element('div',{'styles':{'float':'right','width':'53%'}});
	var leftUl = new Element('ol',{'styles':{'padding':0,'margin':0,'list-style-type':'decimal-leading-zero','font-size':'0.85em'}}).inject(leftCol);
	var rightUl = new Element('ol',{'styles':{'padding':0,'margin':0,'list-style-type':'decimal-leading-zero','font-size':'0.85em'}}).inject(rightCol);
	rightUl.start = 7;
	
	this.options.playlist.each(function(track,index) { 
		var tmpLi = new Element('li',{'styles':{'list-style-position':'inside'}});
		var tmpSpan = new Element('span',{
			html:'<b>'+track.artist+':</b> '+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 < 6) {
			tmpLi.inject(leftUl);
		} else {
			tmpLi.inject(rightUl);
		}
	},this);
	leftCol.inject($('soundplayer_playlist'));
	rightCol.inject($('soundplayer_playlist'));
});

player.addEvent('play', function() {
	//currentTrack = player.currentKey;
	$('nowplayingspc').set('html','<b>'+this.currentSound.artist+':</b> '+this.currentSound.title);
});