//		baseDomain = top.location.href.indexOf('sms.napster') ? "http://sms.napster.com" : "http://home.gb.napster.com"; 
		baseDomain = "http://home.gb.napster.com"; 
		baseURL = "/";
		documentRoot = baseDomain + baseURL;
		query = '';
		var opcode = '';
		// documentRoot = "http://www.napster.co.uk/library/merge/";
		dojo.require("dojo.cookie");
		
function getFirstImage(childNodes) {
	for(var j=0; j<childNodes.length; j++){
		if(childNodes[j].nodeName.toLowerCase() == "img") {
			return childNodes[j];
		}
	}
	return null;
}

function makeDraggable() {
	draggableElements = dojo.query(".drag");
	for(var i=0; i<draggableElements.length; i++){
		draggableElements[i].parentNode.ondragstart = function() {
			dragNode = getFirstImage(this.childNodes);
			dataText = "drag" + "-" + dragNode.id.substring(0, 1) + "-" + dragNode.id.substring(1);
			// dataText = "drag" + "-" + this.childNodes[0].id.substring(0, 1) + "-" + this.childNodes[0].id.substring(1);
			event.dataTransfer.setData("Text", dataText);
			event.dataTransfer.effectAllowed = "copy";
			event.dataTransfer.dropEffect = "move";
		}
	}
	draggableElements = dojo.query(".dragLibrary");
	for(var i=0; i<draggableElements.length; i++){
		draggableElements[i].parentNode.ondragstart = function() {
			dragNode = getFirstImage(this.childNodes);
			dataText = "dragLibrary" + "-" + dragNode.id.substring(0, 1) + "-" + dragNode.id.substring(1);
			event.dataTransfer.setData("Text", dataText);
			event.dataTransfer.effectAllowed = "copy";
			event.dataTransfer.dropEffect = "move";
		}
	}
	draggableElements = dojo.query(".dragBoth");
	for(var i=0; i<draggableElements.length; i++){
		draggableElements[i].parentNode.ondragstart = function() {
			dragNode = getFirstImage(this.childNodes);
			dataText = "dragLibrary" + "-" + dragNode.id.substring(0, 1) + "-" + dragNode.id.substring(1);
			event.dataTransfer.setData("Text", dataText);
			event.dataTransfer.effectAllowed = "copy";
			event.dataTransfer.dropEffect = "move";
		}
	}
	draggableElements = dojo.query(".dragClient");
	for(var i=0; i<draggableElements.length; i++){
//		alert(i)
		draggableElements[i].parentNode.ondragstart = function() {
			dragNode = getFirstImage(this.childNodes);
			dataText = "dragLibrary" + "-" + dragNode.id.substring(0, 1) + "-" + dragNode.id.substring(1);
			event.dataTransfer.setData("Text", dataText);
			event.dataTransfer.effectAllowed = "copy";
			event.dataTransfer.dropEffect = "move";
		}
	}
}
		
		fixedLinkFromURL = function (inURL,justURL,sideBar) {
			var outLink = "";
			if(typeof(justURL) == "undefined") { justURL = 1; }
			if(inURL === undefined || inURL == "") { inURL = "#"; }
			urlPieces = inURL.split(documentRoot, 2);
				var actionStr = (urlPieces[1] ? ("/" + urlPieces[1]) : urlPieces[0]);
				PARSEURL: if(actionStr) {
					// check to see if our URL should be turned into an opcode
					// is it already an opcode?
					if(actionStr.indexOf("opcode.napster") > -1) {
						return inURL;
					}
					if(actionStr.indexOf("?") > -1) {
						opcodeParse = actionStr.split("?",2);
						if( typeof( objOpCodeMap[opcodeParse[0]] ) != 'undefined' ){
					        query = new Arguments(opcodeParse[1]);
							eval(objOpCodeMap[opcodeParse[0]]);
			                        href = "http://opcode.napster.com/?" + opcode;
							return href;
						}
					}
					if(actionStr.charAt(0) == "/") {
						href = baseDomain + actionStr;
						return href;
					}
					else {
						return inURL;
					}
				}
		}
		
		fixLinks = function (elementID) {
			makeDraggable();
			if(elementID) { 
				var links = elementID.getElementsByTagName("a");
			} else {
				var links = document.getElementsByTagName("a");
			}
			
			// dojo.debug("in fixLinks");
		    for(var i=0; i<links.length; i++) {
				var href = "";
				var targetDiv = "";
				
				try { href = links[i].getAttribute("href"); } catch(e) { dojo.debug("href error: " + e.message); }
				if(href == null) { continue; } // If the link has no href, skip it
				if(href.indexOf("javascript:") > -1) {
					urlPieces = new Array();
					urlPieces[0] = href;
				}
				else {
					urlPieces = href.split(documentRoot, 2)
				}
				var actionStr = (urlPieces[1] ? ("/" + urlPieces[1]) : urlPieces[0]);
				try { targetDiv = links[i].getAttribute("rel"); } catch(e) { }
				if(targetDiv) {
					if(targetDiv.indexOf("naps_") == 0) {
						switch(targetDiv.substr(5)) {
							case "current": targetDiv = 0; break
							default: targetDiv = targetDiv.substr(5);
						}
					} else {
						targetDiv = "";
					}
				}
				// dojo.debug("urlPieces: " + urlPieces);
				PARSEURL: if(actionStr) {
					// first check to see if our URL should be turned
					// into an opcode
					// is it already an opcode?
					if(actionStr.indexOf("opcode.napster") > -1) {
						break PARSEURL;
					}
					if(actionStr.indexOf("?") > -1) {
						opcodeParse = actionStr.split("?",2);
						if( typeof( objOpCodeMap[opcodeParse[0]] ) != 'undefined' ){
					        query = new Arguments(opcodeParse[1]);
							eval(objOpCodeMap[opcodeParse[0]]);
			                        href = "http://opcode.napster.com/?" + opcode; 
						break PARSEURL;
						}
					}
					if(actionStr.charAt(0) == "/") {
						href = baseDomain + actionStr;
					}
					else if(actionStr.indexOf("javascript:") > -1) {
						//we're trying to do this, leave it alone
						break PARSEURL;
					}
					else {
						if(actionStr.indexOf("://") >= 0) {
							href = href;
							if(!links[i].getAttribute("onclick")) { //if our link doesn't already have an onclick (set above or in the html)
								links[i].setAttribute("onclick", "var newWindow = window.open('" + links[i].getAttribute("href") + "'); return false;");
								links[i].setAttribute("href", "javascript:var newWindow = window.open('" + links[i].getAttribute("href") + "');");
							}
							//FIXME: below line throws an error
							//links[i].innerHTML = innerHTML;
							// dojo.debug("href2: " + href);
						} else {
							href = documentRoot + href;
							// dojo.debug("href!: " + href);
						}
					}
				}
				if(!links[i].getAttribute("onclick")) {
					if(href != documentRoot + "#") {
						// alert("HREF: " + href);
						// dojo.debug("href: " + href);
						// dojo.debug("documentRoot: " + documentRoot);
						//links[i].setAttribute("onclick", "navigate(\"" + href + "\"); return false;");
						//links[i].setAttribute("href", "javascript:navigate(\"" + href + "\")");
						var innerHTMLFix = links[i].innerHTML; // Fix for IE issue when innerHTML has an @ symbol
						if(targetDiv) {
							if(targetDiv == "close") {
								links[i].setAttribute("href", "http://opcode.napster.com/?op=close");
								links[i].setAttribute("onclick", "self.location.href='http://opcode.napster.com/?op=close'; return false;");
							}
						} else {
							links[i].setAttribute("href", href);
							links[i].setAttribute("onclick", "self.location.href='" + href + "'; return false;");
						}
						links[i].innerHTML = innerHTMLFix; // Fix for IE issue when innerHTML has an @ symbol
					}
				}
		    }
			
			//update site catalyst
			if(!elementID) { 
				try {
					runSCPageLoad();
				} catch(sc_e) {
					//alert(sc_e.message);
				}
				document.onclick = _enableDocumentClick;
			}
		}
		
		function _disableDocumentClick(ev) {
			return false;
		}
		
		function _enableDocumentClick(ev) {
			return true;
		}
		
		
	
		function _safeSendText(inText) {
			inText = inText.toString(); //convert our input text to a string
			var safeText = inText.replace(/'/g, "&rsquo;"); //escape all single quotes
			return safeText;
		}
		
		function getLinkAction(linkURL) {
			if(linkURL.substr(0,9) == "MyLibrary") {
				linkURLpieces = linkURL.substr(9).split('/');
				if(linkURL == "MyLibrary") { linkURLpieces[1] = "MyLibrary"; }
				switch(linkURLpieces[1]) {
					case "": linkActionReturn = "libraryDisplay.displayRecentTracks('1')"; break
					case "MyLibrary": linkActionReturn = "libraryDisplay.displayRecentTracks('1')"; break
					case "RecentlyPlayed": linkActionReturn = "libraryDisplay.displayRecentTracks('1')"; break
					case "RecentlyAdded": linkActionReturn = "libraryDisplay.displayAddedTracks('1')"; break
					case "AllTracks": linkActionReturn = "libraryDisplay.displayAllTracks('1')"; break
					case "Artist": linkActionReturn = "libraryDisplay.displayArtistTracks('" + linkURLpieces[2] + "','')"; break
					case "Playlist": linkActionReturn = "libraryDisplay.displayPlaylistTracks('" + linkURLpieces[2] + "','')"; break
					default: dojo.debug(linkURLpieces[1]); dojo.debug(linkURL); linkActionReturn = linkURL;
				}
			} else {
				linkActionReturn = linkURL;
			}
			return linkActionReturn;
		}
		
		function openInNewWindow(e) {
			var event;
			if (!e) event = window.event;
			else event = e;
			// Abort if a modifier key is pressed
			if (event.shiftKey || event.altKey || event.ctrlKey || event.metaKey) {
				return true;
			}
			else {
				// Change "_blank" to something like "newWindow" to load all links in the same new window
				var newWindow = window.open(this.getAttribute('href'), '_blank');
				if (newWindow) {
					if (newWindow.focus) {
						newWindow.focus();
					}
					return false;
				}
				return true;
			}
		}
		
		function navigate(url, isInitial) {
			if(!url) return;
			dojo.byId("breadcrumb_bar").innerHTML = "";
			dojo.byId("content_head").innerHTML = "";
			// dojo.byId("content_head").style.display = "none";
			dojo.byId("content_footer").innerHTML = "";
			// dojo.byId("content_footer").style.display = "none";
			dojo.byId("content_body").innerHTML = "Loading...";
			urlPieces = url.split(documentRoot, 2);
			
			buildUrl = "";
			linkAction = "";
			
			if(urlPieces[0] == "") {
				if(urlPieces[1].indexOf("MyLibrary") >= 0) {
					buildUrl = "";
					linkAction = getLinkAction(urlPieces[1]) ? getLinkAction(urlPieces[1]) : "";
				} else {
					buildUrl = documentRoot + urlPieces[1];
				}
			} else {
				// dojo.debug("urlPieces[0] != \"\"");
				if(url.indexOf("MyLibrary") >= 0) {
					buildUrl = "";
					linkAction = getLinkAction(url) ? getLinkAction(url) : "";
				} else {
					buildUrl = "/blank.html";
				}
			}
			if(buildUrl) {
				var bindArgs = {
					url:        buildUrl,
					//mimetype:   "text/plain",
					transport: "XMLHTTPTransport",
					error:      function(type, errObj){
						// handle error here
						dojo.debug("Bind Failed");
						var outln = "";
						dojo.debug("bind error: " + errObj);
						for(var i in errObj) {
							dojo.debug(i);
							outln += i + ' is ' + errObj[i] + "\n";
							var splitIt = errObj[i].split(": ");
							if (splitIt.length > 0) {
							var bob = (splitIt[1]);
							dojo.debug(splitIt);
							try{ 
								var junk = eval(bob);
							} catch(e) { 
								dojo.debug("here");
								dojo.debug(bob);
								dojo.debug(e.description);
								dojo.debug("not here anymore");
							}
								dojo.debug(junk);
							}
						}
						dojo.debug(outln);
					},
					load:      function(type, dataIn, evt, ioRequest){
						// handle successful response here
						data = dojo.dom.createDocumentFromText(dataIn, "text/xml");
							//dojo.debug(data.innerXML);
						// data = dojo.dom.createDocumentFromText(dataIn, "text/xml");
						// dojo.debug(data);
						ioRequest.appState = new ApplicationState(buildUrl);
								// try { document.insertBefore(dojo.byId("importStyles"), document.body.firstChild); } catch(e2) { dojo.debug("e2: " + e2.message); }
						try {
							var style_block = data.getElementById("importStyles").item(0);
							var breadcrumb_bar = data.getElementById("breadcrumb").item(0);
							fixLinks(breadcrumb_bar);
							var content_head = data.getElementById("head").item(0);
							fixLinks(content_head);
							var content_body = data.getElementById("main").item(0);
							fixLinks(content_body);
							var content_footer = data.getElementById("footer").item(0);
							fixLinks(content_footer);
							dojo.byId("importedStyles").innerHTML = dojo.dom.textContent(style_block);
							dojo.byId("breadcrumb_bar").innerHTML = dojo.dom.innerXML(breadcrumb_bar);
							dojo.byId("content_head").innerHTML = dojo.dom.innerXML(content_head);
							dojo.byId("content_footer").style.display = "block";
							dojo.byId("content_footer").innerHTML = dojo.dom.innerXML(content_footer);
							dojo.byId("content_body").innerHTML = dojo.dom.innerXML(content_body);
							initalizePageHeight();
						} catch(e) {
							importStylesElement = dojo.byId("importStyles");
							if(importStylesElement) { document.body.removeChild(importStylesElement); }
							
							dojo.byId("content_body").innerHTML = dataIn;
							fixLinks(dojo.byId("content_body"));
							try { 
								dojo.byId("importedStyles").innerHTML = dojo.byId("importStyles").innerHTML;
								// dojo.dom.copyChildren(dojo.byId("importStyles"), dojo.byId("importedStyles"));
							} catch(e1) {
									// var head = document.getElementsByTagName("head");
									var body = document.getElementsByTagName("body");
									// dojo.debug(head);
									var style = dojo.byId("importStyles");
									// dojo.debug(style);
								try {
									// dojo.byId("importStyles").innerHTML = dojo.byId("importStyles").innerHTML;
									body[0].appendChild(style);
								} catch(e3) {
									dojo.debug("e3: " + e3.message);
								}
							}
							dojo.byId("breadcrumb_bar").innerHTML = dojo.byId("breadCrumb").innerHTML;
							dojo.byId("content_head").innerHTML = dojo.byId("head").innerHTML;
							dojo.byId("content_footer").innerHTML = dojo.byId("footer").innerHTML;
							dojo.byId("content_footer").style.display = "block";
							dojo.byId("content_body").innerHTML = dojo.byId("main").innerHTML;
							fixLinks(dojo.byId("content_body"));
							initalizePageHeight();
						}
						initDrag();
					},
					back: function() {
						// dojo.debug("Back: " + this.appState);
						if(this.appState) this.appState.back();
					},
					forward: function() {
						// dojo.debug("Forward: " + this.appState);
						if(this.appState) this.appState.forward();
					},
					changeURL: urlPieces[1]
				};
				// dispatch the request
				var requestObj = dojo.xhrGet(bindArgs);
			} else {
				historyUrl = urlPieces[0] ? urlPieces[0] : urlPieces[1];
				// dojo.debug("historyUrl: " + historyUrl);
				appState = new ApplicationState(historyUrl);
				dojo.undo.browser.addToHistory(appState);
				eval(linkAction);
				initalizePageHeight();
			}
		}

		function fixMainContentArea() {
			if(dojo.isIE) { // a proprietary solution to a proprietary issue with missing content
				// dojo.byId("main").style.zoom = ".99";
				// dojo.byId("main").style.zoom = "1";
				
				// document.body.style.zoom = ".99";
				// document.body.style.zoom = "1";
				
				var elems = dojo.query(".zoomFix");
				
                for( i = 0; i < elems.length; i++ ){
					elems[i].style.zoom = ".99";
					elems[i].style.zoom = "1";
				}
			}
		}
		
		dojo.addOnLoad( fixLinks );
		/* dojo.addOnLoad(function(){
			//wait until we have an initialized library before doing anything
			var objInterval = setInterval( function(){
				if(initialized){
					clearInterval( objInterval );
					//See if there is a bookmark hash on the page URL.
					var bookmarkId = location.hash;
					if(bookmarkId){
						bookmarkId = bookmarkId.substring(1, bookmarkId.length);
					}

					//If we have a bookmark, load that as the initial state.
					if(bookmarkId){
						buildUrl = documentRoot + bookmarkId;
						// alert("have a bookmark");
						dojo.undo.browser.setInitialState("Initial State:" + bookmarkId);
						var appState = new ApplicationState(documentRoot);
						dojo.undo.browser.setInitialState(appState);
						navigate(buildUrl, true);
					}else{
						// var appState = new ApplicationState("This is the initial state (page first loaded, no dojo.io.bind() calls yet)", "output", "dataOutput");
						// appState.showStateData();
						// dojo.undo.browser.setInitialState(appState);
						dojo.undo.browser.setInitialState("Initial State: blank");
						var appState = new ApplicationState(documentRoot + "blank.html");
						navigate(documentRoot + "blank.html", true);
						dojo.undo.browser.setInitialState(appState);
					}
				}
			}, 50 );
		});
	*/

	function Arguments(strQuery){
                var objScriptRegExp = new RegExp( '[\\\<\\\%3ca]+script', 'gi' );
                var objNewLineRegExp = new RegExp( '[\\\n\\\r]+', 'gi' );
                strQuery = strQuery.replace( objScriptRegExp, '' );
                strQuery = strQuery.replace( objNewLineRegExp, '' );
                if( arguments[0] != null && arguments[0] != '' )
                        strQuery += ( ( strQuery == '' && strQuery.indexOf( 'plid' ) == -1 )? '' : '&' ) + arguments[0].substring(1);
                var aryArgumentPairs = strQuery.split( '&' );
                for( intArgumentIndex = 0; intArgumentIndex < aryArgumentPairs.length; intArgumentIndex++ ){
                        var intPosition = aryArgumentPairs[intArgumentIndex].indexOf('=');
                        if( intPosition == -1 ) continue;
                        var strArgumentName = aryArgumentPairs[intArgumentIndex].substring( 0, intPosition );
                        var strArgumentValue = aryArgumentPairs[intArgumentIndex].substring( intPosition + 1 );
                        eval( 'this.' + strArgumentName + ' = "' + decodeURI( strArgumentValue ).replace(/\\|\"/g, "\\\\") + '"' )
                }
        }



	var objOpCodeMap = new Object();
		/* NOTE: the client can't parse the &amp; and is expecting a simple '&' in the opcode URL
        objOpCodeMap['/ns/view/artist/index.html'] = 'opcode = "op=switch&amp;tab=home&amp;type_id=content&amp;url=http://home.gb.napster.com/ns/view/artist/index.html?artist_id=" + query.artist_id;';  
        objOpCodeMap['/ns/view/artist/'] = 'opcode = "op=switch&amp;tab=home&amp;type_id=content&amp;url=http://home.gb.napster.com/ns/view/artist/index.html?artist_id=" + query.artist_id;';  
        objOpCodeMap['/ns/view/artist/bio.html'] = 'opcode = "op=switch&amp;tab=home&amp;type_id=content&amp;url=http://home.gb.napster.com/ns/view/artist/bio.html?artist_id=" + query.artist_id + "&source=" + query.source;';   
        objOpCodeMap['/ns/view/album/review.html'] = 'opcode = "op=switch&amp;tab=home&amp;type_id=content&amp;url=http://home.gb.napster.com/ns/view/album/review.html?album_id=" + query.album_id;';  
        objOpCodeMap['/cgi-bin/featuresXML'] = 'opcode = "op=switch&amp;tab=browse&amp;type_id=" + query.type_id  + "&amp;result_type=album" + (query.select_by ? "&amp;select_by=" + query.select_by + "&amp;select_value=" + query.select_value : "") + (query.filter_by ? "&amp;filter_by=" + query.filter_by + "&amp;filter_value=" + query.filter_value : "") + "&amp;COUNTRYCODE=" + query.COUNTRYCODE;';
        objOpCodeMap['/cgi-bin/searchXML'] = 'opcode = (query.search_string ? "op=search&amp;type=" + query.type + "&amp;search_string=" + query.search_string : "op=switch&amp;tab=browse&amp;type_id=" + query.type_id + "&amp;result_type=" + query.result_type + "&amp;select_by=" + query.select_by + "&amp;select_value=" + query.select_value + (query.filter_by ? "&amp;filter_by=" + query.filter_by + "&amp;filter_value=" + query.filter_value : "") + (query.sort ? "&amp;sort=" + query.sort : "") + (query.count ? "&amp;count=" + query.count : "") + (query.source ? "&amp;source=" + query.source : ""));'; 
        objOpCodeMap['/cgi-bin/playlistXML'] = 'opcode = "op=switch&amp;tab=browse&amp;type_id=" + query.type_id + "&amp;result_type=" + query.result_type + "&amp;select_by=" + query.select_by + "&amp;select_value=" + query.select_value + (query.filter_by ? "&amp;filter_by=" + query.filter_by + "&amp;filter_value=" + query.filter_value : "") + "&amp;COUNTRYCODE=" + query.COUNTRYCODE;';
		*/
        objOpCodeMap['/ns/view/artist/index.html'] = 'opcode = "op=switch&tab=home&type_id=content&url=http://home.gb.napster.com/ns/view/artist/index.html?artist_id=" + query.artist_id;';  
        objOpCodeMap['/ns/view/artist/'] = 'opcode = "op=switch&tab=home&type_id=content&url=http://home.gb.napster.com/ns/view/artist/index.html?artist_id=" + query.artist_id;';  
        objOpCodeMap['/ns/view/artist/bio.html'] = 'opcode = "op=switch&tab=home&type_id=content&url=http://home.gb.napster.com/ns/view/artist/bio.html?artist_id=" + query.artist_id + "&source=" + query.source;';
        objOpCodeMap['/ns/view/album/review.html'] = 'opcode = "op=switch&tab=home&type_id=content&url=http://home.gb.napster.com/ns/view/album/review.html?album_id=" + query.album_id;';  
        objOpCodeMap['/ns/videos/index.html'] = 'opcode = "op=switch&tab=home&type_id=content&url=http://home.gb.napster.com/ns/videos/index.html";';  
        objOpCodeMap['/ns/videos/'] = 'opcode = "op=switch&tab=home&type_id=content&url=http://home.gb.napster.com/ns/videos/index.html";';  
        objOpCodeMap['/cgi-bin/featuresXML'] = 'opcode = "op=switch&tab=browse&type_id=" + query.type_id  + "&result_type=album" + (query.select_by ? "&select_by=" + query.select_by + "&select_value=" + query.select_value : "") + (query.filter_by ? "&filter_by=" + query.filter_by + "&filter_value=" + query.filter_value : "") + "&COUNTRYCODE=" + query.COUNTRYCODE;';
        objOpCodeMap['/cgi-bin/searchXML'] = 'opcode = (query.search_string ? "op=search&type=" + query.type + "&search_string=" + query.search_string + (query.filter_by ? "&filter_by=" + query.filter_by : "") : "op=switch&tab=browse&type_id=" + query.type_id + "&result_type=" + query.result_type + "&select_by=" + query.select_by + "&select_value=" + query.select_value + (query.filter_by ? "&filter_by=" + query.filter_by + "&filter_value=" + query.filter_value : "") + (query.sort ? "&sort=" + query.sort : "") + (query.count ? "&count=" + query.count : "") + (query.source ? "&source=" + query.source : ""));';
        objOpCodeMap['/cgi-bin/playlistXML'] = 'opcode = "op=switch&tab=browse&type_id=" + query.type_id + "&result_type=" + query.result_type + "&select_by=" + query.select_by + "&select_value=" + query.select_value + (query.filter_by ? "&filter_by=" + query.filter_by + "&filter_value=" + query.filter_value : "") + (query.source ? "&source=" + query.source : "") + "&COUNTRYCODE=" + query.COUNTRYCODE;';
		objOpCodeMap['/cgi-bin/radioXML'] = 'opcode = "op=switch&tab=browse&type_id=" + query.type_id + "&result_type=" + query.result_type + "&select_by=" + query.select_by + "&select_value=" + query.select_value + (query.filter_by ? "&filter_by=" + query.filter_by + "&filter_value=" + query.filter_value : "") + "&COUNTRYCODE=" + query.COUNTRYCODE;';
		objOpCodeMap['/cgi-bin/memberXML'] = 'opcode = "op=switch&tab=browsemembers&type_id=" + query.type_id + "&result_type=" + query.result_type + "&select_by=all&select_value=all&filter_by=member&filter_value=" + query.filter_value;';

	function Play( strIds, intType, automix, source ){
		strIds = new String( strIds );
		intType = parseInt( intType );
		var PlayOpCodes = new Array();
		var sourceString = "";
		// var opPre = "top.location.href = ";
		var opPre = "window.external.executeOpcode(";
		var opPost = ")";
		PlayOpCodes[0] = opPre + '"http://opcode.napster.com/?op=play_tracks&skip_tsc=0&ids=" + strIds' + opPost;
		PlayOpCodes[1] = opPre + '"http://opcode.napster.com/?op=play_album&skip_tsc=0&ids=" + strIds' + opPost;
		PlayOpCodes[2] = opPre + '"http://opcode.napster.com/?op=play&type_id=playlist&skip_tsc=0&ids=" + strIds' + opPost;
		PlayOpCodes[5] = opPre + '"http://opcode.napster.com/?op=play_radio&skip_tsc=0&ids=" + strIds' + opPost;
		PlayOpCodes[6] = opPre + '"http://opcode.napster.com/?op=play_automix&skip_tsc=0&type=" + AutoMixType + "&ids=" + strIds + sourceString' + opPost;
		PlayOpCodes[7] = opPre + '"http://opcode.napster.com/?op=play_work&skip_tsc=0&ids=" + strIds' + opPost;
		var AutoMixTypes = new Array();
		AutoMixTypes[0] = "T"; //based on track
		AutoMixTypes[1] = "L"; // based on album
		AutoMixTypes[2] = "P"; // based on Napster-programmed playlist
		AutoMixTypes[4] = "A"; // based on artist
		var AutoMixSC = new Array();
		AutoMixSC[0] = "Track"; //based on track
		AutoMixSC[1] = "Album"; // based on album
		AutoMixSC[2] = "Playlist"; // based on Napster-programmed playlist
		AutoMixSC[4] = "Artist"; // based on artist
		if(automix) {
			AutoMixType = AutoMixTypes[intType];
			AutoMixSCTag= AutoMixSC[intType];
			sourceString = "&source" + source;
			// override the intType to pull the automix opcode
			intType = 6;
		}
	// leave this here so we can do the SC tracking
		// this can be hard coded for now - can only track plays from a button (no right click)
		// and can't see drags to player
		var scPlayVarsStr = 's.eVar1="Play"; s.eVar2="Button";s.eVar3=s.pageName;'; 
		if( strIds.split( ',' ).length > 1 && intType == 0 ){
			scPlayVarsStr += 's.eVar5="MultipleTracks";';
		}
		else{
			if( intType == 0 ) {
				scPlayVarsStr += 's.eVar5="Track";';
			}
			else if( intType == 1 ) {
				scPlayVarsStr += 's.eVar5="Album";';
			}
			else if( intType == 2 ) {
				scPlayVarsStr += 's.eVar5="Playlist";';
			}
			else if( intType == 5 ) {
				scPlayVarsStr += 's.eVar5="Radio";';
			}
			else if( intType == 6) {
				scPlayVarsStr += 's.eVar5="' + AutoMixSCTag + '";';
			}
		}
		$SCEG( 'ContentAction',scPlayVarsStr);
//		alert(PlayOpCodes[intType]);
		eval(PlayOpCodes[intType]);
	
	}
		
	function playAllListReturnTracks() {
		top.location.href = "http://opcode.napster.com/?op=play&type_id=contentlist";
	}

	function Queue( strIds, intType ) {
		strIds = new String( strIds );
		intType = parseInt( intType );
		var QueueOpCodes = new Array();
		QueueOpCodes[0] = 'top.location.href = "http://opcode.napster.com/?op=play_tracks&queue=1&ids=" + strIds';
		QueueOpCodes[1] = 'top.location.href = "http://opcode.napster.com/?op=play_album&queue=1&ids=" + strIds';

		eval(QueueOpCodes[intType]);
	}

	function AddToLibrary( strIds, intType ) {
		strIds = new String( strIds );
		intType = parseInt( intType );
		var ItemOpCodes = new Array();
		ItemOpCodes[0] = 'top.location.href = "http://opcode.napster.com/?op=add_to&type_id=track&destination=library&ids=" + strIds';
		ItemOpCodes[1] = 'top.location.href = "http://opcode.napster.com/?op=add_to&type_id=album&destination=library&ids=" + strIds';
		ItemOpCodes[2] = 'top.location.href = "http://opcode.napster.com/?op=add_to&type_id=playlist&destination=library&ids=" + strIds';
		ItemOpCodes[6] = 'top.location.href = "http://opcode.napster.com/?op=add_to&type_id=contentlist&destination=playlist"';
		// SiteCatalyst Tracking
		var scSaveVarsStr = 's.eVar1="Save"; s.eVar2="Button";s.eVar3=s.pageName;'; 
		if( strIds.split( ',' ).length > 1 && intType == 0 ){
			scSaveVarsStr += 's.eVar5="MultipleTracks";';
		}
		else{
			if( intType == 0 ) {
				scSaveVarsStr += 's.eVar5="Track";';
			}
			else if( intType == 1 ) {
				scSaveVarsStr += 's.eVar5="Album";';
			}
			else if( intType == 2 ) {
				scSaveVarsStr += 's.eVar5="Playlist";';
			}
			else if( intType == 6) { // check on this...
				scSaveVarsStr += 's.eVar5="Playlist";';
			}
		}
		$SCEG( 'ContentAction',scSaveVarsStr);

		eval(ItemOpCodes[intType]);
	}
	
	function SaveMember( memberId, memberName ) {
		var scSaveVarsStr = 's.eVar1="Save"; s.eVar2="Button";s.eVar3=s.pageName;s.eVar5="Member";';
		$SCEG( 'ContentAction',scSaveVarsStr);
		top.location.href = "http://opcode.napster.com/?op=save&type_id=member&id=" + memberId + "&name=" + memberName;
	}
	
	function RemoveMember( memberId ) {
		top.location.href = "http://opcode.napster.com/?op=delete&type_id=member&id=" + memberId;
	}
	
	function addAllListReturnTracks() {
		top.location.href = "http://opcode.napster.com/?op=add_to&type_id=contentlist&destination=library";
	}
	
	function Share( strIds, intType ){
		strIds = new String( strIds );
		intType = parseInt( intType );
		var types = new Array();
		types[0] = 'tracks';
		types[1] = 'album';
		types[2] = 'admin_playlist';
		types[3] = 'playlist';
		types[4] = 'artist';
		var scShareVarsStr = 's.eVar1="Share"; s.eVar2="Button";s.eVar3=s.pageName;s.eVar5="' + types[intType] + '";';
		$SCEG( 'ContentAction',scShareVarsStr);

		var check = "http://opcode.napster.com/?op=pop_url&width=699&height=480&url=http%3A%2F%2Fhome%2Egb%2Enapster%2Ecom%2FGB%2Fen%2Fns%2Fshare%2Findex.html%3Ftype%3D" + types[intType] + "%26ids%3D" + strIds;
		self.location.href = check;
	}

	function Buy( strIds, intType, isAFS ){
		strIds = new String( strIds );
		intType = parseInt( intType );
		var BuyOpCodes = new Array();
		if(strIds == "0") {
			BuyOpCodes[0] = 'top.location.href = "http://opcode.napster.com/?op=add_to&destination=library&type_id=contentlist&perm=y"';
		} else {
			BuyOpCodes[0] = 'top.location.href = "http://opcode.napster.com/?op=download_tracks&perm=y&ids=' + strIds + '"';
		}
		BuyOpCodes[2] = 'top.location.href = "http://opcode.napster.com/?op=add_to&type_id=playlist&perm=y&destination=library&ids=' + strIds + '"';
		BuyOpCodes[3] = 'top.location.href = "http://opcode.napster.com/?op=add_to&type_id=playlist&perm=y&destination=library&ids=' + strIds + '"';
		// handle "album for sale" flag (AFS)
		if (isAFS != null && typeof(isAFS) != 'undefined') {
			BuyOpCodes[1] = 'top.location.href = "http://opcode.napster.com/?op=download_album&perm=y&afs=' + (isAFS ? 1 : 0) + '&ids=' + strIds + '"';
		}
		else {
			BuyOpCodes[1] = 'top.location.href = "http://opcode.napster.com/?op=download_album&perm=y&ids=' + strIds + '"';
		}
		BuyOpCodes[7] = 'top.location.href = "http://opcode.napster.com/?op=download_work&perm=y&ids=' + strIds + '"';

		eval(BuyOpCodes[intType]);
	}
	
	function videoplayerPop(id) {
		openVid(id);
	}

	function openVid(id) {
		//check if we're allowed to play videos
		//if ($C('LFM') == 'Y' || $C('SL') == 'LFM') {
		if (dojo.cookie('LFM') == 'Y' || dojo.cookie('SL') == 'LFM') {
			var success = confirm('This feature is only available to Napster subscribers, click \'OK\' to upgrade your membership.');
			if (success) myAccountPop(3); //change membership node
			return;
		}

		//subtract 4 from width - add 25 to height
		//if you want the size of content area to be correct
		//&width=336&height=402
		self.location.href = "http://opcode.napster.com/?op=pop_url&width=351&height=423&video=1&url=http://" + self.location.hostname + "/ns/videos/player.html?vid=" + id;
	}

	function getChartData() {
		var dataForm = document.chart_data;
		var selectedSeason;
		// this is here in case there's only one season available
		if(!dataForm.seasons.length) {
				selectedSeason = dataForm.seasons.value;
		}
		else {
			for(i = 0; i < dataForm.seasons.length; i++) {
				if(dataForm.seasons[i].checked) {
					selectedSeason = dataForm.seasons[i].value;
				}
			}
		}
		top.location.href = "http://opcode.napster.com/?op=switch&tab=browse&type_id=billboard&result_type=" + dataForm.result_type.value + "&select_by=chart&select_value=" + dataForm.chart_id.value + "&year=" + dataForm.year[dataForm.year.selectedIndex].value + "&seasoncode=" + selectedSeason;
	}

	function myAccountPop( node ) {
		var intNode = parseInt(node);
		var nodes = new Array();
		nodes[0] = 'op=switch&dlg=myaccount&tab=accountstatus'; // Account Status
		nodes[1] = 'op=switch&dlg=myaccount&tab=paymentinfo'; // Payment Information
		nodes[2] = 'op=switch&dlg=myaccount&tab=billinginfo'; // Request Billing History
		nodes[3] = 'op=switch&dlg=myaccount&tab=changemembership'; // Change Membership
		nodes[4] = 'op=switch&dlg=myaccount&tab=redeemccodes'; // Redeem Cards & Codes
		nodes[5] = 'op=switch&dlg=myaccount&tab=managepcs'; // Manage My PCs
		nodes[6] = 'op=switch&dlg=myaccount&tab=managedevices'; // Manage My Devices
		nodes[7] = 'op=switch&dlg=myaccount&tab=preferences'; // Preferences
		nodes[8] = 'op=switch&dlg=myaccount&tab=purchasehistory'; // Track Purchase History
		window.external.executeOpcode(nodes[intNode]);
	}

	function bundleRegPop() {
		if (isClient()) {
			self.location.href = "http://opcode.napster.com/?op=pop_url&height=400&width=690&url=https://sms.napster.com/ns/registration/bundle/agree_terms.html%3Ftype%3Dupsell%26country_code%3DGB%26src%3Dglobal_nav";
		} else {
			window.open('https://sms.napster.com/ns/registration/bundle/?type=reg&country_code=GB&promo_id=BUNDLE_CREATIVEZV1GB_1Y', 'reg');
		}
	}

	function AddListActions(btnEl, itemType) {
		if(typeof(window.external.ui) != "undefined") {
			if(typeof(window.external.ui.DoActionMenu) != "undefined") {
				window.external.ui.DoActionMenu(3, "", {});
			} else {
				addAllListReturnTracks();
			}
		} else {
			addAllListReturnTracks();
		}
	}
	
	function AddActions(btnEl, itemID, itemType, itemRights) {
		if(itemType == 6) { itemType = 4; }
		if(typeof(window.external.ui) != "undefined") {
			if(typeof(window.external.ui.DoActionMenu) != "undefined") {
				window.external.ui.DoActionMenu(itemType, itemID, itemRights);
			} else {
				AddToLibrary(itemID, itemType);
			}
		} else {
			AddToLibrary(itemID, itemType);
		}
	}

	/*
	function genericPop(url) {
		top.location.href = "http://opcode.napster.com/?op=pop_url&width=800&height=600&url=" + encodeURI(url); 
	}
	*/

	function removeAddedPops(closeTarget) {
		// client doesn't deal with css popups, should only be relevant for purchase flow
		// we use a different opcode to close, so this is just a stub to prevent errors
	}


if(dojo.isIE == 6) { window.onresize = fixMainContentArea; }
if(dojo.isIE == 6) { window.onload = fixMainContentArea; }

