

/*
 * The Next Big Sound, Inc. - Artist Player
 *
 * Demo Player Required Scripts
 *
 * Player source: (http://www.jeroenwijering.com/?item=JW_FLV_Media_Player)
 * 
 */

// some variables to save
var currentPosition;
var currentRemaining;
var currentVolume;
var currentItem;
var currentState;
var currentLoad;
var currentXsize;
var currentYsize;
var total;
var currentID = new Array(2);
var widthOfPlayer = 520;
// Used in checking progress bar.  See below
var oldPlayed = 0;
var song_id;
var data_sent;
var artist_name = (document.title).replace('| The Next Big Sound', '');
var song_title;

<!--
// -----------------------------------------------------------------------------
// Globals
// Major version of Flash required
var requiredMajorVersion = 8;
// Minor version of Flash required
var requiredMinorVersion = 0;
// Minor version of Flash required
var requiredRevision = 0;
// -----------------------------------------------------------------------------
// -->

$(window).load(function() {

	return addthis_open('', '', '[URL]', '[TITLE]');

});

$(document).ready(function() {

	createPlayer();

	$(window).keydown(function(event)
	{
		switch (event.keyCode)
		{
			case 80:
				sendEvent('playpause');
			break;
			case 39:
				sendEvent('next');
			break;
			case 37:
				sendEvent('prev');
			break;
			case 38:
				sendEvent('volume',currentVolume + 5);
			break;
			case 40:
				sendEvent('volume',currentVolume - 5);
			break;
		}
	});
	
	
	$(".artistSongPlay").click(function() {
		sendEvent('playitem', $(this).get(0).id);
		
	});
	
	// swith signings for who signed
	
	$("#artistSignings").click(function() {
 
 		if(numSignings > 0)
 		{
			$("#numSign").fadeOut('medium', function() {
				$("#firstSignedBy").fadeIn('medium');
			});
		}
		

	});
	
	
	$("#flip").click(function() 
	{
		$("#firstSignedBy").fadeOut('medium', function() {
				$("#numSign").fadeIn('medium');
				//$("#who").fadeIn();
			});
		
		
		

	});
	
	$("#who").click(function() 
	{

		if(numSignings > 0)
 		{
			$("#numSign").fadeOut('medium', function() {
				$("#firstSignedBy").fadeIn('medium');
				//$("#who").hide();

			});
		}
		

	});
	

	$(".signedByHolder").mouseover(function() {
		$(this).css("background-color", "#eeeeee");
	});
	
	$(".signedByHolder").mouseout(function() {
		$(this).css("background-color", "#ffffff");
	});
	
	// Version check based upon the values entered above in "Globals"
	var hasReqestedVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);
	
	// Check to see if the version meets the requirements for playback
	if (hasReqestedVersion) {} 
	else {
		$(".artistSongHolder").hide();
		$("#flashdetect").show();
		
	}

});



// this function is caught by the JavascriptView object of the player.
function sendEvent(typ,prm) { 

	if(typ=='playitem')
		prm = parseInt(prm);
		
	if(prm==currentItem)
		typ = 'playpause';
	
	if(data_sent!=true && (typ == 'next' || typ == 'prev' || typ == 'playitem'))
	{
		var p_played;
		if (currentPosition ==0)
			p_played = 0
		else
			p_played = currentPosition/total;
		$.post("/song_stats", 
		{
			percentage_played: p_played, 
			seconds_played: currentPosition, 
			song_id: song_id,
			artist_id: demoID,
			played_from: 'artist'
		}
		);
		
		data_sent = true;
	}
	data_sent = false;

	thisMovie("playerID").sendEvent(typ,prm);
	
};


// these functions is called by the JavascriptView object of the player.
function getUpdate(typ,pr1,pr2,swf) { 
	if(typ == "time") { currentPosition = pr1; pr2 == undefined ? null: currentRemaining = Math.round(pr2); total = pr1+pr2;}
	else if(typ == "volume") { currentVolume = pr1; } 
	else if(typ == "item") { currentItem = pr1; setTimeout("getItemData(currentItem)",100);}
	else if(typ == "state") { currentState = pr1; }
	else if(typ == "load") { currentLoad = pr1; }
	else if(typ == "size") { currentXsize = "X=" + pr1; pr2 == undefined ? null: currentYsize = "Y=" + Math.round(pr2); } 
	
	var loaded = Math.round((currentLoad*widthOfPlayer)/100);			
	var played = Math.round((currentPosition*widthOfPlayer)/total);

	// if played is less than it was last udate, we stop it from updating
	if(played < oldPlayed && currentPosition > 1)
		played = oldPlayed;
	
	if(data_sent!=true && currentRemaining ==1)
	{
		var p_played;
		if (currentPosition ==0)
			p_played = 0
		else
			p_played = currentPosition/total;
		
		$.post("/song_stats", 
		{
			percentage_played: p_played, 
			seconds_played: currentPosition, 
			song_id: song_id,
			artist_id: demoID,
			played_from: 'artist'
		}
		);
		
		data_sent = true;
	}
	
	
	// set oldPlayed for next check
	oldPlayed = played;
	
	var totalSeconds = currentPosition;
	var min = Math.floor(totalSeconds/60);
	totalSeconds = totalSeconds % 60;
	if (totalSeconds < 10)
		totalSeconds = "0"+totalSeconds;
		
	var time = min+":"+totalSeconds;
	if (totalSeconds =="00" && min <1)
		var now = '&nbsp;';
	else
		var now = time+" / ";
		
	$(".artistSongProgress").css('width', '0px');
	
	
	
	if(!isIE6())
	{
		$("#load"+currentItem).css('width', '410px');
		
		$(".artistSongLoader").css({background: "none" });
		$(".artistTimeProgress").html('&nbsp;');

		//$("#load"+currentItem).css('width', loaded);

		$("#progress"+currentItem).css('width', played);

		for(var i=0; i<numSongs; i++)
		{
			if(i !=currentItem)
			{
				$("#"+i).removeClass("artistSongPause");
				$("#"+i).addClass("artistSongPlay");
			}
			else
			{
				$("#"+i).addClass("artistSongPause");
			}
		}
					$("#time"+currentItem).html(now);


		if(currentState == 2 || currentState == 1)
		{
				
			document.title = artist_name + " - " + song_title + " | The Next Big Sound";

			$("#"+currentItem).removeClass("artistSongPlay");
			$("#"+currentItem).addClass("artistSongPause");
			
			if(currentState ==1)
			{
				$("#load"+currentItem).css({
					background: "url(/images/ajax-loader.gif) no-repeat",
					backgroundPosition: "center right"
				});
			}
			$(".artistSongProgress").css('background-color', '#b5d6f2');
		}
		else if(currentState ==3 || currentState ==0)
		{	
			$("#"+currentItem).removeClass("artistSongPause");
			$("#"+currentItem).addClass("artistSongPlay");
			
			document.title = artist_name + " | The Next Big Sound";
		}
		else if(currentState ==0 && played>0)
		{
			$("#"+currentItem).removeClass("artistSongPause");
			$("#"+currentItem).addClass("artistSongPlay");
			
			document.title = artist_name + " | The Next Big Sound";
		}
	}
	else
	{
		$(".artistTimeProgress").html('&nbsp;');

		$("#time"+currentItem).html(now);
		$(".songPlay").css('background-image', 'url(/images/playArrowGray.gif)');
		$(".songTitle").css('color', '#a1a1a1');
		
		if(currentState == 2 || currentState == 1)
		{
			$("#"+currentItem).removeClass("artistSongPlay");
			$("#"+currentItem).addClass("artistSongPause");
			
			document.title = artist_name + " - " + song_title + " | The Next Big Sound";

		}
		else if(currentState ==3 || currentState ==0)
		{	
			$("#"+currentItem).removeClass("artistSongPause");
			$("#"+currentItem).addClass("artistSongPlay");
			
			document.title = artist_name + " | The Next Big Sound";
		}
		else if(currentState ==0 && played>0)
		{
			$("#"+currentItem).removeClass("artistSongPause");
			$("#"+currentItem).addClass("artistSongPlay");
			
			document.title = artist_name + " | The Next Big Sound";
		}
	}
	
	
	
	
};

function getItemData(idx) {
	var obj = thisMovie("playerID").itemData(idx);	
	
	song_id = obj['song_id'];
	
	artist_name = obj['artist'];
	song_title = obj['title'];

};

function isIE6()
{
	var browser = navigator.appName;
	var b_version = navigator.appVersion;
	var version = parseFloat(b_version);
	var findIE6 = b_version.search(/MSIE 6.0/);
	if(b_version.search(/MSIE 6.0/)>0)
		return true;
	else
		return false;
};

// These functions are caught by the feeder object of the player.
function loadFile(obj) { thisMovie("playerID").loadFile(obj); };

function addItem(obj,idx) { thisMovie("playerID").addItem(obj,idx); };

function removeItem(idx) { thisMovie("playerID").removeItem(idx); };

function getLength(swf) { return(thisMovie(swf).getLength()); };


// This is a javascript handler for the player and is always needed.
function thisMovie(movieName) {
	if(navigator.appName.indexOf("Microsoft") != -1) {
		return window[movieName];
	} else {
		return document[movieName];
	}
};


// This creates the player after the page has finished loading (onload).
function createPlayer() {
	var s1 = new SWFObject("/js/mediaplayer.swf","playerID","1","1","8");
	s1.addParam("allowfullscreen","true");
	s1.addParam("allowscriptaccess","always");

	s1.addVariable("file","/xml/playlist/"+demoID);
	//s1.addVariable("type", "mp3");
	s1.addVariable("shuffle","false");
	s1.addVariable("linktarget","_self");

	s1.addVariable("enablejs","true");
	s1.addVariable("javascriptid","playerID");

	s1.addVariable("width","1");
	s1.addVariable("height","1");
	s1.addVariable("displayheight","1");

	s1.write("placeholder");
};