// <WebServiceGeneratedProxy Path="/Modules/MusicV2/Services/PopUpPlayer.asmx">
Type.registerNamespace('MySpace.Web.Modules.MusicV2.Services');
MySpace.Web.Modules.MusicV2.Services.PopUpPlayer=function() {
MySpace.Web.Modules.MusicV2.Services.PopUpPlayer.initializeBase(this);
this._timeout = 0;
this._userContext = null;
this._succeeded = null;
this._failed = null;
}
MySpace.Web.Modules.MusicV2.Services.PopUpPlayer.prototype={
GetMultipleArtistsUpdate:function(ArtistIds,succeededCallback, failedCallback, userContext) {
return this._invoke(MySpace.Web.Modules.MusicV2.Services.PopUpPlayer.get_path(), 'GetMultipleArtistsUpdate',false,{ArtistIds:ArtistIds},succeededCallback,failedCallback,userContext); },
GetArtistUpdate:function(ArtistId,succeededCallback, failedCallback, userContext) {
return this._invoke(MySpace.Web.Modules.MusicV2.Services.PopUpPlayer.get_path(), 'GetArtistUpdate',false,{ArtistId:ArtistId},succeededCallback,failedCallback,userContext); }}
MySpace.Web.Modules.MusicV2.Services.PopUpPlayer.registerClass('MySpace.Web.Modules.MusicV2.Services.PopUpPlayer',Sys.Net.WebServiceProxy);
MySpace.Web.Modules.MusicV2.Services.PopUpPlayer._staticInstance = new (MySpace.Web.Modules.MusicV2.Services.PopUpPlayer)();
MySpace.Web.Modules.MusicV2.Services.PopUpPlayer.set_path = function(value) { MySpace.Web.Modules.MusicV2.Services.PopUpPlayer._staticInstance._path =  _proxy_jslib_handle(null, 'value', value, 0, 0); }
MySpace.Web.Modules.MusicV2.Services.PopUpPlayer.get_path = function() { return MySpace.Web.Modules.MusicV2.Services.PopUpPlayer._staticInstance._path; }
MySpace.Web.Modules.MusicV2.Services.PopUpPlayer.set_timeout = function(value) { MySpace.Web.Modules.MusicV2.Services.PopUpPlayer._staticInstance._timeout =  _proxy_jslib_handle(null, 'value', value, 0, 0); }
MySpace.Web.Modules.MusicV2.Services.PopUpPlayer.get_timeout = function() { return MySpace.Web.Modules.MusicV2.Services.PopUpPlayer._staticInstance._timeout; }
MySpace.Web.Modules.MusicV2.Services.PopUpPlayer.set_defaultUserContext = function(value) { MySpace.Web.Modules.MusicV2.Services.PopUpPlayer._staticInstance._userContext =  _proxy_jslib_handle(null, 'value', value, 0, 0); }
MySpace.Web.Modules.MusicV2.Services.PopUpPlayer.get_defaultUserContext = function() { return MySpace.Web.Modules.MusicV2.Services.PopUpPlayer._staticInstance._userContext; }
MySpace.Web.Modules.MusicV2.Services.PopUpPlayer.set_defaultSucceededCallback = function(value) { MySpace.Web.Modules.MusicV2.Services.PopUpPlayer._staticInstance._succeeded =  _proxy_jslib_handle(null, 'value', value, 0, 0); }
MySpace.Web.Modules.MusicV2.Services.PopUpPlayer.get_defaultSucceededCallback = function() { return MySpace.Web.Modules.MusicV2.Services.PopUpPlayer._staticInstance._succeeded; }
MySpace.Web.Modules.MusicV2.Services.PopUpPlayer.set_defaultFailedCallback = function(value) { MySpace.Web.Modules.MusicV2.Services.PopUpPlayer._staticInstance._failed =  _proxy_jslib_handle(null, 'value', value, 0, 0); }
MySpace.Web.Modules.MusicV2.Services.PopUpPlayer.get_defaultFailedCallback = function() { return MySpace.Web.Modules.MusicV2.Services.PopUpPlayer._staticInstance._failed; }
MySpace.Web.Modules.MusicV2.Services.PopUpPlayer.set_path("/Modules/MusicV2/Services/PopUpPlayer.asmx");
MySpace.Web.Modules.MusicV2.Services.PopUpPlayer.GetMultipleArtistsUpdate= function(ArtistIds,onSuccess,onFailed,userContext) {MySpace.Web.Modules.MusicV2.Services.PopUpPlayer._staticInstance.GetMultipleArtistsUpdate(ArtistIds,onSuccess,onFailed,userContext); }
MySpace.Web.Modules.MusicV2.Services.PopUpPlayer.GetArtistUpdate= function(ArtistId,onSuccess,onFailed,userContext) {MySpace.Web.Modules.MusicV2.Services.PopUpPlayer._staticInstance.GetArtistUpdate(ArtistId,onSuccess,onFailed,userContext); }
// </WebServiceGeneratedProxy>


/// <summary>
/// MySpaceMusic Object definition
/// </summary>
function MySpaceMusic () {
	this.otherOnfocus = window.onfocus;
	this.otherOnblur = window.onblur;
	this.focusStatus;
}

/// <summary>
/// MySpaceMusic.WebSvrManager Object definition
/// </summary>
MySpaceMusic.WebSvrManager = {
    ArtistUpdateSuccess: function(result, eventArgs) {
		if (result != null) {
		     _proxy_jslib_assign('',  _proxy_jslib_handle(document, 'getElementById', '', 1, 0)('feedResult'), 'innerHTML', '=', ( result));
        }
    },
    OnFailure: function(msg) {
        print("Error MySpaceMusic.WebSvrManager: " + msg._message);
    }
}

window.onfocus = function (e) {
	if (MySpaceMusic.otherOnfocus) {
          MySpaceMusic.otherOnfocus(e);
    }
    MySpaceMusic.focusStatus = true;
} 
 
window.onblur = function (e) {
    if (MySpaceMusic.otherOnblur) {
          MySpaceMusic.otherOnblur(e);
    }
    MySpaceMusic.focusStatus = false;
}

/// ------------------------------callBacks-------------------------------

getElementPosition = function(element) {
    var left = 0;
    var top = 0;
    if (element) {
        while (element.offsetParent) {
            left += element.offsetLeft;
             top= _proxy_jslib_assign_rval('', 'top', '+=', ( element.offsetTop), top);
            element = element.offsetParent;
        }
        left += element.offsetLeft;
         top= _proxy_jslib_assign_rval('', 'top', '+=', ( element.offsetTop), top);
    }
    
    return { x: left, y:  _proxy_jslib_handle(null, 'top', top, 0, 0) };
}

MySpaceMusic.openTooltip = function (paramHeight, paramWidth) {
    var swfDiv =  _proxy_jslib_handle(document, 'getElementById', '', 1, 0)(MusicPlayerControl.SwfObjectDiv);
    var swfPos = getElementPosition(swfDiv);
    var iframeLeft = -paramWidth;
    var iframeTop = -swfDiv.offsetHeight;
    var pageHalfway = 300;
    if (swfPos.x < pageHalfway)
        iframeLeft = swfDiv.offsetWidth + 10;
    
    var cssText = '.tooltip div.corner,.tooltip div.top,.tooltip div.arrow,.tooltip div.origin_tl,.tooltip div.origin_tr,.tooltip div.origin_bl,.tooltip div.origin_br,.tooltip div.closeButton{background:none;position: absolute;}.tooltip{display:none;z-index: 100001;cursor: default;position: relative;top:0px;}.tooltip div.origin_tl,.tooltip div.origin_tr,.tooltip div.origin_bl,.tooltip div.origin_br{background-position: bottom right;}.tooltip div.corner,.tooltip div.top{top:-5px;}.tooltip div.corner{background:none;height:25px;width:5px;left:-5px;}.tooltip div.top{background: none;height:5px;width:100%;}.tooltip div.closeButton{background-position:-72px top;width:17px;height:16px;top:5px;right:10px;cursor:pointer;z-index: 100002;}.tooltip div.arrow{background: none;height:15px;width:15px;z-index: 100002;}.tooltip div.arrow_lt{margin: 0px 0px 0px 0px}.tooltip div.content {	width:' + paramWidth + 'px;height:' + paramHeight + ';background: none; position:relative;	padding: 0;}';
    addStyles( _proxy_jslib_handle(null, 'cssText', cssText, 0, 0));
     content= _proxy_jslib_assign_rval('', 'content', '=', ( "<iframe scrolling='no' style='position:absolute; top:" + iframeTop + "px; left:" + iframeLeft + "px' id='musicFlashPlayerContent' height='" + paramHeight + "' width='" + paramWidth + "' frameborder='0' src='" + MusicPlayerControl.TooltipUrl + "'></iframe>"), content);
    window.tip = $create(MySpace.UI.Tooltip, {content: _proxy_jslib_handle(null, 'content', content, 0, 0)},null,null,$get(MusicPlayerControl.SwfObjectDiv));
    window.tip.show();
     _proxy_jslib_handle(window, 'setTimeout', '', 1, 0)("MySpaceMusic.closeTooltip()", 25000)

}

MySpaceMusic.closeTooltip = function () {
    if (window.tip != undefined)
        window.tip.hide();
}

function addStyles(styles) {
    var styleSheet=null;
    if (document.createStyleSheet) {
        styleSheet=document.createStyleSheet();
    } else {
        var head= _proxy_jslib_handle(document, 'getElementsByTagName', '', 1, 0)("head")[0];
        styleSheet=document.createElement("style");
        head.appendChild(styleSheet);
    }

    if(Sys.Browser.agent === Sys.Browser.InternetExplorer){
         _proxy_jslib_assign('', styleSheet, 'cssText', '=', (styles));
    } else if (Sys.Browser.agent === Sys.Browser.Safari) {
        styleSheet.innerText=styles;
    } else {
         _proxy_jslib_assign('', styleSheet, 'innerHTML', '=', (styles));
    } 
}

function createPopUp(specificContent, popupW, popupH, invCloseBtn) {
	//Required parameter for $create function below
	var customizedTitle = ""; 
	//Contents of the popup
	var customizedContent = specificContent;
		
	//Create a <div> element with the following popup container inside of it
	var divObj = document.createElement("div");
	//divObj.innerHTML="<div id='divWrapper' class='popup_wrapper' style='z-index:1000001;left:0px;width:100%;position:fixed;display:none;visibility:hidden;text-align:center;padding:auto auto auto auto;'><div class='appspopup_box' style='width:" + popupW + "px; height:" + popupH + "px; margin-left: auto;margin-right: auto;border: 4px solid #6698CB;'>" + invCloseBtn + "<div class='appspopup_title'></div><div class='appspopup_content' style='margin:0 auto;'></div><div class='appspopup_buttons'></div></div></div>";
	 _proxy_jslib_assign('', divObj, 'innerHTML', '=', ("<div id='divWrapper' class='popup_wrapper' style='z-index:1000001;left:0px;width:100%;position:absolute;display:none;visibility:hidden;text-align:center;padding:auto auto auto auto;'><div class='appspopup_box' style='width:" + popupW + "px; height:" + popupH + "px; margin-left: auto;margin-right: auto;border: 4px solid #6698CB;'>" + invCloseBtn + "<div></div><div class='appspopup_content' style='margin:0 auto;'></div><div class='appspopup_buttons'></div></div></div>"));
	
	//Invoke PopUp code from global.js found in Flash Media Player control
	var popupObj = $create(MySpace.UI._Popup,{title:customizedTitle,content:customizedContent,left:0,top:50},null,null,divObj.firstChild);

	return popupObj;	
}  

MySpaceMusic.onFindRingtoneClicked = function(artistArr, currSong) {
	if(MusicPlayerControl.AllowJamba)
	{
		var jambaURL = "";
		var parameters = "";
		var aSong = [];			//Temp array holding a single song's data with formatting.
		var tempString;
		
		popupWidth = 604;
		popupHeight = 465;
			
		if (currSong == "" || artistArr == "")
		{
			jambaURL = MusicPlayerControl.JambaUrl1;
		}
		else
		{
			currSong =  _proxy_jslib_handle(currSong, 'replace', '', 1, 0)(/ /g, "+");
			currSong =  _proxy_jslib_handle(currSong, 'replace', '', 1, 0)(/'/g, "");
			aSong = currSong.split(":");
			parameters = aSong[0] + "," + aSong[1];
					
			for (var i = 1; i < artistArr.length; i++) //Discard first element because it's the current song
			{
				tempString =  _proxy_jslib_handle( _proxy_jslib_handle(artistArr, (i), 0, 0), 'replace', '', 1, 0)(/ /g, "+");
				tempString =  _proxy_jslib_handle(tempString, 'replace', '', 1, 0)(/'/g,"");
				aSong = tempString.split(":");
				aSong[0] =  _proxy_jslib_handle(aSong[0], 'replace', '', 1, 0)(/,/g, "+");
				parameters = parameters + "&arttitle=" + aSong[0] + "," + aSong[1]; 
			}
			jambaURL = MusicPlayerControl.JambaUrl2 + parameters;
		}
		
		//Content to display in the popup
		popupContent = "<iframe id='popupiframe' scrolling='no' style='border:0;overflow:hidden' src='" + jambaURL + "' width='" + popupWidth + "' height='" + popupHeight + "'></iframe>";
		//The popup code allows for a single element with class=pop_x to close the popup; here, we use invisible <p> elements placed over images of the content
		invCloseBtn = "<p class='popup_x' style='background:none; width:66px; height:25px; top:26px; margin:-27px 0 0 0; cursor:pointer; float:right; position:relative;'></p>";

		popup = createPopUp(popupContent,popupWidth,popupHeight,invCloseBtn);
		popup.show();
	}
}

MySpaceMusic.IsWindowFocused = function () {
    return this.focusStatus;
}

MySpaceMusic.AmazonInPlacePurchase = function(ASIN) {
	var amazonURL = MusicPlayerControl.AmazonPrice + "&asin=" + ASIN + "&mode=";
	var popupWidth = 626;
	var popupHeight = 426;
	
	if(navigator.userAgent.toLowerCase().indexOf("firefox/") >= 0)
	{
		popupWidth = 611;
		popupHeight = 366;
	}
	
	amazonURL += "windowed";
	var newWindow =  _proxy_jslib_handle(window, 'open', '', 1, 0)(amazonURL, 'Amazon', 'status=no, scrollbars=no, resizable=no, toolbar=no, location=no, directories=no, menubar=no, width=610, height=400');		
	newWindow.focus();
}

MySpaceMusic.AmazonNotInPlacePurchase = function(engine, artistName, itemName) {
	// engine is either "album" or "track"
	baseUrl = "http://www.amazon.com/s/ref=nb_ss_dmusic";
	engineUrl = "url=search-alias%3Ddigital-music-" + engine;
	artistField = escape("\"" + artistName + "\"");
	itemField = escape("\"" + itemName + "\"");
	fields = "field-keywords=" + artistField + "+" + itemField;
	
	fullUrl = baseUrl + "?" + engineUrl + "&" + fields;
	
	 _proxy_jslib_handle(window, 'open', '', 1, 0)(fullUrl);
}



MySpaceMusic.onBuyAlbumClicked = function(ASIN, albumId, artistName, albumName) {
	if(MusicPlayerControl.AllowAmazonInPlace && ASIN != undefined && ASIN != null && ASIN != "")
		MySpaceMusic.AmazonInPlacePurchase(ASIN);
	else
		MySpaceMusic.AmazonNotInPlacePurchase("album", artistName, albumName);
}

MySpaceMusic.onBuySongClicked = function(ASIN, songId, artistName, songName) {
	if(MusicPlayerControl.AllowAmazonInPlace && ASIN != undefined && ASIN != null && ASIN != "")
		MySpaceMusic.AmazonInPlacePurchase(ASIN);
	else
		MySpaceMusic.AmazonNotInPlacePurchase("track", artistName, songName);
}

var popup;

function ClosePopUp() {
	popup._hide();
	popupId =  _proxy_jslib_handle(document, 'getElementById', '', 1, 0)('divWrapper');
	 _proxy_jslib_handle(document, 'body', '', 0, 0).removeChild(popupId);
}

MySpaceMusic.OptIn = function(userId, playlistId, songId, artistId, songName, albumId) {
	
	popupWidth = 540;
	popupHeight = 550;
	
	popupContent = "<iframe id='popupiframe' scrolling='no' style='border:0;overflow:hidden' src='/modules/musicv2/pages/optindialog.aspx?userid=" + userId + "&songid=" + songId + "&playlistid=" + playlistId + "&artistid=" + artistId + "&songname=" + songName + "&albumid=" + albumId + "' width='" + popupWidth + "' height='" + popupHeight + "'></iframe>";
	invCloseBtn = "<a></a>";
	
	popup = createPopUp(popupContent,popupWidth,popupHeight,invCloseBtn);					
	popup.show();


}

function logoutAndClose() {
	checkbox =  _proxy_jslib_handle(document, 'getElementById', '', 1, 0)("logoutUserCheckBox");
	if (checkbox.checked)
	{
		var logoutFrame = document.createElement("iframe");
		logoutFrame.id = "amazonLogoutIFrame";
		 _proxy_jslib_assign('', logoutFrame, 'src', '=', ( MusicPlayerControl.AmazonLogoutFrameURL));
		logoutFrame.style.display = "none";
		logoutFrame.style.width = "1px";
		logoutFrame.style.height = "1px";
		 _proxy_jslib_handle(document, 'body', '', 0, 0).appendChild(logoutFrame);
		popup._hide();
	}
	else
	{
		popup._hide();
	}
	checkbox.checked = false;
}

MySpaceMusic.refreshMedRec = function() {
	MySpaceMusic.MedRecRefresh();
}

MySpaceMusic.MedRecRefresh = function() {
	if (MySpace.ClientContext.FunctionalContext == "PopUpPlayer")
        MedRecRefresh();
    if (MySpace.ClientContext.FunctionalContext == "UserViewProfile") 
    	MySpaceMusic.openTooltip(300, 310);
}

/// <summary>
/// onPlayingTrack callback
/// </summary>
MySpaceMusic.onPlayingTrack = function(songID, artistIDArray) {
    /// <param name="songID" type="Integer" mayBeNull="false"></param>
    /// <returns>none</returns>
    if (artistIDArray[0] > 0)
        MySpace.Web.Modules.MusicV2.Services.PopUpPlayer.GetMultipleArtistsUpdate(artistIDArray, MySpaceMusic.WebSvrManager.ArtistUpdateSuccess, MySpaceMusic.WebSvrManager.OnFailure);
    else
	     _proxy_jslib_assign('',  _proxy_jslib_handle(document, 'getElementById', '', 1, 0)('feedResult'), 'innerHTML', '=', ( '<br/><div class="activityFeedNoUpdate">' + MySpaceRes.PopUpPlayer.NoUpdatesForThisArtist + '</div>'));
}

MySpaceMusic.PlaySongInPOMP = function (songID, artistID, albumID, songName) {
    try{    
         _proxy_jslib_handle(document, 'getElementById', '', 1, 0)('shell').playSong(songID, artistID, albumID, songName);
    }
    catch (e){
    }
}
 ;
_proxy_jslib_flush_write_buffers() ;