songActive = 1;
videoActive = 0;
idTimeRoot = null;
idTimeJoe = null;
idTimeMusic = null;
idTimeVideo = null;
activeVideo = 0;
activeJoe = 0;
activeMusic = 0;
audioWindow = null;
ArtistSongNumber = 1;
ArtistLetterId = '';
LetterId = '';
ArtistSong = '';
videoFrameLoad = 0;
videoFrameLoadFunction = null;
JoeFrameLoad = 0;
JoeFrameLoadFunction = null;
inPopup = 0;
inPopupClick = 0;

//create and delete handler from event
function eventPush(obj, event, handler) {
  if (obj.addEventListener) {
    obj.addEventListener(event, handler, false);
  } else if (obj.attachEvent) {
    obj.attachEvent('on'+event, handler);
  }
}
function eventDelete(obj, event, handler) {
  if (obj.addEventListener) {
    obj.removeEventListener(event, handler, false);
  } else if (obj.attachEvent) {
    obj.detachEvent('on'+event, handler);
  }
}
// change baner with action on site
function getContent(iframe) {
    var content = '';
    if (iframe.contentDocument) {
        content = iframe.contentDocument.body.innerHTML;
    } else if (iframe.contentWindow) {
        content = iframe.contentWindow.document.body.innerHTML;
    } else if (iframe.document) {
        content = iframe.document.body.innerHTML;
    }
    return content;
}
function onLoadFrameRoot() {
    if (getContent(document.getElementById('hiddenRoot')) != '') {
        document.getElementById("ad_med_square").innerHTML = getContent(document.getElementById('hiddenRoot'));
    }
}
function setContentRoot(url) {
    frames['hiddenRoot'].location = url;
    var timeRoot = Math.floor(Math.random() * 20000 + 15000);
    idTimeRoot = setTimeout("setContentRoot('/includes/music/banerRoot.html')", timeRoot);
}
function onLoadFrameJoe() {
    if (getContent(document.getElementById('hiddenJoe')) != '') {
        document.getElementById("ad_leaderboardCloudBack").innerHTML = getContent(document.getElementById('hiddenJoe'));
    }
}
function setContentJoe(url) {
    if (activeJoe == 1) {
        frames['hiddenJoe'].location = url;
        var timeJoe = Math.floor(Math.random() * 20000 + 15000);
        idTimeJoe = setTimeout("setContentJoe('/includes/music/banerJoe.html')", timeJoe);
    }
}
function onLoadFrameMusic() {
    if (getContent(document.getElementById('hiddenMusic')) != '') {
        document.getElementById("ad_med_square").innerHTML = getContent(document.getElementById('hiddenMusic'));
    }
}
function setContentMusic(url) {
    frames['hiddenMusic'].location = url;
    var timeMusic = Math.floor(Math.random() * 20000 + 15000);
    idTimeMusic = setTimeout("setContentMusic('/includes/music/banerMusic.html')", timeMusic);
}
// change baner with action on site
function adGetWindowWidth() {
    if (typeof(window.innerWidth) == 'number') {
        //Non-IE
        return window.innerWidth;
    }
    if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
        //IE 6+ in 'standards compliant mode'
        return document.documentElement.clientWidth;
    }
    if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
        //IE 4 compatible
        return document.body.clientWidth;
    }
    return 0;
}

function adGetWindowHeight() {
    if (typeof(window.innerWidth) == 'number') {
        //Non-IE
        return window.innerHeight;
    }
    if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
        //IE 6+ in 'standards compliant mode'
        return document.documentElement.clientHeight;
    }
    if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
        //IE 4 compatible
        return document.body.clientHeight;
    }
    return 0;
}

function addGlassDiv() {
    var oDiv = document.createElement("div");
    oDiv.id = "glass";
    oDiv.setAttribute("id", "glass");
    document.body.insertBefore(oDiv, document.body.firstChild);
    var oGlass = document.getElementById("glass");
    pngOrGif = (navigator.userAgent.toLowerCase().indexOf('msie 6') >= 0) ? 'gif' : 'png';
    oGlass.innerHTML = '<div id="mfGlassPaneDarkDiv" style="display:none">&nbsp;</div>';
}

function showDarkGlassPane(popupId) {
    document.getElementById(popupId).style.position = 'fixed';
    var div2 = document.getElementById('mfGlassPaneDarkDiv');
    var ua = navigator.userAgent.toLowerCase();
    if (ua.indexOf('msie 6') != -1) {
        document.getElementById(popupId).style.position = 'absolute';
        div2.style.position = 'absolute';
        div2.style.width = document.body.clientWidth;
        div2.style.height = document.body.clientHeight;
        div2.style.top = document.body.scrollTop + 'px';
        div2.style.left = document.body.scrollLeft + 'px';
        document.body.onscroll = function () {
            document.getElementById('mfGlassPaneDarkDiv').style.top = (document.body.scrollTop) + 'px';
            document.getElementById('mfGlassPaneDarkDiv').style.left = (document.body.scrollLeft) + 'px';
//            document.getElementById(popupId).style.top = (document.body.scrollTop) + 'px';
//            document.getElementById(popupId).style.left = (document.body.scrollLeft) + 'px';
        };
    }
    div2.style.display = 'block';
    showDarkGlassPaneInit = true;
}

function showPopupDiv(popupId) {
    document.getElementById(popupId).style.display = 'block';
    var windowWidth = adGetWindowWidth();
    var windowHeight = adGetWindowHeight();
    var objWidth = document.getElementById(popupId).offsetWidth;
    var objHeight = document.getElementById(popupId).offsetHeight;
    var posX = Math.round((windowWidth - objWidth) / 2);
    if (posX < 0) {
        posX = 0;
    }
    var posY = Math.round((windowHeight - objHeight) / 2);
    if (posY < 0) {
        posY = 0;
    }
    document.getElementById(popupId).style.left = posX + 'px';
    document.getElementById(popupId).style.top = posY + 'px';
}

actualPopup = null;
oldEvent = null;
function showPopup(popupId) {
    actualPopup = popupId;
    addGlassDiv();
    showDarkGlassPane(popupId);
    showPopupDiv(popupId);
    oldEvent = window.onresize;
    window.onresize = function () {
        if (oldEvent) {
            oldEvent();
        }
        showPopupDiv(actualPopup);
    };
}

function closePopup(popupId) {
    window.onresize = function () {};
    document.getElementById(popupId).style.display = 'none';
    var oGlass = document.getElementById("glass");
    oGlass.parentNode.removeChild(oGlass);
}

function closePopupJoe(popupId) {
    activeJoe = 0;
    frames.JoeFrame.tpController.setReleaseURL('http://release.theplatform.com/content.select?pid=');
    closePopup(popupId);
}

function closePopupVideo(popupId) {
    activeVideo = 0;
    frames.videoFrame.tpController.setReleaseURL('http://release.theplatform.com/content.select?pid=');
    closePopup(popupId);
}

function getNodesByName(nodes, name) {
    var filteredNodes = [];
    for (var i = 0; i < nodes.length; i++) {
        if (nodes[i].nodeName == name) {
            filteredNodes.push(nodes[i]);
        }
    }
    return filteredNodes;
}

function showGallery(id, n, size) {
    var gallery = document.getElementById(id);
    if (!gallery) {
        return;
    }
    var nodes = getNodesByName(gallery.childNodes, "LI");
    for (var i = 0; i < nodes.length; i++) {
        if ((i >= n) && (i < (n + size))) {
            nodes[i].style.display = "block";
        } else {
            nodes[i].style.display = "none";
        }
    }
    var prev = document.getElementById(id + "Prev");
    if (prev) {
        if (n > 0) {
            prev.style.visibility = "visible";
            prev.onclick = function () {
                showGallery(id, n - 1, size);
            };
        } else {
            prev.style.visibility = "hidden";
            prev.onclick = null;
        }
    }
    var next = document.getElementById(id + "Next");
    if (next) {
        if ((n + size) < nodes.length) {
            next.style.visibility = "visible";
            next.onclick = function () {
                showGallery(id, n + 1, size);
            };
        } else {
            next.style.visibility = "hidden";
            next.onclick = null;
        }
    }
}

function showArtist(letter, n) {
    var artist = document.getElementById("artist" + letter + n);
    var artistLink = document.getElementById("artistLink" + letter + n);
    if (artist && artistLink) {
        var t;
        var i = 1;
        do {
            t = document.getElementById("artist" + letter + i);
            if (t && (t != artist)) {
                t.style.display = "none";
            }
            i++;
        }
        while (t);

        i = 1;
        do {
            t = document.getElementById("artistLink" + letter + i);
            if (t && (t != artistLink)) {
                t.className = "accordion-toggle";
            }
            i++;
        }
        while (t);

        artist.style.display = "block";
        artistLink.className = "accordion-toggle active";
    }
}

function showArtists(letter) {
    var songs = document.getElementById("songs" + letter);
    if (songs) {
        songs.style.display = "none";
    }
    var artists = document.getElementById("artists" + letter);
    var letterLink = document.getElementById("letterLink" + letter);
    if (artists && letterLink) {
        var t;
        var c = "A".charCodeAt(0);
        do {
            t = document.getElementById("artists" + String.fromCharCode(c));
            if (t && (t != artists)) {
                t.style.display = "none";
            }
            c++;
        }
        while (t);

        c = "A".charCodeAt(0);
        do {
            t = document.getElementById("letterLink" + String.fromCharCode(c));
            if (t && (t != letterLink)) {
                t.className = "";
            }
            c++;
        }
        while (t);

        artists.style.display = "block";
        letterLink.className = "active";
        showArtist(letter, 1);
        activeLetter = letter;
    }
}

function showSongs(letter) {
    var artists = document.getElementById("artists" + letter);
    if (artists) {
        artists.style.display = "none";
    }
    var songs = document.getElementById("songs" + letter);
    var letterLink = document.getElementById("letterLink" + letter);
    if (songs && letterLink) {
        var t;
        var c = "A".charCodeAt(0);
        do {
            t = document.getElementById("songs" + String.fromCharCode(c));
            if (t && (t != songs)) {
                t.style.display = "none";
            }
            c++;
        }
        while (t);

        c = "A".charCodeAt(0);
        do {
            t = document.getElementById("letterLink" + String.fromCharCode(c));
            if (t && (t != letterLink)) {
                t.className = "";
            }
            c++;
        }
        while (t);

        songs.style.display = "block";
        letterLink.className = "active";
        activeLetter = letter;
    }
}

function processData(id, display) {
    var t;
    var c = "A".charCodeAt(0);
    do {
        t = document.getElementById(id + String.fromCharCode(c));
        if (t && t.style && t.style.display) {
            t.style.display = display;
        }
        c++;
    }
    while (t);
}

function getTabDivId(name) {
    name = name.toLowerCase();
    if (name.indexOf("artists") != -1) {
        return "mainArtists";
    }
    if (name.indexOf("songs") != -1) {
        return "mainSongs";
    }
    return null;
}

function getTabDiv(name) {
    var tabDivName = getTabDivId(name);
    return ((tabDivName) ? document.getElementById(tabDivName) : null);
}

function isActiveTab(name) {
    var tabDiv = getTabDiv(name);
    if (tabDiv) {
        name = name.toLowerCase();
        var nodes = getNodesByName(tabDiv.childNodes, "A");
        for (var i = 0; i < nodes.length; i++) {
            if (nodes[i].className.toLowerCase().indexOf(name) != -1) {
                return true;
            }
        }
    }
    return false;
}

function showLetter(letter) {
    if (isActiveTab("Artists")) {
        showArtists(letter);
        return;
    }
    if (isActiveTab("Songs")) {
        showSongs(letter);
        return;
    }
}

function showTab(name) {
    var className;

    if (name.toLowerCase().indexOf("artists") != -1) {
        className = "artistsActive";
        processData("songs", "none");
    } else if (name.toLowerCase().indexOf("songs") != -1) {
        className = "songsActive";
        processData("videos", "none");
    }

    if (className) {
        var mainArtists, mainSongs, i, nodes, node;
        mainArtists = document.getElementById("mainArtists");
        nodes = mainArtists.childNodes;
        for (i = 0; i < nodes.length; i++) {
            node = nodes[i];
            if (node.nodeName == "A") {
                node.className = className;
                break;
            }
        }
        mainSongs = document.getElementById("mainSongs");
        nodes = mainSongs.childNodes;
        for (i = 0; i < nodes.length; i++) {
            node = nodes[i];
            if (node.nodeName == "A") {
                node.className = className;
                break;
            }
        }
    }
    showLetter(activeLetter);
}

function defaultOpenHandler(artistId) {
    document.location.href = "/music/" + artistId;
}

function selectArtist(artistId, letter, n, handler) {
    var artist = document.getElementById("artist" + letter + n);
    if (artist) {
        if (artist.style.display == "block") {
          if (inPopup == 0) {
            if (handler && (typeof handler == "function")) {
                handler(artistId);
            } else {
                defaultOpenHandler(artistId);
            }
          }
        } else {
            showArtist(letter, n);
        }
    }
}

function showMoreArtist(page, size) {
    var moreArtists = document.getElementById("more-artists-boxes");
    if (!moreArtists) {
        return;
    }
    var imgThumb;
    var imgHost = (document.location.host == "www.channelone.com") ? "http://images.channelone.com" : "";
    var nodes = getNodesByName(moreArtists.childNodes, "LI");
    var start = page * size;
    var end = Math.min(start + size, nodes.length);
    for (var i = 0; i < nodes.length; i++) {
        if ((i >= start) && (i < end)) {
			imgThumb = document.getElementById("imgThumb" + i);
			if (imgThumb) {
				if (!imgThumb.src || (imgThumb.src.indexOf(artistThumbs[i]) == -1)) {
					imgThumb.src = imgHost + artistThumbs[i];
				} 
			}
            nodes[i].style.display = "block";
        } else {
            nodes[i].style.display = "none";
        }
    }
    var prev = document.getElementById("more-artists-nav-prev");
    if (prev) {
        if (start > 0) {
            prev.innerHTML = "<a href='javascript:showMoreArtist(" + (page - 1) + ", " + size + ");' class='active'>Prev</a>";
        } else {
            prev.innerHTML = "<span>Prev</span>";
        }
    }
    var next = document.getElementById("more-artists-nav-next");
    if (next) {
        if (end < nodes.length) {
            next.innerHTML = "<a href='javascript:showMoreArtist(" + (page + 1) + ", " + size + ");' class='active'>Next</a>";
        } else {
            next.innerHTML = "<span>Next</span>";
        }
    }
}

function artistOverlay(a) {
    if (!a) {
        return;
    }
    if (a.parentNode.style.top === "") {
        a.style.backgroundPosition = "bottom right";
        a.parentNode.style.top = "0px";
    } else {
        a.style.backgroundPosition = "";
        a.parentNode.style.top = "";
    }
}

function removeOldVideoSong() {
    if (songActive === 0) {
        var videoList = document.getElementById('videoList' + videoActive);
        if (videoList) {
        	videoList.removeAttribute('class');
        	videoList.setAttribute('class', 'video');
        	videoList.className = 'video';
            if (navigator.userAgent.toLowerCase().indexOf('msie 6') != -1) {
            	videoList.style.backgroundColor = '';
            }
        }
        videoActive = 0;
        return;
    }
    if (videoActive === 0) {
        var songList = document.getElementById('songList' + songActive);
        if (songList) {
        	songList.removeAttribute('class');
        	songList.className = '';
        }
        songActive = 0;
        return;
    }
}

function removeBeforeASlist() {
 	if (ArtistSong == 'artist') {
		document.getElementById('ASList'+ArtistSongNumber).setAttribute('class','video');
		document.getElementById('ASList'+ArtistSongNumber).className = 'video';
	}
 	if (ArtistSong == 'song') {
		document.getElementById('ASList'+ArtistSongNumber).removeAttribute('class');
		document.getElementById('ASList'+ArtistSongNumber).className = '';
	}
}
function playSong(path,artist,title,ASNumber) {
	var pathGoogle='/music/play/'+artist+"/song/"+title;
   	pageTracker._trackPageview(pathGoogle);
//    alert(pathGoogle);
	
	if (ASNumber > 0) {
		removeBeforeASlist();
		removeOldVideoSong();
		ArtistSong = 'song';
		ArtistSongNumber = ASNumber;
		document.getElementById('ASList'+ArtistSongNumber).setAttribute('class','active');
		document.getElementById('ASList'+ArtistSongNumber).className = 'active';
	}
	
    if (activeMusic == 0) {
        flash.audioPlayPath(path);
    }
    if (activeMusic == 1) {
        audioWindow.flash.audioPlayPath(path);
    }
    //    flash.audioPlayPath(path);
}
function removeBeforeASlistPopup() {
	document.getElementById('ASList'+ArtistSongNumber).removeAttribute('class');
	document.getElementById('ASList'+ArtistSongNumber).className = '';
}
function playSongNumber(ASNumber) {
	removeBeforeASlistPopup();
	ArtistSongNumber = ASNumber;
	document.getElementById('ASList'+ArtistSongNumber).setAttribute('class','active');
	document.getElementById('ASList'+ArtistSongNumber).className = 'active';

	inPopupClick = 1;
	var oNumberId = document.getElementById('ASList'+ASNumber);
	LetterId = oNumberId.parentNode.parentNode.parentNode.parentNode.getAttribute('id');
	if (LetterId.substring(0,7) == 'artists') {
		ArtistLetterId =  oNumberId.parentNode.parentNode.parentNode.getAttribute('id');
		ArtistSong = 'artist';
	} else {
	 	ArtistLetterId = '';
		ArtistSong = 'song';
	}
}
function playSongPopup(path,artist,title,ASNumber) {
	var pathGoogle='/music/play/'+artist+"/song/"+title;
   	pageTracker._trackPageview(pathGoogle);

	playSongNumber(ASNumber);
    flash.audioPlayPath(path);
}

function onLoadFrame(param) {
	alert('jestem');
	alert(param);
}

function playVideoOnLoad(path,artist,title,number,ASNumber) {
//	alert('playVideoOnLoad');
	videoFrameLoad = 1;
    eventDelete(document.getElementById('videoFrame'),'load',videoFrameLoadFunction);
 	playVideo(path,artist,title,number,ASNumber);
}
function playVideo(path,artist,title,number,ASNumber) {
 	if (videoFrameLoad == 0) {
	 	videoFrameLoadFunction = function () {playVideoOnLoad(path,artist,title,number,ASNumber);}
    	eventPush(document.getElementById('videoFrame'),'load',videoFrameLoadFunction);
		document.getElementById("videoFrame").src = "/musicPopup/new/video.vm";
		return;
	}
	var pathGoogle='/music/play/'+artist+"/video/"+title;
   	pageTracker._trackPageview(pathGoogle);
//    alert(pathGoogle);
	if (ASNumber > 0) {
		removeBeforeASlist();
		removeOldVideoSong();
		ArtistSong = 'artist';
		ArtistSongNumber = ASNumber;
		document.getElementById('ASList'+ArtistSongNumber).setAttribute('class','active video');
		document.getElementById('ASList'+ArtistSongNumber).className = 'active video';
	}

    activeVideo = 1;
    if (number > 0) {
     	removeBeforeASlist();
	    removeOldVideoSong();
    	var videoList = document.getElementById('videoList' + number);
    	if (videoList) {
    		videoList.removeAttribute('class');
       		videoList.setAttribute('class', 'active video');
        	videoList.className = 'active video';
        	if (navigator.userAgent.toLowerCase().indexOf('msie 6') != -1) {
        		videoList.style.backgroundColor = '#AF6680';
       		}
    	}
    	videoActive = number;
    }
    audioPause();
    frames['videoFrame'].document.getElementById('section_musicVideo').style.display = "block";
    frames['videoFrame'].displayVideoPlayer();
    frames['videoFrame'].tpController.setReleaseURL('http://release.theplatform.com/content.select?pid=' + path);
    frames['videoFrame'].setContentVideo('/includes/music/banerVideo.html');
    showPopup('section_musicVideo');
    //	var videoWindow = window.open('/musicPopup/new/video.vm?PID='+path, 'video', 'height=360,width=730,toolbar=no,scrollbars=no');
}

function playVideoGalery(path) {
    var videoWindow = window.open('/musicPopup/new/video.vm?PID=' + path, 'video', 'height=360,width=730,toolbar=no,scrollbars=no');
}

function openJoePopupOnLoad(path, play) {
//	alert('openJoePopupOnLoad');
	JoeFrameLoad = 1;
    eventDelete(document.getElementById('videoFrame'),'load',JoeFrameLoadFunction);
	setTimeout(function(){openJoePopup(path, play);},2000);
}
function openJoePopup(path, play) {
 	if (JoeFrameLoad == 0) {
	 	JoeFrameLoadFunction = function () {openJoePopupOnLoad(path, play);}
    	eventPush(document.getElementById('JoeFrame'),'load',JoeFrameLoadFunction);
		document.getElementById("JoeFrame").src = "/musicPopup/new/joe-b-archive.vm";
		return;
	}
    flash.audioPause();
    activeJoe = 1;
    frames['JoeFrame'].document.getElementById('section_musicJoe').style.display = "block";
    frames['JoeFrame'].displayVideoPlayerJoe();
    if (play == 0) {
        frames['JoeFrame'].tpController.loadReleaseURL('http://release.theplatform.com/content.select?pid=' + path);
    }
    if (play == 1) {
        frames['JoeFrame'].tpController.setReleaseURL('http://release.theplatform.com/content.select?pid=' + path);
    }
    frames['JoeFrame'].setContentJoe('/includes/music/banerJoe.html');
    showPopup('section_musicJoe');
}

function openMusicPopup(id) {
    activeMusic = 1;
    document.getElementById('np-hdr-id').style.display = 'none';
    document.getElementById('flash-music').style.left = '-1000px';
    document.getElementById('flash-music').style.height = '0px';
    document.getElementById('scroll-box-id').style.height = '217px';
    flash.audioPause();
    audioWindow = window.open('/music/player/popup-player.vm?artistId=' + id + '&songNumber=' + songActive, 'audioPlayer', 'height=317,width=700,toolbar=no,scrollbars=no');
}

function showMusicPlayer() {
    activeMusic = 0;
    document.getElementById('np-hdr-id').style.display = 'block';
    document.getElementById('flash-music').style.height = '20px';
    document.getElementById('flash-music').style.left = '0px';
    document.getElementById('scroll-box-id').style.height = '169px';
    //    flash.setList(playList);
    flash.audioSetVolume(50);
}
function closeMusicPopup() {
    audioWindow.close();
    showMusicPlayer();
}

function showPhotoGallery(galleryId, photoNumber) {
    var url = "/music/" + galleryId;
    if (photoNumber) {
    	url += "/" + photoNumber;
    }
    window.open(url, 'hear_it_now', 'height=515,width=730,toolbar=no,scrollbars=yes');
}

function bonamassaPlay(path) {
    tpController.setReleaseURL('http://release.theplatform.com/content.select?pid=' + path);
}

function changeActivePlayList(number) {
    removeOldVideoSong();
    var songList = document.getElementById('songList' + number);
    if (songList) {
        songList.setAttribute('class', 'active');
        songList.className = 'active';
    }
    songActive = number;
}
function audioPlayNumber(number,artist,title) {
   	removeBeforeASlist();
	var pathGoogle='/music/play/'+artist+"/song/"+title;
   	pageTracker._trackPageview(pathGoogle);
//   	alert(pathGoogle);
	 	 
    changeActivePlayList(number);
    if (activeMusic == 0) {
        flash.audioPlayNumber(number - 1);
    }
    if (activeMusic == 1) {
        audioWindow.flash.audioPlayNumber(number - 1);
    }
}

function audioPause() {
    flash.audioPause();
}
//callback from flash
function actualNumber(number, dir) {
 	if (inPopup == 0) {
	    changeActivePlayList(number + 1);
	}
 	if (inPopup == 1) {
//	    top.opener.changeActivePlayList(number + 1);
		if (dir == 1) {
	    	actualPlayEnd(number,dir);
	    } 
		if (dir == -1) {
	    	actualPlayEnd(number-2,dir);
		}
	}
}
//callback from flash - end play
function actualPlayEnd(number, dir) {
 	if (inPopup == 0) {
		var thisNumber = number + 1;
		if (thisNumber >= playList.length) { thisNumber = 0; }
		flash.audioPlayNumber(thisNumber);
    	changeActivePlayList(thisNumber + 1);
    }
 	if ((inPopup == 1) && (inPopupClick == 0)) {
		var thisNumber = number + 1;
		if (thisNumber >= playList.length) { thisNumber = 0; }
		flash.audioPlayNumber(thisNumber);
    	top.opener.changeActivePlayList(thisNumber + 1);
 	}
 	if ((inPopup == 1) && (inPopupClick == 1)) {
		var nextNumber = 0;
		if (dir == 1) {
 			nextNumber = ArtistSongNumber + 1;
	 		if (nextNumber > numberOfSongs) {
				nextNumber = 1;
			}
 		}
		if (dir == -1) {
 			nextNumber = ArtistSongNumber - 1;
	 		if (nextNumber < 1) {
				nextNumber = numberOfSongs;
			}
 		}
		var playSongFunction = document.getElementById('ASList'+nextNumber).getAttribute('onclick');
		var oNumberId = document.getElementById('ASList'+nextNumber);
		if (LetterId[0] != oNumberId.parentNode.parentNode.parentNode.parentNode.getAttribute('id')[0]) {
			if (LetterId[0] == 'a') { 
       		  var letter = oNumberId.parentNode.parentNode.parentNode.parentNode.getAttribute('id').slice(-1);
			  var changeLetterFunction = document.getElementById('letterLink'+letter).getAttribute('href');
			  changeLetterFunction = changeLetterFunction.substring(11);
			  eval(changeLetterFunction);
			  showTab('Songs');
			  eval(playSongFunction);
			  return;
			}
			if (LetterId[0] == 's') { showTab('Artists'); }
		}
		if (LetterId != oNumberId.parentNode.parentNode.parentNode.parentNode.getAttribute('id')) {
			var letter = oNumberId.parentNode.parentNode.parentNode.parentNode.getAttribute('id').slice(-1);
			var changeLetterFunction = document.getElementById('letterLink'+letter).getAttribute('href');
			changeLetterFunction = changeLetterFunction.substring(11);
			eval(changeLetterFunction);
		}
		   if (ArtistLetterId != '') {
			if (ArtistLetterId != oNumberId.parentNode.parentNode.parentNode.getAttribute('id')) {
				var id = oNumberId.parentNode.parentNode.parentNode.getAttribute('id').substring(0,6)+'Link'+
				 oNumberId.parentNode.parentNode.parentNode.getAttribute('id').substring(6);
				var changeArtistFunction = document.getElementById(id).getAttribute('onclick');
				changeArtistFunction = changeArtistFunction.substring(7);
				eval(changeArtistFunction);
			}
		  }
		eval(playSongFunction);
 	}
}
