// some variables to save
var currentPosition;
var currentVolume;
var currentItem;

// these functions are caught by the JavascriptView object of the player.
function sendEvent(typ,prm) { thisMovie("player").sendEvent(typ,prm); };
function getUpdate(typ,pr1,pr2,pid) {
    if(typ == "time") { currentPosition = pr1; }
    else if(typ == "volume") { currentVolume = pr1; }
    else if(typ == "item") { currentItem = pr1; setTimeout("getItemData(currentItem)",100); }
    var id = document.getElementById(typ);
    id.innerHTML = typ+ ": "+Math.round(pr1);
    pr2 == undefined ? null: id.innerHTML += ", "+Math.round(pr2);
    if(pid != "null") {
        document.getElementById("pid").innerHTML = "(received from the player with id <i>"+pid+"</i>)";
    }
};

// These functions are caught by the feeder object of the player.
function loadFile(obj) { thisMovie("player").loadFile(obj); };
function addItem(obj,idx) { thisMovie("player").addItem(obj,idx); }
function removeItem(idx) { thisMovie("player").removeItem(idx); }
function getItemData(idx) {
    var obj = thisMovie("player").itemData(idx);
    var nodes = "";
    nodes += "<span id='track-artist' style='color: #fff;'>Name: " + obj.title + "</span><br />";
    nodes += "<span id='track-album' style='color: #fff'>Artist: " + obj.author + "</span><br />";
    nodes += "<span id='track-artist' style='color: #fff'>Album: " + obj.category + "</span><br />";
    
    //for(var i in obj) { 
    //  nodes += "<li>"+i+": "+obj[i]+"</li>"; 
    //}
    document.getElementById("data").innerHTML = nodes;
    if (document.getElementById('add-to-playlist-block')) {
    document.getElementById('add-to-playlist-block').innerHTML = "<a href=\"#\" class=\"lightgray\" onclick=\"atpse('addtoplaylist','sharediv','embed');return false;\" onmouseover=\"icoMouseover1('add2playlist','pp');\" onmouseout=\"icoMouseout1('add2playlist','pp');\"><img src=\"/images/music_playlists/ico-add-2-playlist.gif\" width=\"22\" height=\"22\" border=\"0\" alt=\"Add to Playlist\" title=\"Add to Playlist\" id=\"pp\"><span id=\"add2playlist\" style=\"display:none;text-decoration:none;\" class=\"white\"><b>Add to Playlist</b></span></a>";
		    
    document.getElementById('report-abuse-block').innerHTML = " <a href='/report/abuse/" + obj.id +"' id='track-abuse-link' onmouseover=\"icoMouseover5('reportabuse','rpab');\" onmouseout=\"icoMouseout5('reportabuse','rpab');\"><img src=\"/images/music_playlists/ico-report-abuse.gif\" alt=\"Report Abuse\" title=\"Report Abuse\" border=\"0\" height=\"22\" width=\"22\" id=\"rpab\"><span id=\"reportabuse\" style=\"display:none;text-decoration:none;\" class=\"white\"><b>Report Abuse</b></span></a>";
          new Control.Modal('track-abuse-link', {height: 445});

	
		document.getElementById('embed_source_block').innerHTML="<a href=\"#\" class=\"lightgray\" onclick=\"atpse('embed','addtoplaylist','sharediv');return false;\" onmouseover=\"icoMouseover3('embedt','ei');\" onmouseout=\"icoMouseout3('embedt','ei');\"><img src=\"/images/music_playlists/ico-embed.gif\" alt=\"Embed\" title=\"Embed\" id=\"ei\" border=\"0\" height=\"22\" width=\"22\"><span id=\"embedt\" style=\"display: none;text-decoration:none;\" class=\"white\"><b>Embed</b></span></a>"
		
		
     //new Control.Modal('track-link', {height: 100});
     }
     if (document.getElementById('playlist_track_id')) {
      document.getElementById("playlist_track_id").value=obj.id;
     }
     
     if (document.getElementById('playlist_track_no')) {
      document.getElementById("playlist_track_no").value=obj.id;
     }
     
    if (document.getElementById('embed_track_id')) {
      document.getElementById("embed_track_id").value=obj.id;
     }
    
     if (document.getElementById('share_track_id')) {
      document.getElementById("share_track_id").value=obj.id;
     }
    
    if(document.getElementById('track_info')){
	  new Ajax.Request("/listen/findtrackuser/"+obj.id, {asynchronous:true,onComplete:function(request){Element.hide('ajax_spinnerimg');},onLoading:function(request){Element.show('ajax_spinnerimg');}});
    }
    /* jayashree commented
     if(document.getElementById('musicplayerbx')){
	  new Ajax.Request("/listen/find_relatedsongs_playlists/"+obj.id, {asynchronous:true,onComplete:function(request){Element.hide('rel_ajax_spinnerimg');},onLoading:function(request){Element.show('rel_ajax_spinnerimg');}});
          }*/
    
};
    

// This is a javascript handler for the player and is always needed.
function thisMovie(movieName) {
    if(navigator.appName.indexOf("Microsoft") != -1) {
        return window[movieName];
    } else {
        return document[movieName];
    }
};

function embed_src(source,track_type){
if(track_type==1){
  source = (source + $('embed_track_id').value);    
}
var embed="<embed src=\"http://"+window.location.host+"/flash/mp3player.swf\" flashvars=\"file="+source+"&backcolor=0x000000&autostart=true&allowfullscreen=true&allowscriptaccess=always&wmode=transparent&enablejs=true&javascriptid=player&width=250&height=180&allowscriptaccess=always&allowfullscreen=true&showeq=true&displayheight=40&backcolor=0x000000&frontcolor=0xffffff&lightcolor=0x0099CC&linktarget=_blank&shuffle=false&repeat=true\"    />"
$('embedForm').value=embed;
$('directshare').value=source.replace("xspf","listen");

}

function share_src(source,track_type){
if(track_type==1){
  source = (source + $('share_track_id').value);  
}
$('share_track_url').value=source;

}

function admin_slim_player(url)
{
   if (document.getElementById('preview_button')) {  
      document.getElementById('preview_button').innerHTML = "<object type=\"application/x-shockwave-flash\"\n\" data=\"/flash/xspf_player_slim.swf?&container_id[equal tongue]review_button&button_width=17&button_height=17&menu_width=311&menu_height=206&song_url="+url+"&m_colors=000000,ff00ff,666666,ffffff,ffff00,ff0000,0000ff&autoplay=true\" width=\"100%\" height=\"100%\">"+"<param name=\"movie\" value=\"/flash/xspf_player_slim.swf?&container_id[equal tongue]review_button&button_width=17&button_height=17&menu_width=311&menu_height=206&song_url="+url+"&m_colors=000000,ff00ff,666666,ffffff,ffff00,ff0000,0000ff&autoplay=true\" /><param name=\"wmode\" value=\"transparent\" /></object>";
      return false
   }
}