/*
 * jQuery JamTube - custom jQuery functions for the Jamroom JamTube Skin/Theme
 * copyright 2003-2009 by Talldude Networks LLC
 * author Brian Johnson - bigguy@jamroom.net
 * $Id: jquery.jamtube.js,v 1.1.1.1 2009/05/30 15:34:45 bigguy Exp $
 */

function jrLoad(id,url) {
  if (typeof url == "undefined") {
    return false;
  }
  if (url == 'blank') {
    $(id).hide();
  }
  else if (id == '#hidden') {
    $(id).hide();
    $(id).load(url);
  }
  else {
    var h = $(id).height();
    if (h > 150) {
      $(id).height(h);
    }
    $(id).fadeTo(100,0.5,function() {
      $(id).html('<img src="'+ jamroom_url +'/skins/JamTube/images/loading.gif" style="margin:10px;">');
      $(id).load(url,function() {
        var l = $(id).text();
        if (l.length < 1 && id != '#player') {
          $(id).html('');
        }
        if (h > 150) {
          $(id).height('100%');
        }
        $(id).fadeTo(100,1,function() {
          if (jQuery.browser.msie) {
            this.style.removeAttribute('filter');
          }
        })
      })
    });
  }
}

function jrSubmitComment() {
  var r_options = {
    target: '#cform',
    dataType: 'xml',
    success: jrProcessCommentXML
  };
  $('#comment_form').ajaxSubmit(r_options);
}
function jrProcessCommentXML(responseXML) {
  // 'responseXML' is the XML document returned by the server; we use
  // jQuery to extract the content of the message node from the XML doc
  var message_type = $('message_type',responseXML).text();
  var message      = $('message',responseXML).text();
  var band_id      = $('comment_type_id',responseXML).text();
  $('#cform').fadeOut(100,function() {
    $('#cform').text(message);
    if (message_type == 'success') {
      jrLoad('#comment_browser',jamroom_url +'/ranking.php?mode=comment&type=band&band_id='+ band_id +'&row_template=theme_index_comment_row.tpl&tpl_dir=theme&theme=JamTube&pagebreak=3');
    }
    else {
      $('#cform').removeClass('results_error');
      $('#cform').removeClass('results_success');
      $('#cform').addClass('results_'+ message_type);
      $('#cform').fadeIn('slow');
    }
  });
}

function jrSubmitFanForm() {
  var r_options = {
    target: '#fanform',
    dataType: 'xml',
    success: jrProcessFanXML
  };
  $('#fan_form').ajaxSubmit(r_options);
}
function jrProcessFanXML(responseXML) {
  // 'responseXML' is the XML document returned by the server; we use
  // jQuery to extract the content of the message node from the XML doc
  var message_type = $('message_type',responseXML).text();
  var message      = $('message',responseXML).text();
  $('#fanform').fadeOut(100,function() {
    $('#fanform').text(message);
    $('#fanform').removeClass('results_error');
    $('#fanform').removeClass('results_success');
    $('#fanform').addClass('results_'+ message_type);
    $('#fanform').fadeIn('slow');
  });
}

function jrSubmitRating(id,rate_num,target_div) {
  $(id +' #rate_num').val(rate_num);
  var r_options = {
    target: target_div,
    dataType: 'xml',
    success: jrProcessRatingXML
  };
  $(id).ajaxSubmit(r_options);
}
function jrProcessRatingXML(responseXML) {
  var message_type = $('message_type',responseXML).text();
  var message      = $('message',responseXML).text();
  var rate_percent = $('rate_percent',responseXML).text();
  var rate_type    = $('rate_type',responseXML).text();
  $('#rform').fadeOut(100,function() {
    $('#rform').text(message);
    $('#rform').removeClass('results_error');
    $('#rform').removeClass('results_success');
    $('#rform').addClass('results_'+ message_type);
  });
  if (message_type == 'success') {
    $('#current_rating').css('width',rate_percent +'%');
  }
  $('#rform').fadeIn('slow');
}

