/***********************************************
* Pop-it menu- © Dynamic Drive (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/

var defaultMenuWidth="150px" //set default menu width.
var requestAction = 'none';

////No need to edit beyond here

var ie5=document.all && !window.opera
var ns6=document.getElementById
var isInternetExplorer = navigator.appName.indexOf("Microsoft") != -1;
// Handle all the the FSCommand messages in a Flash movie
function mp3player_DoFSCommand(command, args) {
        var mp3playerObj = isInternetExplorer ? document.all.mp3player : document.mp3player;
        //
        // Place your code here.
        //
        if(command == "changetime") {
//                newwidth = args * 3;
//                document.getElementById('progressbar1').style.width = newwidth;
        } else if(command == "shake") {
                shake(10);
        }
}
if (navigator.appName && navigator.appName.indexOf("Microsoft") != -1 && navigator.userAgent.indexOf("Windows") != -1 && navigator.userAgent.indexOf("Windows 3.1") == -1) {
        document.write('<script language=\"VBScript\"\>\n');
        document.write('On Error Resume Next\n');
        document.write('Sub mp3player_FSCommand(ByVal command, ByVal args)\n');
        document.write('        Call mp3player_DoFSCommand(command, args)\n');
        document.write('End Sub\n');
        document.write('</script\>\n');
}
function getFlashMovieObject(movieName)
{
  if (window.document[movieName])
  {
      return window.document[movieName];
  }
  if (navigator.appName.indexOf("Microsoft Internet")==-1)
  {
    if (document.embeds && document.embeds[movieName])
      return document.embeds[movieName];
  }
  else // if (navigator.appName.indexOf("Microsoft Internet")!=-1)
  {
    return document.getElementById(movieName);
  }
}
function changeSong(videoID)
{
        var url = 'http://bluelaguna.net/scripts/generatexml.php?type=mp3s&videoid=' + videoID;
        //var videoID = $F('playlist');
        var flashMovie=getFlashMovieObject("mp3player");
        flashMovie.SetVariable("/:videoid",videoID);
}

if (ie5||ns6)
document.write('<div id="popitmenu" onMouseover="clearhidemenu();" onMouseout="dynamichide(event)"></div>')

function iecompattest(){
return (document.compatMode && document.compatMode.indexOf("CSS")!=-1)? document.documentElement : document.body
}
// function adddlqueue(dlurl){
// 	var timeToKeep = 2592000;
// 	var expires = new Date();
// 	expires.setTime(expires.getTime() + timeToKeep);
// 	var dlarray = init_array(); // if it isn't already defined
// 	get_array("dlarray", dlarray);
// 	var num = next_entry(dlarray);
// 	dlarray[num] = dlurl;
// 	set_array("dlarray", dlarray, expires);
// 	return false;
// }
function showmenu(e, id, userid, listid, songhash){
if (!document.all&&!document.getElementById)
return
clearhidemenu()
// var dlarray = init_array(); // if it isn't already defined
// get_array("dlarray", dlarray);
var menuitems = "<h2>Options:</h2><ul>"
menuitems += "<li onclick='changeSong(" + id + ");'>Stream / Preview</li>"
//menuitems += "<li><a href='" + dlurl + "'>Download</a></li>"
menuitems += "<li onclick='addSong(" + userid + "," + listid + "," + id + ")'>Add to Playlist</li>";

//	menuitems += "<li><a href='#' onClick=\"adddlqueue('" + dlurl + "');\">Add to Queue</a></li>"

menuobj=ie5? document.all.popitmenu : document.getElementById("popitmenu")
menuobj.innerHTML=menuitems + "</ul>"
menuobj.style.width= defaultMenuWidth
menuobj.contentwidth=menuobj.offsetWidth
menuobj.contentheight=menuobj.offsetHeight
eventX=ie5? event.clientX : e.clientX
eventY=ie5? event.clientY : e.clientY
//Find out how close the mouse is to the corner of the window
var rightedge=ie5? iecompattest().clientWidth-eventX : window.innerWidth-eventX
var bottomedge=ie5? iecompattest().clientHeight-eventY : window.innerHeight-eventY
//if the horizontal distance isn't enough to accomodate the width of the context menu
if (rightedge<menuobj.contentwidth)
//move the horizontal position of the menu to the left by it's width
menuobj.style.left=ie5? iecompattest().scrollLeft+eventX-menuobj.contentwidth+"px" : window.pageXOffset+eventX-menuobj.contentwidth+"px"
else
//position the horizontal position of the menu where the mouse was clicked
menuobj.style.left=ie5? iecompattest().scrollLeft+eventX+"px" : window.pageXOffset+eventX+"px"
//same concept with the vertical position
if (bottomedge<menuobj.contentheight)
menuobj.style.top=ie5? iecompattest().scrollTop+eventY-menuobj.contentheight+"px" : window.pageYOffset+eventY-menuobj.contentheight+"px"
else
menuobj.style.top=ie5? iecompattest().scrollTop+event.clientY+"px" : window.pageYOffset+eventY+"px"
menuobj.style.visibility="visible"
return false
}

function contains_ns6(a, b) {
//Determines if 1 element in contained in another- by Brainjar.com
while (b.parentNode)
if ((b = b.parentNode) == a)
return true;
return false;
}

function hidemenu(){
if (window.menuobj)
menuobj.style.visibility="hidden"
}

function dynamichide(e){
if (ie5&&!menuobj.contains(e.toElement))
hidemenu()
else if (ns6&&e.currentTarget!= e.relatedTarget&& !contains_ns6(e.currentTarget, e.relatedTarget))
hidemenu()
}

function delayhidemenu(){
delayhide=setTimeout("hidemenu()",500)
}

function clearhidemenu(){
if (window.delayhide)
clearTimeout(delayhide)
}
function makeRequest(url){
        http_request = false;
        if (window.XMLHttpRequest) { // Mozilla, Safari,...
        http_request = new XMLHttpRequest();
        if (http_request.overrideMimeType) {
                        http_request.overrideMimeType('text/xml');
                        // See note below about this line
        }
        } else if (window.ActiveXObject) { // IE
        try {
                http_request = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
                try {
                http_request = new ActiveXObject("Microsoft.XMLHTTP");
                } catch (e) {}
        }
        }
        if (!http_request) {
        alert('Giving up :( Cannot create an XMLHTTP instance');
        return false;
        }
        http_request.onreadystatechange = showResponse;
        http_request.open('GET', url, true);
        http_request.send(null);
}
function showResponse(){
	if(requestAction == 'addsong'){
		alert('song added');
	}
}
function addSong(userid, listid, songid){
	var url
	url = 'http://bluelaguna.net/scripts/playlist.php?action=addsong&userid=' + userid + '&listid=' + listid + '&songid=' + songid;
	makeRequest(url);
}
function addAlbum(album){
	var url
	url = 'http://bluelaguna.net/scripts/playlist.php?action=addalbum&album=' + album;
	makeRequest(url);
	alert('Playlist Created');
}
if (ie5||ns6)
document.onclick=hidemenu
