// JavaScript Document

/**
 * @version		1.0.1
 * @package		muscol
 * @copyright	2009 JoomlaMusicSolutions.com
 * @license		GPLv2
 */
 
var muscol_player_plugin_loaded = true;

function add_song_to_playlist(song_id,playlist_id,type)
{
var xmlHttp;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    try
      {
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    catch (e)
      {
      alert("Your browser does not support AJAX!");
      return false;
      }
    }
  }
  xmlHttp.onreadystatechange=function()
    {
    if(xmlHttp.readyState==4)
      {
	
	  if(muscol_player_module_loaded){
		  //if the module player exists, we refresh it
		  new_items = true;
		  popup_new_items = true;
		  if(popup_active && (!popWin)){ // if the popup is active but we havent reloaded it yet
			initialize_popup_variables(popup_url);
		  }
		  if ((popWin) && (! popWin.closed)) {popWin.new_items = true;}
		  
		  reload_if_possible();
		  }
	
      }
    }
  //xmlHttp.open("GET","puntua.php?points="+points+"&album_id="+album_id,true);
  xmlHttp.open("GET","index2.php?option=com_muscol&task=add_song_to_playlist&id=" + playlist_id + "&song_id=" + song_id + "&type=" + type,true);
  xmlHttp.send(null);
  }
  
  function reload_playlist(){
		new_items = false;
		popup_new_items = false;

		if ((popWin)&&(! popWin.closed)) { // we update the playlist on the popup player. SUPER COOL
			popWin.new_items = false;
			popWin.module_jwplayer.sendEvent('STOP'); 	
			popWin.module_jwplayer.sendEvent('LOAD',  	current_playlist_url );	
		}
		else{
			module_jwplayer.sendEvent('STOP'); 	
			module_jwplayer.sendEvent('LOAD',  	current_playlist_url );
		}
  }
  
  function reload_if_possible(){
	  if ((popWin)&&(! popWin.closed)) {
		  popWin.reload_if_possible();
	  }
	  else{
		  if( (currentState == "COMPLETED") || (currentState == "IDLE") ){
				reload_playlist();  
		  }
	  }
  }
  
  