var NOWPLAYING = {
	getCurrentMediaObj : function(){
		try {
			return RadioPlayerObj.currentMedia;
		} catch(e) {
			WriteToLog("error calling getCurrentMediaObj");
		}
	},
	getNowPlayingArtist : function(){
		try {
			return RadioPlayerObj.currentMedia.getItemInfo("Author");
		} catch(e) {
			WriteToLog("error calling getNowPlayingArtist");
		}
	},
	getNowPlayingArtistId : function(){
		try {
			return RadioPlayerObj.currentMedia.getItemInfo("ArtistId");
		} catch(e) {
			WriteToLog("error calling getNowPlayingArtistId");
		}
	},
	getNowPlayingTitle : function(){
		try {
			return RadioPlayerObj.currentMedia.name;
		} catch(e) {
			WriteToLog("error calling getNowPlayingTitle");
		}
	},
	getTrackId : function(){
		try {
			return RadioPlayerObj.currentMedia.getItemInfo("CPTrackID");
		} catch(e) {
			WriteToLog("error calling getTrackId");
		}
	},	
	getNowPlayingAlbum : function(){
		try {
		return RadioPlayerObj.currentMedia.getItemInfo("AlbumTitle");
		} catch(e) {
			WriteToLog("error calling getNowPlayingAlbum");
		}
	},
	getNowPlayingAlbumId : function(){
		try {
			return RadioPlayerObj.currentMedia.getItemInfo("AlbumId");
		} catch(e) {
			WriteToLog("error calling getNowPlayingAlbumId");
		}
	},
	getNextUpArtist : function() {
		try {
			for(var i=0; i < (RadioPlayerObj.currentPlaylist.count); i++){
				if (RadioPlayerObj.currentmedia.isIdentical(RadioPlayerObj.currentPlaylist.item(i))){
					if (i+1 < (RadioPlayerObj.currentPlaylist.count)) {
					return RadioPlayerObj.currentPlaylist.item(i+1).getItemInfo("Author");
					} else {
					return "NONE";
					}
				}
			}	
		} catch(e) {
			WriteToLog("error calling getNextUpArtist");
		}
	},
	getNextUpArtistId : function() {
		try {
			for(var i=0; i < (RadioPlayerObj.currentPlaylist.count); i++){
			  	if (RadioPlayerObj.currentmedia.isIdentical(RadioPlayerObj.currentPlaylist.item(i))){
					if (i+1 < RadioPlayerObj.currentPlaylist.count) {
					return RadioPlayerObj.currentPlaylist.item(i+1).getItemInfo("ArtistId");
					} 
				}
			}	
		} catch(e) {
			WriteToLog("error calling getNextUpArtistId");
		}
	},
	getNextUpTitle : function() {
		try {
			for(var i=0; i < (RadioPlayerObj.currentPlaylist.count); i++){
				if (RadioPlayerObj.currentmedia.isIdentical(RadioPlayerObj.currentPlaylist.item(i))){
					if (i+1 < RadioPlayerObj.currentPlaylist.count) {
					return RadioPlayerObj.currentPlaylist.item(i+1).getItemInfo("Title");
					} else {
					return "NONE";
					}
				}
			}	
		} catch(e) {
			WriteToLog("error calling getNextUpTitle");
		}
	},
	playlistCount : function() {
		try {
			return RadioPlayerObj.currentPlaylist.count;
		} catch(e) {
			WriteToLog("error calling playlistCount");
		}
	},
	playlistCurrentItemCount : function() {
		for (var i = 0; i < RadioPlayerObj.currentPlaylist.count; i++){
		   	if (RadioPlayerObj.currentmedia.isIdentical(RadioPlayerObj.currentPlaylist.item(i))){
		  		return (i + 1); 
		     }  
		}
		return "";
	},
	getNextEntrytype : function() {
		try {
			for(var i=0; i < (RadioPlayerObj.currentPlaylist.count); i++){
				if (RadioPlayerObj.currentmedia.isIdentical(RadioPlayerObj.currentPlaylist.item(i))){
					if (i+1 < RadioPlayerObj.currentPlaylist.count) {
					return RadioPlayerObj.currentPlaylist.item(i+1).getItemInfo("entrytype");
					} else {
					return "NONE";
					}
				}
			}	
		} catch(e) {
			WriteToLog("error calling getNextEntrytype");
		}
	},
	getNextCanSkip : function() {
		try {
			return RadioPlayerObj.controls.isAvailable("next");
		} catch(e) {
			WriteToLog("error calling getNextCanSkip");
		}
	},
	playNextUp : function() {
		try {
			if(RadioPlayerObj.controls.isAvailable('Next') && (TrackSkips < 10)){
				// send reporting call
				RadioReporting.Send(true);
				
				RadioPlayerObj.controls.next();
				WriteToLog("NEXT method called on player");
				TrackSkips++;
			}
			if(TrackSkips>=10){ // disable next button
				$("BtnNext").DisableOrEnableImg(false);
			}
			if (RadioPlayerObj.controls.isAvailable('Play')){ RadioPlayerObj.controls.play();}
		} catch(e) {
			WriteToLog("error calling playNextUp");
		}
	}, 
	getStationObj : function(){
		try {
			return RadioPlayerObj.currentPlaylist;
		} catch(e) {
			WriteToLog("error calling getStationObj");
		}
	},
	getStationName : function(){
		try {
			return RadioPlayerObj.currentPlaylist.name;
		} catch(e) {
			WriteToLog("error calling getStationName");
		}
	},
	getStationId : function(){
		try {
			return RadioPlayerObj.currentPlaylist.getItemInfo("CPRadioID");
		} catch(e) {
			WriteToLog("error calling getStationId, Error" + e.number + " :" + e.message + " :" + e.description)
		}
	},
	currentStationId : "",
	getTrackAvailable : function(){
		try {
			return RadioPlayerObj.currentMedia.getItemInfo("Available");
		} catch(e) {
			WriteToLog("error calling getTrackAvailable");
		}
	},
	getArtistAvailable : function(){
		try {
			return RadioPlayerObj.currentMedia.getItemInfo("ArtistAvailable");
		} catch(e) {
			WriteToLog("error calling ArtistAvailable");
		}
	},
	init : function(){
		try {
			this.currentStationId = NOWPLAYING.getStationId();
		} catch(e) {
			WriteToLog("error calling init");
		}
	},	
	getPlayState : function(){
		try {
			return RadioPlayerObj.playState;
		} catch(e) {
			WriteToLog("error calling getPlayState");
		}
	},	
	entrytype : function(){
		try {
			return RadioPlayerObj.currentMedia.getItemInfo("entrytype");
		} catch(e) {
			WriteToLog("error calling entrytype");
		}
	},	
	getStartUrl : function(){
		try {
			return RadioPlayerObj.currentMedia.getItemInfo("startUrl");
		} catch(e) {
			WriteToLog("error calling getStartUrl");
		}
	},	
	getEndUrl : function(){
		try {
			return RadioPlayerObj.currentMedia.getItemInfo("endUrl");
		} catch(e) {
			WriteToLog("error calling getStartUrl");
		}
	},	
	hasCoAd : function(){
		try {
			if ((RadioPlayerObj.currentMedia.getItemInfo("coAd"))  && (RadioPlayerObj.currentMedia.getItemInfo("coAd")!= "undefined")){
				return true;
			} else {
				return false;
			}
		} catch(e) {
			WriteToLog("error calling hasCoAd");
		}
	},	
	displayCoAd : function(displayType){
		try {
			var adTag = RadioPlayerObj.currentMedia.getItemInfo("coAd");
			WriteToLog("coAd : " + adTag.substr(0,20));
			var adFrame = document.all.adFrame;
			if (displayType == 'load'){
				adFrame.src = adTag;
			} else {
				//adFrame.src = "/sitewide/img/spacer.gif";
			}
		} catch (e) { WriteToLog("error in display_coAd: " + e.description); }
	},	
	display : function() {
		var charlimit = 40;
		try {
			var trackTitle = this.getNowPlayingTitle();
			if(this.entrytype()=="promo"){ trackTitle = "URGE Radio"; }
			if (trackTitle.length > charlimit) { 
				trackTitle = trackTitle.substr(0,charlimit); 
				trackTitle = trackTitle.concat("...");
			}
			var artistName = this.getNowPlayingArtist();
			var artistNameTitle = artistName;
			if (this.entrytype()=="promo"){ artistName = " "; }
			if (artistName.length > charlimit) { 
				artistName = artistName.substr(0,charlimit); 
				artistName = artistName.concat("...");
			}
			var albumTitle = this.getNowPlayingAlbum();
			if (albumTitle.length > charlimit) { 
				albumTitle = albumTitle.substr(0,charlimit); 
				albumTitle = albumTitle.concat("...");
			}
			var nextUpArtist = this.getNextUpArtist();
			var nextUpArtistTitle = nextUpArtist;
			if (nextUpArtist.length > 30) { 
				nextUpArtist = albumTitle.substr(0,charlimit); 
				nextUpArtist = albumTitle.concat("...");
			}		
			
			var stationName = this.getStationName();
			if (stationName.length > charlimit) { 
				stationName = stationName.substr(0,charlimit); 
				stationName = stationName.concat("...");
			}
			
			// this will have to be replaced with the actual image url


			var AlbumImgSrc = "images/album_placeholder_75.gif";
			var ThisAlbumId = this.getNowPlayingAlbumId();
			if(ThisAlbumId!=""){
				AlbumImgSrc = "http://store.urge.com/sitewide/dataservices/images/?type=album&id=" + this.getNowPlayingAlbumId();
			}

			var np = "<div id='NowPlayingHeading'>"+CopyStrings.NowPlaying.Heading+"</div>";
			np += "<div id='NowPlayingStation'><span class='left'>"+CopyStrings.NowPlaying.Station+"</span><span class='right'>" + stationName + "</span></div>";
			np += "<div id='NowPlayingSong'><span class='left'>"+CopyStrings.NowPlaying.Song+"</span><span class='right'>" + trackTitle + "</span></div>";
			np += "<div id='NowPlayingArtist'><span class='left'>"+CopyStrings.NowPlaying.Artist+"</span><span class='right'>" + artistName + "</span></div>";
			np += "<div id='NowPlayingAlbum'><span class='left'>"+CopyStrings.NowPlaying.Album+"</span><span class='right'>" + albumTitle + "</span></div>";
			np += "<div id='NowPlayingAlbumArtImg'><img class='AlbumArtImg' src='"+AlbumImgSrc+"' width='75' height='75' alt='" + albumTitle + "' /></div>"


			if (this.getNextEntrytype()!="NONE"){
				np += "<div id='NowPlayingUpNext'>"+CopyStrings.NowPlaying.UpNext+"</div>";
				if (this.getNextEntrytype()!="promo"){
					// disable skipping
					if (!this.getNextCanSkip()){
						np += nextUpArtist; 	
					}else{
						np += "<div id='NowPlayingNextUp'><a href='javascript:NOWPLAYING.playNextUp();'>" + nextUpArtist + "</a></div>";
					}
				}
				np += "";
			}
			return np;
		}catch(e){
			WriteToLog("error calling display: " + e);
		}			
	}
}


