﻿$(function() {
		// install flowplayer into container 
		$f("player1", "/video/flowplayer-3.1.0.swf", { 

		// fullscreen button not needed here 
		plugins: { 
			audio: { 
					url: '/video/flowplayer.audio-3.1.0.swf'
			} ,
			controls: {
					fullscreen: false,
					playlist: false,
					all: true,
					stop: false,
					backgroundColor: '#CCCCCC', 
					backgroundGradient: 'none',
	        
					// display properties such as size, location and opacity 
					top: 0, 
					left: 0, 
					bottom: 0,  
					opacity: 1,
					height: 30,
					buttonColor: '#254659',
					timeColor: '#9AD9E0'	                
			} 
		}, 

		clip: { 
				autoPlay: false,
				// optional: when playback starts close the first audio playback 
				onBeforeBegin: function() { 
						$f("player").close(); 
				}
				
		}
	});

	$(".songinfo").click( function() { 
		clipLink = $(this).attr("href"); 
		clipTitle = $(this).attr("title");
		//Set the now playing song name
		var el = document.getElementById("music_info"); 
		el.innerHTML = "Now Playing: " + clipTitle;
	  
		if($(this).is('.songinfo_playing')) {
			//if this is currently paused resume
 			if($f().getState() == "4")
 				$f().resume();
			else if($f().getState() == "3") {
				//the audio is currently playing so pause
				$f().pause();
			}
		} else {
			$('div.clips> a').removeClass("songinfo_playing");
			$(this).toggleClass("songinfo_playing");
			
			//Play the video
			$f().play(clipLink); 
			
		}
		return false;                     
	}); //end click function handler 
	         
	$f().onBeforeClick(function() {  
		// ignore 2+ clicks, which happens if Flashblock is installed  
		if (this.alreadyCalledBeforeClick)  
			return false;  
		this.alreadyCalledBeforeClick = true;  
		return true;
	}); //end before click function handler
       
       //Set the first playlist element to play by default.
       $f().play($('div.clips').find('a:first').attr("href"));
       $('div.clips').find('a:first').toggleClass("songinfo_playing");     
       var el = document.getElementById("music_info"); 
			 el.innerHTML = "Now Playing: " + $('div.clips').find('a:first').attr("title");
});