
var currentPlaylist = null;
var currentLength = 0;
var currentItem = -1; 
var previousItem = -1; 


var player = null;
function playerReady(thePlayer) {
	player = window.document[thePlayer.id];
	addListeners();
}

/* This function is used to add different listners to the player 
* Following are the list of listeners
* itemListener()
* muteListener()
* loadedListener()
* stateListener()
* positionListener()
* volumeListener()
* Go to the link for the live demo using all the above listener 
*
* http://home5.inet.tele.dk/nyboe/flash/mediaplayer4/JW_API_xmpl_6-2-0-0.html
*
*/
function addListeners() {
	if (player) { 
		player.addControllerListener("ITEM", "itemListener");		
	} else {
		setTimeout("addListeners()",100);
	}
}


function itemListener(obj) { 
	if (obj.index != currentItem) {
 		previousItem = currentItem;
		currentItem = obj.index;

		/* Custom code comes here */
		var txt = '';
		var plst = null;
  	    plst = player.getPlaylist();
		
		if (plst) {
			setCurrentTrackBeingPlayed('mainTrack'+plst[currentItem].author);
			highLightCurrentItem('sampleTracks');

			/*txt = plst[currentItem].title;
			var tmp = document.getElementById("mp3_player");
		    if (tmp) { tmp.innerHTML = txt; }*/
		}
		/* end of code */
	}
}

function getLength() { currentLength = player.getPlaylist().length; return(currentLength); };


function loadFile(theFile) { currentItem = -1; previousItem = -1; player.sendEvent('LOAD', theFile); };

function createPlayerForMVSection(theFile) 
{
	var flashvars = {
			file:theFile, 
			image:"http://www.max3.com/jwplayer/preview.jpg",
			skin:"http://www.max3.com/jwplayer/Snel.swf",
			playlist:"none",
			autostart:"false",
            abouttext:"max3",
			aboutlink:"http://www.max3.com"
	}
	var params = {
			allowfullscreen:"true", 
			allowscriptaccess:"always",
			wmode:"opaque"
	}
	var attributes = {
			id:"player1",  
			name:"player1"
	}
	swfobject.embedSWF("http://www.max3.com/jwplayer/player.swf", "placeholder1", "685", "30", "9.0.115", false, flashvars, params, attributes);
}

/* Function for admin player */
function createPlayerForMCSectionAdmin(theFile) 
{
	var flashvars = {
			file:theFile, 
			image:"http://www.max3.com/jwplayer/preview.jpg",
			playlist:"none",
			autostart:"false",
			abouttext:"max3",
			aboutlink:"http://www.max3.com"
	}
	var params = {
			allowfullscreen:"true", 
			allowscriptaccess:"always",
			wmode:"opaque"
	}
	var attributes = {
			id:"player1",  
			name:"player1"
	}
	swfobject.embedSWF("http://www.max3.com/jwplayer/player.swf", "placeholder1", "310", "20", "9.0.115", false, flashvars, params, attributes);
}

/* Function for what is max3 */
function tellMeMoreCreatePlayer(strDivId, theFile, theHeight, theWidht, theStart) 
{	
	var flashvars = {
			file:theFile, 
			autostart:theStart,
			abouttext:"max3",
			aboutlink:"http://www.max3.com"
	}
	var params = {
			allowfullscreen:"true", 
			allowscriptaccess:"always",
			wmode:"opaque"
	}
	var attributes = {
			id:"player1",  
			name:"player1"
	}
	swfobject.embedSWF("http://www.max3.com/jwplayer/player.swf", "placeholder1", theWidht, theHeight, "9.0.115", true, flashvars, params, attributes);
}

/* Function for homepage video */
function homePageCreatePlayer(strDivId, theFile, theHeight, theWidht, theStart) 
{	
	var requestFrom = document.domain;
	var flashvars = {
			file:theFile,
 		    skin:"http://"+requestFrom+"/images/max3_images/skins/hardRock/flash/PreviewerControls.swf",
			plugins:"http://"+requestFrom+"/images/max3_images/skins/hardRock/flash/trackTitle",
		    image : "http://"+requestFrom+"/images/homeimages_3.0/_3_ logo1.jpg",		
			autostart:theStart,
			abouttext:"max3",
			aboutlink:"http://www.max3.com"
	}
	var params = {
			allowfullscreen:"true", 
			bgcolor: 000000,
			wmode: "transparent",
			allowscriptaccess:"always"
		
	}
	var attributes = {
			id:"player1",  
			name:"player1"
	}
	swfobject.embedSWF("http://"+requestFrom+"/images/max3_images/skins/hardRock/flash/player.swf", "placeholder1", theWidht, theHeight, "9.0.115", true, flashvars, params, attributes);
	  
}

/* Function for library section */
function globalLibCreatePlayer(theFile) 
{
	document.getElementById('player1').innerHTML ="<div id='placeholder1'> </div>";  
	var flashvars = {
			file:theFile, 
			autostart:"true",
			abouttext:"max3",
			aboutlink:"http://www.max3.com"
	}
	var params = {
			allowfullscreen:"true", 
			allowscriptaccess:"always",
			wmode:"opaque"
	}
	var attributes = {
			id:"player1",  
			name:"player1"
	}
	swfobject.embedSWF("http://www.max3.com/jwplayer/player.swf", "placeholder1", "200", "20", "9.0.115", true, flashvars, params, attributes);
}


/**
* @desc Function getJwPlayerAdmin() - This function is used to instantiate jwPlayer in admin site for audio files
*/
function getJwPlayerAdmin(theFile)
{
	var embedCode = '';
	embedCode += '<embed src="/jwplayer/player.swf" width="250" height="20"';
	embedCode += 'type="application/x-shockwave-flash"';
	embedCode += 'pluginspage="http://www.macromedia.com/go/getflashplayer"';
	embedCode += 'bgcolor="#ffffff"';
	embedCode += 'allowscriptaccess="always"';
	embedCode += 'allowfullscreen="true"';
	embedCode += 'flashvars="file='+theFile;
	embedCode += '&image=/jwplayer/preview.jpg';
	embedCode += '&autostart=false';
	embedCode += '&abouttext=max3';
	embedCode += '&aboutlink=http://www.max3.com';
	embedCode += '&controlbar=bottom';
	embedCode += '&fullscreen=true"';
	embedCode += '&backcolor=000000"';
	embedCode += '&frontcolor=ffffff';
	embedCode += '></embed>';
	
	document.write(embedCode);
}
/* end of funtion getJwPlayerAdmin() */


/**
* @desc Function getJwPlayerVideoAdmin() - This function is used to instantiate jwPlayer in admin site for video files
* @access public
* @param string theFile, int theWidht, int theHeight
*/
function getJwPlayerVideoAdmin(theFile, theWidth, theHeight)
{
	var embedCode = '';
	embedCode += '<embed src="/jwplayer/player.swf" width="'+theWidth+'" height="'+theHeight+'"';
	embedCode += 'type="application/x-shockwave-flash"';
	embedCode += 'pluginspage="http://www.macromedia.com/go/getflashplayer"';
	embedCode += 'bgcolor="#ffffff"';
	embedCode += 'allowscriptaccess="always"';
	embedCode += 'allowfullscreen="true"';
	embedCode += 'flashvars="file='+theFile;
	embedCode += '&autostart=false';
	embedCode += '&abouttext=max3';
	embedCode += '&aboutlink=http://www.max3.com';
	embedCode += '&controlbar=over';
	embedCode += '&fullscreen=true"';
	embedCode += '&backcolor=000000"';
	embedCode += '&frontcolor=ffffff';
	embedCode += '></embed>';
	
	document.write(embedCode);
}
/* end of getJwPlayerVideoAdmin() function */

/**
* @desc Function getJwPlayerVideoMVSection() - This function is used to display jwPlayer in MV section for videos liks
* @access public
* @param string theFile, int theWidth, int theHeight
*/
function getJwPlayerVideoMVSection(theFile, theWidth, theHeight)
{
	var embedCode = '';
	embedCode += '<embed src="/jwplayer/player.swf" width="'+theWidth+'" height="'+theHeight+'"';
	embedCode += 'type="application/x-shockwave-flash"';
	embedCode += 'pluginspage="http://www.macromedia.com/go/getflashplayer"';
	embedCode += 'bgcolor="#ffffff"';
	embedCode += 'allowscriptaccess="always"';
	embedCode += 'allowfullscreen="true"';
	embedCode += 'flashvars="file='+theFile;
	embedCode += '&autostart=true';
	embedCode += '&abouttext=max3';
	embedCode += '&aboutlink=http://www.max3.com';
	embedCode += '&controlbar=over';
	embedCode += '&fullscreen=true"';
	embedCode += '&backcolor=000000"';
	embedCode += '&frontcolor=ffffff';
	embedCode += '></embed>';
	
	document.write(embedCode);
}


/* Function for what is max3 */
function getJwPlayerMVBrowse(theFile)
{
	var embedCode = '';
	embedCode += '<embed src="/jwplayer/player.swf" width="685" height="30"';
	embedCode += 'type="application/x-shockwave-flash"';
	embedCode += 'pluginspage="http://www.macromedia.com/go/getflashplayer"';
	embedCode += 'allowscriptaccess="always"';
	embedCode += 'allowfullscreen="true"';
	embedCode += 'flashvars="file='+theFile;
	embedCode += '&image=/jwplayer/preview.jpg';
	embedCode += '&skin=/jwplayer/Snel.swf';
	embedCode += '&abouttext=max3';
	embedCode += '&aboutlink=http://www.max3.com';
	embedCode += '&autostart=true"';
	embedCode += '></embed>';
	
	document.getElementById('mp3playerContainer').innerHTML = "<span id='mp3_player' ></span><div id='placeholder1'></div><div id='blank'></div>" + embedCode;
}

function getJwPlayerMVOverloadMusicAudio(theFile)
{
	swfobject.removeSWF('player1'); // deleting player

	document.getElementById('mp3playerContainer').innerHTML = "<span id='mp3_player' ></span><div id='placeholder1'></div>";
	createPlayerForMVSection(theFile);
}
