var objPlayer;
if(window.parent.frames['dmh_player'] == undefined)
{
	objPlayer	=	window.parent.parent.frames['dmh_player'].document.getElementById("mPlayer");
	//objPlayer	=	window.parent.parent.frames['dmh_player'].document.mPlayer;
}
else
{
	objPlayer	=	window.parent.frames['dmh_player'].document.getElementById("mPlayer");
	//objPlayer	=	window.parent.frames['dmh_player'].document.mPlayer;
}

//alert(window.parent.frames['dmh_player']);

//var objPlayer	=	document.getElementById("mPlayer")
//alert(objPlayer.id);

var purchaseMode, puchaseModeId, upsell = false;
//------------------------------------------------------------------------------
function load(trackID, mode)
{
	tracks[trackID]['mode']	=	mode;
	var track = tracks[trackID];

	var objFlash		=	new Object();
	objFlash.id			=	track['id'];
	objFlash.name		=	track['name'];
	objFlash.path		=	track['path'];
	//objFlash.path		=	"rtmp://ajay/oflaDemo/output.mp3";
	objFlash.img		=	track['img'];
	objFlash.details	=	track['details'];
	objFlash.mode		=	track['mode'];

	//alert(objPlayer.id);
	/*
	for ( key in objPlayer )
	{
		alert ("key "+ key +": value "+ eval("objPlayer."+key));
	}
	*/
	objPlayer.smessage(objFlash);
}
//------------------------------------------------------------------------------
function loadPlayList(playlist_id, mode)
{
	if(playlist_id != "")
	{
		if( mode == undefined)
			var plURL		=	"/player/play-list/?act=load&playlist_id="+playlist_id;
		else
			var plURL		=	"/player/play-list/?act=loadGuestPlaylist&playlist_id="+playlist_id;

		var objFlash	=	new Object();
		objFlash.url	=	plURL;
		
		objPlayer.loadPlayList(objFlash);
	}
}
//------------------------------------------------------------------------------
function loadChart(chart_id)
{
	if(chart_id != "")
	{
		var chartURL	=	"/catalog/charts/load/"+chart_id+"/";
		
		var objFlash	=	new Object();
		objFlash.url	=	chartURL;
		
		objPlayer.loadPlayList(objFlash);
	}
}
//------------------------------------------------------------------------------
function loadAlbum(album_id, mode)
{
	if(album_id != "")
	{
		var albumURL	=	"/catalog/album/load/"+album_id+"/";
		
		var objFlash	=	new Object();
		objFlash.url	=	albumURL;
		objFlash.mode	=	mode;
		
		objPlayer.loadPlayList(objFlash);
	}
}
//------------------------------------------------------------------------------
function buyItem(id, what)
{
	if(id == "")
	{
		alert("Please select atleast one item");
		return false;
	}
	purchaseMode=	what;
	puchaseModeId	=	id;

	process		=	'addtocart';
	output		=	'text';
	url			=	getURL() + "/store/cart/";
	
	fields		=	new Array();
	id			=	encodeURI(id);
	itemType	=	encodeURI(what);
	act			=	encodeURI("add");
	responseHandler	=	"processBuyItemResponse";

	fields.push("id="+id);
	fields.push("itemType="+itemType);
	fields.push("act="+act);

	ajaxParams	=	fields.join('&');

	ajaxPostRequest(url, ajaxParams);
	return false;
}
//------------------------------------------------------------------------------
function processBuyItemResponse(responseText)
{
	ht	=	"150px";
	wd	=	"300px";
	if (responseText.length > 1500)
	{
		wd	=	"350px";
		ht	=	"280px";
	}

	if ( responseText.indexOf("successfully") == -1 )
	{
		if ( parent.content == undefined )
		{
			window.parent.parent.content.inlineWindow(responseText, "Add to Crate", "width="+wd+",height="+ht+",resize=0,scrolling=1,center=1");
		}
		else
		{
			parent.content.inlineWindow(responseText, "Add to Crate", "width="+wd+",height="+ht+",resize=0,scrolling=1,center=1");
		}
	}
	else
	{
		upsell = true;
	}
	refreshCartBox();
}
//------------------------------------------------------------------------------
function refreshCartBox()
{
	process		=	'cartSummary';
	output		=	'text';
	url			=	getURL() + "/store/cart/";
	
	fields		=	new Array();
	act			=	encodeURI("summary");
	responseHandler	=	"processCartBoxResponse";

	fields.push("act="+act);

	ajaxParams	=	fields.join('&');

	ajaxPostRequest(url, ajaxParams);
	return false;
}
//------------------------------------------------------------------------------
function processCartBoxResponse(responseText)
{
	if(parent.useraccount == undefined)
	{
		window.parent.parent.useraccount.document.getElementById("crateBox").innerHTML	=	responseText;	
	}
	else
	{
		window.parent.useraccount.document.getElementById("crateBox").innerHTML	=	responseText;	
	}
	if ( upsell )
	{
		//showUpsellBlock();
	}
}
//------------------------------------------------------------------------------
function showUpsellBlock(purchaseMode, puchaseModeId)
{
	process		=	'upsellItems';
	output		=	'text';
	url			=	getURL() + "/catalog/tracks/upsell/";
	
	fields		=	new Array();
	act			=	encodeURI("get");
	id			=	encodeURI(puchaseModeId);
	itemType	=	encodeURI(purchaseMode);

	responseHandler	=	"processUpsellResponse";

	fields.push("act="+act);
	fields.push("id="+id);
	fields.push("itemType="+itemType);

	ajaxParams	=	fields.join('&');

	ajaxPostRequest(url, ajaxParams);
	return false;
}
//------------------------------------------------------------------------------
function processUpsellResponse(responseText)
{
	obj = document.getElementById("upsell");
	if ( obj != null && obj != undefined )
	{
		obj.innerHTML	=	responseText;
	}
	//window.parent.parent.useraccount.document.getElementById("crateBox").innerHTML	=	responseText;	
}
//------------------------------------------------------------------------------
function addToChart(trackID)
{
	process		=	'addtochart';
	output		=	'text';
	url			=	getURL() + "/members/my-charts/";
	
	fields		=	new Array();
	trackID		=	encodeURI(trackID);
	act			=	encodeURI("addToChartCart");
	responseHandler	=	"processAddToChartResponse";

	fields.push("trackID="+trackID);
	fields.push("act="+act);

	ajaxParams	=	fields.join('&');

	ajaxPostRequest(url, ajaxParams);
	return false;
}
//------------------------------------------------------------------------------
function processAddToChartResponse(responseText)
{
	window.parent.parent.content.inlineWindow("<center>"+responseText+"</center>", "Add to DJ Playlist", "width=300px,height=150px,resize=0,scrolling=0,center=1");
	window.parent.preview_chart.location	=	window.parent.preview_chart.location;
}
//------------------------------------------------------------------------------
function emailUserPlaylist(playlist_id)
{
	process		=	'emailUPL';
	output		=	'text';
	url			=	getURL() + "/player/play-list/";
	
	fields		=	new Array();
	id			=	encodeURI(playlist_id);
	act			=	encodeURI("getTrackIDs");
	responseHandler	=	"processGetUPLresponse";

	fields.push("playlist_id="+id);
	fields.push("act="+act);

	ajaxParams	=	fields.join('&');

	ajaxPostRequest(url, ajaxParams);
	return false;
}
//------------------------------------------------------------------------------
function processGetUPLresponse(responseText)
{
	trackIDs	=	responseText;
	emailUPlTracks(trackIDs);
}
//------------------------------------------------------------------------------
function emailUPlTracks(trackIDs)
{
	parent.content.iFrameWindow("/player/play-list/?act=emailToFriends&done=false&trackIDs="+trackIDs, "E-mail playlist to Friend(s)", "width=500px,height=400px,resize=0,scrolling=0,center=1");
}
//------------------------------------------------------------------------------
function emailDjChart(chart_id)
{
	parent.content.iFrameWindow("/members/mail-objects/?act=emailToFriends&done=false&chart_id="+chart_id, "E-mail DJ Playlist to Friend(s)", "width=500px,height=400px,resize=0,scrolling=0,center=1");	
}
//------------------------------------------------------------------------------
function showTrack(track_id)
{
	process		=	'showTrack';
	output		=	'text';
	url			=	getURL() + "/catalog/tracks/short-view/"+track_id;
	
	responseHandler	=	"showTrackResponse";

	ajaxGetRequest(url);
	return false;
}
//------------------------------------------------------------------------------
function showTrackResponse(responseText)
{
	window.parent.parent.content.inlineWindow("<center>"+responseText+"</center>", "Track Details", "width=350px,height=150px,resize=0,scrolling=0,center=1");
}
//------------------------------------------------------------------------------
function addToFav(fav_ref_id, fav_mode)
{
	if(fav_ref_id == "" || fav_mode == "")
	{
		return false;
	}
	process		=	'addtofav';
	output		=	'text';
	url			=	getURL() + "/members/my-hub/";
	
	fields		=	new Array();
	fav_ref_id	=	encodeURI(fav_ref_id);
	fav_mode	=	encodeURI(fav_mode);
	act			=	encodeURI("add_fav");
	responseHandler	=	"processAddToFavResponse";

	fields.push("fav_ref_id="+fav_ref_id);
	fields.push("fav_mode="+fav_mode);
	fields.push("act="+act);

	ajaxParams	=	fields.join('&');

	ajaxPostRequest(url, ajaxParams);
	return false;
}
//------------------------------------------------------------------------------
function processAddToFavResponse(responseText)
{
	ht	=	"150px";
	wd	=	"300px";
	if (responseText.length > 1500)
	{
		wd	=	"350px";
		ht	=	"280px";
	}
	if ( parent.content == undefined )
	{
		window.parent.parent.content.inlineWindow(responseText, "Add to Favourites", "width="+wd+",height="+ht+",resize=0,scrolling=1,center=1");
	}
	else
	{
		parent.content.inlineWindow(responseText, "Add to Favourites", "width="+wd+",height="+ht+",resize=0,scrolling=1,center=1");
	}
}
//------------------------------------------------------------------------------
function removeFromFav(fav_ref_id, fav_mode)
{
	if(fav_ref_id == "" || fav_mode == "")
	{
		return false;
	}
	process		=	'removefromfav';
	output		=	'text';
	url			=	getURL() + "/members/my-hub/";
	
	fields		=	new Array();
	fav_ref_id	=	encodeURI(fav_ref_id);
	fav_mode	=	encodeURI(fav_mode);
	act			=	encodeURI("rem_fav");
	responseHandler	=	"processRemFromFavResponse";

	fields.push("fav_ref_id="+fav_ref_id);
	fields.push("fav_mode="+fav_mode);
	fields.push("act="+act);

	ajaxParams	=	fields.join('&');

	ajaxPostRequest(url, ajaxParams);
	return false;
}
//------------------------------------------------------------------------------
function processRemFromFavResponse(responseText)
{
	ht	=	"150px";
	wd	=	"300px";
	if (responseText.length > 1500)
	{
		wd	=	"350px";
		ht	=	"280px";
	}
	if ( parent.content == undefined )
	{
		window.parent.parent.content.inlineWindow(responseText, "Add to Favourites", "width="+wd+",height="+ht+",resize=0,scrolling=1,center=1");
	}
	else
	{
		parent.content.inlineWindow(responseText, "Add to Favourites", "width="+wd+",height="+ht+",resize=0,scrolling=1,center=1");
	}
}
//------------------------------------------------------------------------------
var tracks = new Array();