/*
 * jQuery Woodojo - custom jQuery functions for the Jamroom Woodojo Skin/Theme
 * copyright 2003-2008 by Talldude Networks LLC
 * author Brian Johnson - bigguy@jamroom.net
 * $Id: jquery.nova.js,v 1.2 2010/05/16 14:53:32 bigguy Exp $
 */

function jrLoad(id,url,round_id,round_num) {
  if (typeof url == "undefined") {
    return false;
  }
  if (url == 'blank') {
    $(id).hide();
  }
  else if (id == '#hidden') {
    $(id).hide();
    $(id).load(url);
  }
  else {
    if (id == '#rank') {
      var t = $('#rank').height();
      if (t == null) {
        $('#main').html('<div class="inner"><div id="rank"></div></div>');
      }
    }
    var h = $(id).height();
    if (h > 150) {
      $(id).height(h);
    }
    $(id).fadeTo(100,0.5,function() {
      if (id == '#login') {
        $(id).html('<img src="'+ jamroom_url +'/skins/Woodojo/images/loading.gif">');
      }
      else {
        $(id).html('<img src="'+ jamroom_url +'/skins/Woodojo/images/loading.gif" style="margin:15px;">');
      }
      $(id).load(url,function() {
        var l = $(id).text();
        if (l.length < 1 && id != '#player') {
          $(id).html('');
        }
        if (h > 150) {
          $(id).height('100%');
        }
        if (round_id && round_num > 0) {
          $(id).fadeTo(100,1.00,function() {
            if (jQuery.browser.msie) {
              this.style.removeAttribute('filter');
            }
            $(round_id).corner(round_num +'px');
          });
        }
        else {
          $(id).fadeTo(100,1,function() {
            if (jQuery.browser.msie) {
              this.style.removeAttribute('filter');
            }
          });
        }
      })
    });
  }
}



function jrSubmitRating(id,rate_num,target_div) {
  $(id +' input').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();
  if (rate_type == 'band') {
    var div = '#prform';
  }
  else {
    var div = '#rform';
  }
  $(div).fadeOut(100,function() {
    $(div).text(message);
    $(div).removeClass('results_error');
    $(div).removeClass('results_success');
    $(div).addClass('results_'+ message_type);
  });
  if (message_type == 'success') {
    $('#current_rating').css('width',rate_percent +'%');
  }
  $(div).fadeIn('slow');
}

function jrHideComments() {
  $('#cform').hide();
  $('#comments_t').hide();
  $('#comments').hide();
  $('#your_comment').hide();
}

function jrShowComments(type,type_id) {
  jrResetResults();
  $('#comments_t').show();
  $('#comments').show();
  $('#your_comment').show();
  if (type) {
    $('#comment_type').val(type);
    if (type_id) {
      $('#comment_type_id').val(type_id);
    }
    jrLoad('#comments',artist_url +'index.php?t=video_comments&vid='+ type_id );
  }
  else {
    $('#comment_type').val('band');
    jrLoad('#comments', artist_url +'index.php?t=video_comments&vid='+ type_id );
  }
}

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 type         = $('comment_type',responseXML).text();
  var type_id      = $('comment_type_id',responseXML).text();
  var message_type = $('message_type',responseXML).text();
  var message      = $('message',responseXML).text();
  if (type == 'band') {
    jrLoad('#comments',artist_url +'comments.php');
  }
  else {
    var page = artist_url +'index.php?t=video_comments&vid='+ type_id;
    jrLoad('#comments',page);
  }
  $('#cform').fadeOut(100,function() {
    $('#cform').text(message);
    if (message_type == 'success') {
      $('#comment_form').clearForm();
    }
    $('#cform').removeClass('results_error');
    $('#cform').removeClass('results_success');
    $('#cform').addClass('results_'+ message_type);
  });
  $('#cform').fadeIn('slow');
}
