﻿// JScript File
/*----------------------- Playing a song ------------------------------*/
// ajax call to play media
function showAjaxPopUp(mediaId)
{
    var url = 'ajax.aspx';
    var parms = 'method=GetMedia&mediaId='+mediaId;
    var myAjax = new Ajax.Request(url, {method: 'get', parameters: parms, onSuccess: ajaxPopUp, onFailure: ajaxPopUpFailure} );
}
function ajaxPopUp(request)
{
    var popUp = document.getElementById('PopUp');
    var artistImage = document.getElementById('ArtistImage');
    var popUpArtistName = document.getElementById('PopUpArtistName');
    var popUpSongTitle = document.getElementById('PopUpSongTitle');
    var popUpLinerNote = document.getElementById('PopUpLinerNote');
    var popUpPlayer = document.getElementById('PopUpPlayer');
    var newY = (getClientHeight() / 2) - 139;
    var newX = (getClientWidth() / 2) - 141;

    var response = request.responseText;
    var returnValues = response.split('|');
    var artist = returnValues[0];
    var songTitle = returnValues[1];
    var liner = returnValues[2];
    var img = returnValues[3];
    var mediaSrc = returnValues[4];

/*
    if ((newX + parseInt(popUp.style.width)) > getClientWidth()) {
        newX -= parseInt(popUp.style.width);
    }
    if ((newY + parseInt(popUp.style.height)) > getClientHeight()){
        newY -= parseInt(popUp.style.height);
    }
*/
    artistImage.style.background = 'url(http://media.premierstudios.com/artistovation/images/thumb/' + img + ')';
    popUpSongTitle.innerHTML = songTitle + "<br /><span class='LinerNote'>" + liner + "</span>";
    popUpArtistName.innerHTML = artist;
    popUpPlayer.innerHTML = "<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' id='player' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0' width='240' height='69' id='flashobject'><param name='movie' value='http://media.premierstudios.com/ArtistOvation/flash/AOMediaPlayer.swf' /><param name='quality' value='high' /><param name='flashVars' value='mediaFile=http://media.premierstudios.com/artistovation/songs/"+mediaSrc+"' /><embed src='http://media.premierstudios.com/ArtistOvation/flash/AOMediaPlayer.swf' quality='high' width='240' height='69' flashVars='mediaFile=http://media.premierstudios.com/artistovation/songs/"+mediaSrc+"' id='flashembed' allowscriptaccess='sameDomain' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' /></object>";
    
    popUp.style.display = 'block';
    popUp.style.position = 'absolute';
    popUp.style.top = newY+'px';
    popUp.style.left = newX+'px';
}
function ajaxPopUpFailure(request)
{
    alert("There was an error retrieving the song requested.");
}
function showPopUp(link,artist,songTitle,liner,img,mediaSrc,mediaId, rating) {
    var popUp = document.getElementById('PopUp');
    var artistImage = document.getElementById('ArtistImage');
    var popUpArtistName = document.getElementById('PopUpArtistName');
    var popUpSongTitle = document.getElementById('PopUpSongTitle');
    var popUpLinerNote = document.getElementById('PopUpLinerNote');
    var popUpPlayer = document.getElementById('PopUpPlayer');
    var newY = findPosY(link)+5;
    var newX = findPosX(link)+8;

    if ((newX + parseInt(popUp.style.width)) > getClientWidth()) {
        newX -= parseInt(popUp.style.width);
    }
    if ((newY + parseInt(popUp.style.height)) > getClientHeight()){
        newY -= parseInt(popUp.style.height);
    }
    
    artistImage.style.background = 'url(http://media.premierstudios.com/artistovation/images/thumb/' + img + ')';
    popUpSongTitle.innerHTML = songTitle + "<br /><span class='LinerNote'>" + liner + "</span>";
    popUpArtistName.innerHTML = artist;
    popUpPlayer.innerHTML = "<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' id='player' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0' width='240' height='69' id='flashobject'><param name='movie' value='http://media.premierstudios.com/ArtistOvation/flash/AOMediaPlayer.swf' /><param name='quality' value='high' /><param name='flashVars' value='mediaFile=http://media.premierstudios.com/artistovation/songs/"+mediaSrc+"' /><embed src='http://media.premierstudios.com/ArtistOvation/flash/AOMediaPlayer.swf' quality='high' width='240' height='69' flashVars='mediaFile=http://media.premierstudios.com/artistovation/songs/"+mediaSrc+"' id='flashembed' allowscriptaccess='sameDomain' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' /></object>";
    
    popUp.style.display = 'block';
    popUp.style.position = 'absolute';
    popUp.style.top = newY+'px';
    popUp.style.left = newX+'px';
}
function hidePopUp() {
    var popUp = document.getElementById('PopUp');
    var popUpPlayer = document.getElementById('PopUpPlayer');
    popUpPlayer.innerHTML = '';
    popUp.style.display = 'none';
}
function findPosX(obj) {
    var curLeft = 0;
    if (obj.offsetParent) {
        curLeft = obj.offsetLeft;
        while (obj = obj.offsetParent) {
            curLeft += obj.offsetLeft;
        }
    } 
    return curLeft;
}
function findPosY(obj) {
    var curTop = 0;
    if (obj.offsetParent) {
        curTop = obj.offsetTop;
		while (obj = obj.offsetParent) {
			curTop += obj.offsetTop;
		}
	}
	return curTop;
}
function getClientHeight() {
    var __returnValue = isSF ? window.innerHeight : document.documentElement.clientHeight;
    return __returnValue;
}
function getClientWidth() {
    var __returnValue = isSF ? window.innerWidth : document.documentElement.clientWidth
    return __returnValue;
}
