
// var current_id = 0;


function tagClick (event, assoc_id, type, context  ) {

      if ( token == '' )
      {
          return;
      } 

  var show_agg = -1;

  current_id = assoc_id;
  var fl = document.getElementById('tagger1');
  fl.style.position = 'absolute';
  var inputEl = did('tag_img_'+assoc_id + '_' + type + '_' + context);
  var pos = Position.get(inputEl);

  fl.style.top = (pos.top + pos.height) + 'px';
  fl.style.left = pos.left - 200 + 'px';
  fl.style.visibility= 'visible';  

  did('tagger_assoc_id').value = assoc_id;
  did('tagger_type').value = type;
  did('tagger_context').value = context;
  sendRequest('LoadTags|' + token + '|' + assoc_id + '|' + type + ',' + context + ',' + show_agg);
  setOverlay(true);

}

function xratingClick(event, album_id) { 

     dismissOwnership ();
     current_id = album_id;
     var fl = document.getElementById('miniratedlg');
     var inputEl = did('rate_'+album_id);
     var pos = Position.get(inputEl);
 
     fl.style.top = (pos.top + pos.height) + 'px';
     fl.style.left = pos.left + 'px';
     fl.style.visibility= 'visible';  
}

function xownershipClick(event, album_id) { 

     dismissRating ();
     current_id = album_id;
     var fl = document.getElementById('miniownershipdlg');
     var inputEl = did('ownership_img_'+album_id);
     var pos = Position.get(inputEl);
 
     fl.style.top = (pos.top + pos.height)+ 'px';
     fl.style.left = pos.left  - 100 + 'px';
     fl.style.visibility= 'visible';  
}

function supdateItemOwnership (album_id, ownership, format)
{
   if ( ownership == 'n' )
   {
     did('ownership_img_'+ album_id ).src = '/images/fmt/cde.gif';
   }
   else
   {
      if ( format == '' )
      {
        did('ownership_img_'+ album_id ).src = '/images/fmt/cdf.gif';
      }
      else
      {
         did('ownership_img_'+ album_id ).src = '/images/fmt/' + format.toLowerCase() + '.gif';
      }
   } 
   if ( ownership == 'w' )
   {
      did('ownership_img_'+ album_id ).style.background='url("/images/fmt/bgwish.gif")';
   }
   if ( ownership == 'u' )
   {
      did('ownership_img_'+ album_id ).style.background='url("/images/fmt/bgused.gif")';
   }

}


var g_rgFormatMusic = new Array('CD','LP','Cassette','Minidisc','MP3','DVD-A','SACD','8-Track','CD-R','Other');
var g_rgFormatVideo = new Array('DVD','VHS','Other');


function xupdateFormat ( album_id, format )
{
   if ( format == '' )
   {
     did('ownership_img_'+ album_id ).src = '/images/fmt/cde.gif';
   }
   else
   {
      did('ownership_img_'+ album_id ).src = '/images/fmt/' + format.toLowerCase() + '.gif';
   }

   for ( var i in g_rgFormatMusic )
   {
      did('format_link' + g_rgFormatMusic[i] ).className = (g_rgFormatMusic[i] == format) ? 'ownbuttonhc' : 'ownbutton';
      if ( g_rgFormatMusic[i] == format )
      {
         if ( 'LP' == format )
         {
            format = 'Vinyl';
         }
    }
   }
   for ( var i in g_rgFormatVideo )
   {
      did('format_link' + g_rgFormatVideo[i] ).className = (g_rgFormatVideo[i] == format) ? 'ownbuttonhc' : 'ownbutton';
      if ( g_rgFormatVideo[i] == format )
      {
      }
   }
}

function xupdateTags ( album_id, type, context, tags )
{ 
   
   if ( tags == '' )
   {
     did('tag_img_'+ album_id + '_' + type + '_' + context ).src = 'http://static.rateyourmusic.com/images/tage.gif';
   }
   else
   {
      did('tag_img_'+ album_id + '_' + type + '_' + context ).src = 'http://static.rateyourmusic.com/images/tagf.gif';
   }
   if ( did('taglist_' + album_id + '_' + type + '_' + context ) )
   {
      did('taglist_' + album_id + '_' + type + '_' + context).innerHTML = tags;
   }
}

function xsetItemOwnership (album_id, ownership )
{
   did('ownership_img_' + album_id).src = '/images/loading.gif';
   sendRequest('Ownership|' + token + '|' + album_id + '|' + ownership);
}

function xsetFormat (album_id, format)
{
   did('ownership_img_' + album_id).src = '/images/loading.gif';
   sendRequest('Format|' + token + '|' + album_id + '|' + format);

}


function xrateItem (album_id, rating)
{
   did('rate_' + album_id).src = '/images/loading.gif';
   sendRequest('Rate|' + token + '|' + album_id + '|' + rating);
}


function xdisplayrating (album_id , rating ) { 

   if ( rating == 0 ) 
   {
      did('rate_' + album_id).src = '/images/stare.gif';
      did('ratetext_' + album_id).innerHTML = '&nbsp;&nbsp;&nbsp;'; 
   }
   else
   {
      did('rate_' + album_id).src = '/images/starf.gif';
      did('ratetext_' + album_id).innerHTML = (rating/2).toFixed(1); 
   }
   dismissRating ();
}


function xdismissRating ()
{
   var fl = document.getElementById('miniratedlg');
   fl.style.visibility= 'hidden'; 
}

function xdismissOwnership ()
{
   var fl = document.getElementById('miniownershipdlg');
   fl.style.visibility= 'hidden'; 
}

 function toggleSub(assoc_id, type, context, last_id, el)
 {
     did('sub_' + assoc_id + '_' + type + '_' + context  ).src='/images/loading.gif'
     sendRequest('Subscription|' + token + '|' + assoc_id + '|' + type + '|' + context + '|' + last_id);
 }

 function toggleFav(assoc_id, type, context, el)
 {
     did('fav_' + assoc_id + '_' + type + '_' + context).src='/images/loading.gif'
     sendRequest('Favorite|' + token + '|' + assoc_id + '|' + type + '|' + context);
 }
