 
	var opMap = new Array();
	opMap[0] = 'play_tracks';
	opMap[1] = 'play_album';
	opMap[2] = 'play_tracks';
	
    var PlayerObjectReference = null;
	var strPlaylistID = null;
	
	function PopupBlocker(){
		var blnReturnValue = false;
		checkForPlayer();
		if( PlayerObjectReference == null ){
			if( document.getElementById( 'PopupBlockedNoticeFloat' ) != null ){
				if( document.getElementById( 'disc_sort' ) != null )
					document.getElementById( 'disc_sort' ).style.display = 'none';
				if( document.getElementById( 'type' ) != null )
					document.getElementById( 'type' ).style.display = 'none';
				try{
					var intAvailableWidth = innerWidth;
				}
				catch(e){
					var intAvailableWidth = document.body.clientWidth;
				}
				document.getElementById( 'PopupBlockedNoticeFloat' ).style.display = 'block';
			}
			else{
				//document.getElementById( 'FlashMovie' ).style.display = 'none';
				var strPopupBlockerLAyers = '<div class="PopupBlockerWarningIcon"><img src="/images/icons/gfc_warning.gif" width="80" height="69" alt="" /></div>';
				strPopupBlockerLAyers += '<div class="PopupBlockerHeader"><img src="/images/headers/popup_blocker/hdr_popup_blocker.gif" width="288" height="23" alt="" /></div>';
				strPopupBlockerLAyers += '<div class="PopupBlockerText">We\'ve detected that you have a pop-up blocker active.</div>';
				strPopupBlockerLAyers += '<div class="PopupBlockerText2">To listen to your music</div>';
				strPopupBlockerLAyers += '<div class="PopupBlockerButton"><a href="javascript:OpenPopupPlayer()"><img src="/images/buttons/popup_blocker/btn_launch_free_player.gif" width="181" height="22" alt="" /></a></div>';
				strPopupBlockerLAyers += '<div class="PopupBlockerCancelLink"><a href="javascript:void(null)" onclick="CancelPopup()">Cancel Player</a></div>';
				strPopupBlockerLAyers += '<div class="PopupBlockerLink"><a href="javascript:void(null)" onclick="OpenPopupWindow( \'/info/info_popup_blocker.html\', \'PopupBlocker\', 365, 670, \'center\', \'center\' )">Click here</a> to learn how to add Napster to your  pop-up blocker\'s approved Web site list</div>';
				document.getElementById( 'PopupBlockedNotice' ).style.display = 'block';
				document.getElementById( 'PopupBlockedNotice' ).innerHTML = strPopupBlockerLAyers;
				objPlayerTimer = setTimeout( CloseWarning, 60000 );
			}
			blnReturnValue = true;
		}
		return blnReturnValue;
	}
	
	function PreparePlaylist( intPlaylistID ){
		var search_url = "/playlistPlayXML/" + intPlaylistID;
		strPlaylistID = intPlaylistID;
		var Playlist = new Ajax.Request(
			search_url, {
				method: 'get',
				paramters: '',
				onComplete: CreatePlaylistTracks
			}
		);
	}
	
	function CreatePlaylistTracks(){
		if( arguments[0] != null )
			objPlaylistXML = arguments[0].responseXML.documentElement;
		var objAjaxSubData = objPlaylistXML.getElementsByTagName( 'playlist' );
		strPlaylistIDs = objAjaxSubData[0].getAttribute( 'track_ids' );
		_Play( strPlaylistIDs, 2 );
	}
	
	function PlayPlaylist( intPlaylistID ){
		var objPlugin = document.getElementById( 'objNapsterPlugin' );
		try{
			$SCEG( 'Click', 's_eVar3="Play_Playlist_' + intPlaylistID + '_"' );
		}
		catch(e){}
		if( !$B.isNapCompatible || ( objPlugin == null || objPlugin.object == null ) || $C( 'SL' ) == 'LFM' ){
			_Play( intPlaylistID, 2 );
		}
		else if(!$C( 'CLID' )) {
			_Play( intPlaylistID, 2 );
		}
		else{
			PreparePlaylist( intPlaylistID )
		}
	}

	function _Play( strIds, intType ){
        // NOTE: all the functionality necessary for login-gated plays has been
        // left in place but commented out in case we need to go back to that
		if(typeof $SCData == 'undefined') {
			return;
		}
		var typeMap = new Array();
		typeMap[0] = 'track';
		typeMap[1] = 'album';
		typeMap[2] = 'playlist';
        /* first check to see if they're from the US */
        /*if( $C('COUNTRYCODE') == 'US' ) { */
            /* they're from the US, so... */
            /* check for login first */
       /*     if(!$C('CLID')) {
                var playURL = "http://www.napster.com/player/validate_play.html?play_id=" + strIds + "&type=" + typeMap[intType];
                /* var retURL = escape( playURL );
				if( $SCData( 'uac' ) != null && $SCData( 'uac' ) == 'nl' )
					$SCData( 'rs', 3 );
				else
					$SCData( 'rs', 1 );
				var intCompliance = Math.random();
				$SCData( 'ls', 1 );
				$SCEG( 'Sign-In/Registration', '' );
				if( !PopupBlocker() ){
                                
		            //check for player
		            if(PlayerObjectReference == null || (PlayerObjectReference.closed || !PlayerObjectReference.closed)) {
		                checkForPlayer();
		            }
	
					// are we sending them to login or reg
					var playerAction = (!($SCData('r')) || ($SCData('r') == '0')) ? 'registration' : 'login'; 
	
					PlayerObjectReference.window.location.href = "https://sms.napster.com/nweb/" + playerAction + "/player/?return_url=" + retURL; 
				}
                return;
            }
        } */
    /* comment this out since we're not supporting client plays anymore
var blnOpCodeSucess = false;
		if( $C( 'CLID' ) ){
			if( $C( 'SL' ) != 'LFM' && FWSupportedCountries[$C('COUNTRYCODE')] ){
				blnOpCodeSucess = $OC( "op=" + opMap[intType] + "%26ids%3d" + strIds, $C( 'CLID' ), null );
				if( blnOpCodeSucess )
					$C( 'PLAYDATA', '', true, null );
			}
		}
                */
        /* intType is either 0 for track or 1 for album */
		// if( !blnOpCodeSucess ){  /* this will be false if they're from an unsupported country */
			if( !PopupBlocker() ){
				if( strPlaylistID != null )
					var playerURL = "http://www.napster.com/player/?play_id=" + strPlaylistID + "&type=" + typeMap[intType];
				else
		            var playerURL = "http://www.napster.com/player/?play_id=" + strIds + "&type=" + typeMap[intType];
	            //check for player
	            if(PlayerObjectReference == null || (PlayerObjectReference.closed || !PlayerObjectReference.closed)) {
	                checkForPlayer();
	            }
// comment this all out cuz we're not requiring login anymore
/*			if( $C('COUNTRYCODE') == 'US' && !$C( 'CLID' ) ){ /* we only have to login for US 
				//see if they're eligible for free play
				if ($SCData( 'FPF' ) == 0 ) {
			                PlayerObjectReference.window.location.href = playerURL;
					return;
				}
				else {
	                var playURL = "http://www.napster.com/player/validate_play.html?play_id=" + strIds + "&type=" + typeMap[intType];
	                var retURL = escape( playURL );
					if( $SCData( 'uac' ) != null && $SCData( 'uac' ) == 'nl' )
						$SCData( 'rs', 3 );
					else
						$SCData( 'rs', 1 );
					var intCompliance = Math.random();
					$SCData( 'ls', 1 );
					$SCEG( 'Sign-In/Registration', '' );
					var playerAction = (!($SCData('r')) || ($SCData('r') == '0')) ? 'registration' : 'login'; 
					PlayerObjectReference.window.location.href = "https://sms.napster.com/nweb/" + playerAction + "/player/?return_url=" + retURL;
				}
				}
                                */
	        //    else if( PlayerObjectReference.window.location.href.indexOf( "player" ) < 0 ) {
	            if( PlayerObjectReference.window.location.href.indexOf( "player" ) < 0 ) {
	                PlayerObjectReference.window.location.href = playerURL;
	            }
	            else {
	                PlayerObjectReference.focus();
	                PlayerObjectReference.loadNewData( strIds,typeMap[intType] );
	            }
		}
		//}
    }

    function checkForPlayer(){
        PlayerObjectReference = window.open( "","PlayerWin","width=670,height=396,menubar=no,location=no,resizable=no,resizable=0,scrollbars=no,status=no" );
    }

    function PlayClip( strIds ) {
        var playerURL = "http://www.napster.com/player/?play_id=" + strIds + "&type=clip";
        //check for player
        if(PlayerObjectReference == null || (PlayerObjectReference.closed || !PlayerObjectReference.closed)) {
            checkForPlayer();
        }
        if (PlayerObjectReference.window.location.href.indexOf("player") < 0) {
            PlayerObjectReference.window.location.href = playerURL;
        }
        else {
            PlayerObjectReference.focus();
            PlayerObjectReference.loadNewData(strIds,typeMap[intType]);
        }
    }

var playJSloaded = 1;

    function sendMusic( strIds, type, strMediaName, strArtistName ) {
		var strMediaAndArtist = strMediaName + ( ( strArtistName != null )? ' by ' + strArtistName : '' );
		var strEmailMessage = 'mailto:?subject=Free Music From Napster&body=Listen to this great music from Napster! Click below to hear ' + strMediaAndArtist + ', and go to Napster.com to listen to millions of free tracks.%0A%0A';
		strEmailMessage += "http://www.napster.com/player/" + type + "/" + strIds;
		self.location.href = strEmailMessage;
    }
	
	function AddEvent( objElement, strEvent, funcAction ){
		try{
			objElement.attachEvent( 'on' + strEvent, function(){ eval( funcAction ) } );
		}
		catch(e){
			try{
				objElement.addEventListener( strEvent, function(){ eval( funcAction ) } , false );
			}
			catch(e){}
		}
	}
	
	function CloseMessage( strMessageLayerName ){
		document.getElementById( strMessageLayerName ).style.display = "none";
		return true;
	}
	
	var objPlayerTimer = null;

    function playNLink( plid,plt ){
		$SCData( 'uac', 'nl' );
		//objPlayInterval = setInterval( function(){
		//	if( playJSloaded ){
		//		clearInterval( objPlayInterval );
                Play( plid, plt );
		//	}
		//}, 25 );
    }
	
	function CloseWarning(){
		if( objPlayerTimer != null )
			clearTimeout( objPlayerTimer );
		if( document.getElementById( 'FlashMovie' ) != null ){
			document.getElementById( 'FlashMovie' ).style.display = 'block';
			document.getElementById( 'PopupBlockedNotice' ).style.display = 'none';
		}
		if( document.getElementById( 'PopupBlockedNoticeFloat' ) != null ){
			if( document.getElementById( 'disc_sort' ) != null )
				document.getElementById( 'disc_sort' ).style.display = 'inline';
			if( document.getElementById( 'type' ) != null )
				document.getElementById( 'type' ).style.display = 'inline';
			document.getElementById( 'PopupBlockedNoticeFloat' ).style.display = 'none';
		}
		return true;
	}
	
	function OpenPopupPlayer(){
		CloseWarning();
        //check if we have play data in the query else fallback to PLAYDATA cookie
        var plid = query.plid;
        var plt = query.plt;
        if( ( plid == null || plid == '' ) || ( plt == null || plt == '' ) ){
			if( $C( 'PLAYDATA' ) != null && $C( 'PLAYDATA' ) != '' ){
                var strLocation = unescape( $C( 'PLAYDATA' ) );
                queryPD = new Arguments( strLocation );
                plid = queryPD.plid;
                plt = queryPD.plt;
            }
            else {
                //TODO: handle case where we have no valid play data
            }
        }
		_Play( plid, plt );
	}
	
	function PlayFromFlash( strIds, intType ){
		if( strIds.split( ',' ).length > 1 && intType == 0 ){
			$SCEG( 'Click', 's_eVar3="Flash_Play_All_' + strIds + '"' );
		}
		else{
			if( intType == 0 )
				$SCEG( 'Click', 's_eVar3="Flash_Play_Track_' + strIds + '"' );
			else if( intType == 1 )
				$SCEG( 'Click', 's_eVar3="Flash_Play_Album_' + strIds + '"' );
		}
		var typeMap = new Array();
		typeMap[0] = 'track';
		typeMap[1] = 'album';
		typeMap[2] = 'playlist';
		
		var strQ = '?strIds=' + strIds + '&intType=' + intType + '&playfromhome=true';
        $C( 'PLAYDATA', strQ );
		
		if( intType < 2 ){
			$SCData( 'uac', 'nl' );
			var blnOpCodeSucess = false;
			if( $C( 'CLID' ) ){
				if( $C( 'SL' ) != 'LFM' && FWSupportedCountries[$C('COUNTRYCODE')] ){
					blnOpCodeSucess = $OC( "op=" + opMap[intType] + "%26ids%3d" + strIds, $C( 'CLID' ), null );
					if( blnOpCodeSucess )
						$C( 'PLAYDATA', '', true, null );
				}
			}
	        /* intType is either 0 for track or 1 for album */
			if( !blnOpCodeSucess ){ /* this will be false if they're from an unsupported country */
				checkForPlayer();
				if( !PopupBlocker() ){
					if( strPlaylistID != null )
						var playerURL = "http://www.napster.com/player/?play_id=" + strPlaylistID + "&type=" + typeMap[intType];
					else
			            var playerURL = "http://www.napster.com/player/?play_id=" + strIds + "&type=" + typeMap[intType];
		            //check for player
		            if(PlayerObjectReference == null || (PlayerObjectReference.closed || !PlayerObjectReference.closed)) {
		                checkForPlayer();
		            }
					if( $C('COUNTRYCODE') == 'US' && !$C( 'CLID' ) ){ /* we only have to login for US */
						//see if they're eligible for free play
						if ($SCData( 'FPF' ) == 0 ) {
				  	              PlayerObjectReference.window.location.href = playerURL;
							return;
						}
						else {
			                var playURL = "http://www.napster.com/player/validate_play.html?play_id=" + strIds + "&type=" + typeMap[intType];
			                var retURL = escape( playURL );
							if( $SCData( 'uac' ) != null && $SCData( 'uac' ) == 'nl' )
								$SCData( 'rs', 3 );
							else
								$SCData( 'rs', 1 );
							var intCompliance = Math.random();
							$SCData( 'ls', 1 );
							$SCEG( 'Sign-In/Registration', '' );
							var playerAction = (!($SCData('r')) || ($SCData('r') == '0')) ? 'registration' : 'login'; 
							PlayerObjectReference.window.location.href = "https://sms.napster.com/nweb/" + playerAction + "/player/?return_url=" + retURL;
						}
					}
		            else if( PlayerObjectReference.window.location.href.indexOf( "player" ) < 0 ) {
		                PlayerObjectReference.window.location.href = playerURL;
		            }
		            else {
		                PlayerObjectReference.focus();
		                PlayerObjectReference.loadNewData( strIds,typeMap[intType] );
		            }
				}
			}
		}
		else
			PlayPlaylist( strIds );
	}
	
	function Play( strIds, intType ){
		strIds = new String( strIds );
		intType = parseInt( intType );
		if( strIds.split( ',' ).length > 1 && intType == 0 ){
			$SCEG( 'Click', 's_eVar3="Play_All_' + $FILEPATH() + '"' );
		}
		else{
			if( intType == 0 )
				$SCEG( 'Click', 's_eVar3="Play_Track_' + strIds + '_' + $FILEPATH() + '"' );
			else if( intType == 1 )
				$SCEG( 'Click', 's_eVar3="Play_Album_' + strIds + '_' + $FILEPATH() + '"' );
		}
		_Play( strIds, intType );
	}
	
	function ClickFromFlash( strURL ){
		$SCEG( 'Click', 's_eVar3="Flash_URL_' + strURL + '"' );
		document.location.href = strURL;
	}
	
	function PlayFromHome( plid, plt ){
        var strQ = '?plid=' + plid + '&plt=' + plt + '&playfromhome=true';
        $C( 'PLAYDATA', strQ );
		if( plt < 2 )
			playNLink( plid, plt );
		else
			PlayPlaylist( plid );
	}
	
	function CancelPopup(){
		$C( 'PLAYDATA', '', true, null );
		CloseWarning();
	}

     if ( $C( 'PLAYDATA' ) != null && $C( 'PLAYDATA' ) != '' ) {
		if( $C( 'PLAYDATA' ).indexOf( 'elnk' ) == -1 && ( $C( 'ENUID' ) == null || $C( 'ENUID' ) == '' ) ){
			$C( 'PLAYDATA', '', true, null );
		}
	 	else{
        	var strLocation = unescape( $C( 'PLAYDATA' ) );
	        query = new Arguments( strLocation );
		}
    }
    //initiate play if you find attrs on the query string (return URL from login)
    if( query.plid && query.plt ){
		AddEvent( window, 'load', "playNLink( '" + query.plid + "', " + query.plt + " )" );
    }
	
	function DownloadTrack( strDownloadLink ){
		if( $C( 'COUNTRYCODE' ) != 'US' )
			document.location.href = '/subscribe/unsupported_country.html';
		else if( $C( 'CLID' ) == null || $C( 'CLID' ) == '' ){
			$SCData( 'ddlink', strDownloadLink );
			document.location.href = "https://sms.napster.com/nweb/login/?return_url=" + escape( location.href );
		}
		else{
			document.location.href = strDownloadLink;
			$SCData( 'ddlink', null );
		}
	}
	
	if( ( $C( 'PLAYDATA' ) != null && $C( 'PLAYDATA' ) != '' ) && ( query.mix_pl != null && query.mix_pl != '' ) )
		PreparePlaylist( query.mix_pl.replace( 'MIX_', '' ) );
		
	function StartDownloadDelayed(){
		if( ( $SCData( 'ddlink' ) != null && $SCData( 'ddlink' ) != '' ) && ( $C( 'CLID' ) != null && $C( 'CLID' ) != '' ) ){
			var strDownloadLink = unescape( $SCData( 'ddlink' ) );
			DownloadTrack( strDownloadLink );
		}
	} 
	
	AddEvent( window, 'load', 'StartDownloadDelayed()' );
