// JavaScript Document

var status = new Array();

function Listen(interval, playerName) {
	//interval = setInterval("doit('player1')", 1000);
}

function doit(p) {
	//Check player status
	
	//alert("isplaying " + $f(p).isPlaying());
	
	if($f(p).getState() != 3)
		$f(p).getPlugin("c1").show();
	else
		$f(p).getPlugin("c1").hide();
}

function ShowPlayer(playerName, playlist) 
{
	
	document.write("<a style=\"display:block;width:300px;height:325px;\" id=\"" +playerName+"\" ></a>"); 
	
	//flowplayer(playerName, "http://www.energypriorities.com/player/flowplayer-3.1.5.swf", {			 
	flowplayer(playerName, "http://energypriorities.com.previewdns.com/player/flowplayer-3.1.5.swf", {			 
		playlist: [      // show album cover
			 {url: 'graphs/bpb-album-art-flowplayer.jpg', scaling: 'orig'}, //,
					  // our MP3 does not start automatically
			 {url: 'podcasts/bim-minute.mp3', autoPlay: false}  ],
		clip: {
			autoPlay: true,
				// make something happen on first, fifth and last second     
			//onCuepoint: [[5000, 10000], function(clip, cuepoint) {         
				//alert("cuepoint entered");     
			//}]
			onBegin: function() {
				var c = $f(playerName).getClip().url;
				var ext = c.substring(c.length-4, c.length).toLowerCase();
				if(ext == ".mp3")
					$f(playerName).getPlugin("c1").hide();
			},
			onStart: function() {
				//alert($f(playerName).getClip().url + ": start");
				//$f(playerName).getPlugin("c1").hide();
			},
			onStop: function() {
				//alert($f(playerName).getClip().url + ": stop");
				//$f(playerName).getPlugin("c1").show();
			},
			onPause: function() {
				var c = $f(playerName).getClip().url;
				var ext = c.substring(c.length-4, c.length).toLowerCase();
				if(ext == ".mp3")
					$f(playerName).getPlugin("c1").show();
				//alert($f(playerName).getClip().url + ": Pause");
				//$f(playerName).getPlugin("c1").show();
			},
			onResume: function() {
				var c = $f(playerName).getClip().url;
				var ext = c.substring(c.length-4, c.length).toLowerCase();
				if(ext == ".mp3")
					$f(playerName).getPlugin("c1").hide();
				//alert($f(playerName).getClip().url + ": Resume");
				//$f(playerName).getPlugin("c1").show();
			}
		},
		plugins: {      
		   
			c1: {          
					 
				url: 'flowplayer.content-3.1.0.swf',          
				top: 185,         
				width: 250,
				height: 100,
				borderRadius: 10,         
				opacity:0.87,
				backgroundGradient:'high',
				backgroundImage: 'url(/player/spacer.gif)', 
				backgroundColor:'#ffffff',
				/*(Paul tried) stylesheet: 'http://p5works.com/active/flowplayer/test/player/player-content.css',  */        
				style: {             
					"p": {                 
						fontSize: 11,                 
						fontFamily: 'verdana,arial,helvetica',
						color: '#000000'
					 },
					 "a": {                 
						fontSize: 12, 
						fontWeight: 'bold',
						fontFamily: 'verdana,arial,helvetica',
						color: '#003366',
						textDecoration: 'none'
					 }
					 ,
					 "a:hover": {                 
						fontSize: 12,                 
						fontWeight: 'bold',
						fontFamily: 'verdana,arial,helvetica',
						color: '#003366',
						textDecoration: 'underline'
					 }
					 
				},        
				html: "<img src=\"hello-world.png\" align=\"left\" /><p class=\"title\">My title</p>"     
			 } 
		 },
			
		onLoad: function() {
			var html = $("#html_"+playerName).html();
			$f(playerName).getPlugin("c1").setHtml(html);
			if(playlist.length > 0) {
				$f(playerName).setPlaylist( playlist );
			}	
		},
				
		onMouseOver: function() {
			if($f(playerName).getState() == 3);
				$f(playerName).getPlugin("c1").show();
		},

		onMouseOut: function() {
			if($f(playerName).isPlaying())
				$f(playerName).getPlugin("c1").hide();
		},
		
		onPlaylistReplace: function() {
			found = false;
			for(i=0;i<playlist.length;i++) {
				c = $f(playerName).getClip(i);
				if(!found) {
					a = c.url.split(".");
					ext = a[a.length-1].toLowerCase(); 
					
					if(ext == "mp3") {
						c.update({autoPlay:false});
						found = true;
					}
				}
			}
		}
		
	}); 

}

