$(document).ready(function () {
  $('#profilePlaylistSearchTerm').watermark('Search');
  
  //Appending click events
  $('body').live('click', function (event) {
    //If the user clicked within the global play list do not close it
    //Hide play list only when user clicked outside the parent DIV
    if ($(event.target).parents('#ajaxGlobalPlaylist').length != 1) {
      $('#ajaxGlobalPlaylist').hide();
      $('#globalPlaylistNewPlaylistContainer').hide();
    }
	if ($(event.target).parents('#ajaxGlobalPlaylist_vid').length != 1) {
      $('#ajaxGlobalPlaylist_vid').hide();
      $('#globalPlaylistNewPlaylistContainer_vid').hide();
    }
  });

    //add multiple select boxes
  $('#addgenres').click(function () {
    $('#addgenre').toggle();
  });
  
  jQuery.fn.input = function () {
    var strType = '';
    
    return this.each(function () {
      if (this.type == 'password') {
        strType = this.type;
        this.type = 'text';
      }
    }).focus(function () {
      if (strType == 'password') {
        this.type = 'password';
      }
      if (this.value == this.defaultValue)
        this.value = '';
    }).blur(function () {
      if (isEmpty(this.value)) {
        if (this.type == 'password') {
          this.type = 'text';
        }
        this.value = this.defaultValue;
      }
    });
  };
  
  /*
  GlobalAddToPlaylist.init('addToPlaylist, addedToPlaylist');
  
  var GlobalAddToPlaylist = function () {
    init: function (selectors) {
      var objOffset = $(this).offset();
      var songID = $(this).attr('id');
      
      $('#ajaxGlobalPlaylist').find('#ajaxAllPlaylists').empty();
      $(':hidden#globalPlaylistAddSong').val(songID);
      
      $('#ajaxGlobalPlaylist').css({'top' : objOffset.top,
                                    'left' : objOffset.left - 200
                                  }).fadeIn('fast', function () {
                                            $(this).find('#loadingTxt').show();
                                            var objSelf = $(this); 
      
                                            $.ajax({
                                              type: 'POST',
                                              dataType: 'json',
                                              cache: false,
                                              url: 'ajax/ajax.getPlaylists.php',
                                              success: function (json) {
                                                var html = '';
                                                for(j in json)
                                                  html += '<div class="globalPlaylistContainer" id="'+json[j].id+'"><a href="#">'+json[j].name+'</a></div>';
                                              
                                                objSelf.find('#loadingTxt').hide();
                                                objSelf.find('#ajaxAllPlaylists').html(html);
                                              }
                                            });
                                        });
      return false;
    };
  };*/
  
  //Show the global playlist
  $('.ajaxAddToPlaylist').live('click', function () {
    var objOffset = $(this).offset();
    var songID = $(this).attr('id');
    
    $('#ajaxGlobalPlaylist').find('#ajaxAllPlaylists').empty();
    $(':hidden#globalPlaylistAddSong').val(songID);
    
    $('#ajaxGlobalPlaylist').css({'top' : objOffset.top,
                                  'left' : objOffset.left - 200
                            }).fadeIn('fast', function () {
                              $(this).find('#loadingTxt').show();
                              var objSelf = $(this); 
                              
                              $.ajax({
                                type: 'POST',
                                dataType: 'json',
                                cache: false,
                                url: 'ajax/ajax.getPlaylists.php',
                                success: function (json) {
                                  var html = '';
                                  for(j in json)
                                    html += '<div class="globalPlaylistContainer" id="'+json[j].id+'"><a href="#">'+json[j].name+'</a></div>';
                                  
                                  objSelf.find('#loadingTxt').hide();
                                  objSelf.find('#ajaxAllPlaylists').html(html);
                                }
                              });
                            });
    return false;
    
  });
  
    //Show the global playlist
  $('.ajaxAddToPlaylist_vid').live('click', function () {
    var objOffset = $(this).offset();
    var songID = $(this).attr('id');
    
    $('#ajaxGlobalPlaylist_vid').find('#ajaxAllPlaylists_vid').empty();
    $(':hidden#globalPlaylistAddSong_vid').val(songID);
    
    $('#ajaxGlobalPlaylist_vid').css({'top' : objOffset.top,
                                  'left' : objOffset.left - 200
                            }).fadeIn('fast', function () {
                              $(this).find('#loadingTxt').show();
                              var objSelf = $(this); 
                              
                              $.ajax({
                                type: 'POST',
                                dataType: 'json',
                                cache: false,
                                url: 'ajax/ajax.getPlaylists_vid.php',
                                success: function (json) {
                                  var html = '';
                                  for(j in json)
                                    html += '<div class="globalPlaylistContainer_vid" id="'+json[j].id+'"><a href="#">'+json[j].name+'</a></div>';
                                  
                                  objSelf.find('#loadingTxt').hide();
                                  objSelf.find('#ajaxAllPlaylists_vid').html(html);
                                }
                              });
                            });
    return false;
    
  });
  
  //When the user clicks on this container, they want to add the current song to this play list
  $('.globalPlaylistContainer').live('click', function () {
    var playlistID = $(this).attr('id');
    var songID = $(':hidden#globalPlaylistAddSong').val();
    var objSelf = $(this);
    
    if (!isNaN(songID) && !isNaN(playlistID)) {
      //var addConfirm = confirm('Are you sure you want to add this song to your playlist?');
      if(playlistID){
    $.ajax({
      type: 'POST',
      data: 'songID=' +songID+ '&playListID=' +playlistID,
      cache: false,
      url: 'ajax/ajax.addToPlaylist.php',
      success: function (html) {
        if (html == 1) {
            objSelf.parent().parent().hide();
            $.gritter.add({
            	title: 'Playlist Notice!',
            	text: 'Successfully added song to playlist.',
              image: 'js/grumble/themes/smoke/success.png' //check image
            });
          $(".addsong-"+songID).removeClass('addToPlayList').addClass('addedToPlayList');
          
        }else{
            objSelf.parent().parent().hide();
            $.gritter.add({
            	title: 'Playlist Error!',
            	text: 'Song already added to this playlist.',
              image: 'js/grumble/themes/smoke/error.png' //check image
            });
        }
      }
    });
    }
    }
    return false;
  });
  
  //When the user clicks on this container, they want to add the current song to this play list
  $('.globalPlaylistContainer_vid').live('click', function () {
    var playlistID = $(this).attr('id');
    var songID = $(':hidden#globalPlaylistAddSong_vid').val();
    var objSelf = $(this);
    
    if (!isNaN(songID) && !isNaN(playlistID)) {
    $.ajax({
      type: 'POST',
      data: 'videoID=' +songID+ '&playListID=' +playlistID,
      cache: false,
      url: 'ajax/ajax.addToPlaylist_vid.php',
      success: function (html) {
        if (html == 1) {
          objSelf.parent().parent().hide();
          $.gritter.add({
            	title: 'Playlist Notice!',
            	text: 'Successfully added video to playlist.',
              image: 'js/grumble/themes/smoke/success.png' //check image
            });
        }else{
          objSelf.parent().parent().hide();
            $.gritter.add({
            	title: 'Playlist Error!',
            	text: 'Video already added to this playlist.',
              image: 'js/grumble/themes/smoke/error.png' //check image
            });
        }
      }
    });
    }
    return false;
  });
  
  //Show the container to create a new play list from the quick view
  $('#globalPlaylistNewPlaylistLink').live('click', function () {
    $('#globalPlaylistNewPlaylistContainer').toggle();
    
    return false;
  });
    //Show the container to create a new play list from the quick view
  $('#globalPlaylistNewPlaylistLink_vid').live('click', function () {
    $('#globalPlaylistNewPlaylistContainer_vid').toggle();
    
    return false;
  });
  
  //Handle the submit event to create a new play list through the quick play list view
  $('#globalPlaylistCreateForm').live('submit', function () {
    var strForm = $(this).serialize();
    var playListName = $(this).find('#globalPlaylistNewPlaylistName');
    var songID = $(this).find('#globalPlaylistAddSong').val();
    var objSelf = $(this);
    
    if (!isEmpty(playListName.val())) {
      $.ajax({
        type: 'POST',
        data: strForm,
        cache: false,
        url: 'ajax/ajax.createPlaylist.php',
        success: function (html) {
          if (html != 0) {
            objSelf.parent().hide();
            
            objSelf.find('#globalPlaylistNewPlaylistContainer')
                   .toggle()
                   .find('#globalPlaylistNewPlaylistName')
                   .val('');
            //init_player_set_playlist('' +songID+ '');
          }
        }
      });
    }
    return false;
  });
  
  //Handle the submit event to create a new play list through the quick play list view
  $('#globalPlaylistCreateForm_vid').live('submit', function () {
    var strForm = $(this).serialize();
    var playListName = $(this).find('#globalPlaylistNewPlaylistName_vid');
    var videoID = $(this).find('#globalPlaylistAddSong_vid').val();
    var objSelf = $(this);
    
    if (!isEmpty(playListName.val())) {
      $.ajax({
        type: 'POST',
        data: strForm,
        cache: false,
        url: 'ajax/ajax.createPlaylist_vid.php',
        success: function (html) {
          if (html != 0) {
            objSelf.parent().hide();
            
            objSelf.find('#globalPlaylistNewPlaylistContainer_vid')
                   .toggle()
                   .find('#globalPlaylistNewPlaylistName_vid')
                   .val('');
            //init_player_set_playlist('' +songID+ '');
          }
        }
      });
    }
    return false;
  });
  
  //Suggest to join the NA network function
  $('#suggestToJoinNA').live('click', function () {
    var parentDIV = $(this).parent();
    var email = parentDIV.find('.homeFindNewFriendEmail').text();
    
    $.ajax({
    type: 'POST',
    data: 'email='+email,
    url: 'ajax/ajax.suggestJoinNA.php',
    global: false, 
    success: function (html) {
      if (html == 1) {
        $.gritter.add({
            	title: 'Invitation Notice!',
            	text: 'Successfully sent invitation to: '+email,
              image: 'js/grumble/themes/smoke/success.png' //check image
            });
        parentDIV.fadeOut().remove();
      }
    }
    });
    return false;
  });
  
  //Artists Page - Menu control
  $('#artistsMenuTitle').click(function () {
    $('#artistsGenreLIs').toggle();
  }, function () {
    $('#artistsGenreLIs').hide();
  });
  
  //This function grabs all hidden fields that contain song ids to initilize the player
  
  var current_songID = $('#pl_stars > div', frames['top_frame']).attr('id');
  var globalPlayerPageSongs = current_songID;
  $(':hidden.jsPlayerSongID').each(function () {
    globalPlayerPageSongs += (globalPlayerPageSongs == '') ? '' +this.value+ '' : ',' +this.value+ '';
  });
    if (parent.frames.length > 0){
      parent.frames['top_frame'].init_player_items('' +globalPlayerPageSongs+ '');
    }
  
  
  //Add song to play list from the player view
  $('#globalPlayerAddToPlayListLink').live('click', function () {
    $('#globalPlayerAddToPlaylist').show();
    
    return false;
  });
  
    //remove song from playlist from the player view
  $('#removefrom_playlist').live('click', function () {
      var playlistID = $('.profileNewFavSongRm').attr('name');
      var songID = $('.ajaxGlobalPlayerCurrentSong').attr('id');
      var objSelf = $(this);
    
    $.ajax({
      type: 'POST',
      data: 'songID=' +songID+ '&playlistID=' +playlistID,
      cache: false,
      url: 'ajax/ajax.removeFromPlaylist.php',
      success: function (html) {
        $('#profilePlaylistSongContainer-' +songID).fadeOut();
      }
    });
  })
  
  //Show the playlists that you can add to from the player view
  $('#globalPlayerShowAddToPlaylists').hover(function () {
    $('#globalPlayerAddToPlaylistArea').show();
    $('#globalPlayerLoadingAddToPlayList').show();
    
    $.ajax({
      type: 'POST',
      dataType: 'json',
      cache: false,
      url: 'ajax/ajax.getPlaylists.php',
      success: function (json) {
        var html = '';
        for(j in json)
          html += '<div class="row globalPlayerAddToPlaylistFromSelect" id="'+json[j].id+'">'+json[j].name+'</div>';
        
        $('#globalPlayerLoadingAddToPlayList').hide();
        $('#globalPlayerAddToPlaylistSelect').html(html);
      }
    });
  }, function () {
    $('#globalPlayerAddToPlaylistArea').hide();
    $('#globalPlayerAddToPlaylistSelect').empty();
  });
  
  //Close add to play list DIV
  $('#globalPlayerCancelAddToPlaylist').live('click', function () {
    $(this).parent().parent().hide();
    $('#globalPlayerNewPlaylistName').val('');
  });
  
  //Show play list from the player
  $('#player_drop_down_playlist_link').hover(function () {
    $('#globalPlayerPlaylistHolder').show();
    $('#globalPlayerAjaxAllPlaylists').show();
    $('#globalPlayerLoadingPlayList').show();
    
    $.ajax({
      type: 'POST',
      dataType: 'json',
      cache: false,
      url: 'ajax/ajax.getPlaylists.php',
      success: function (json) {
        var html = '';
        for(j in json)
          html += '<div class="row ajaxGlobalPlayerPlaylist" id="'+json[j].id+'">'+json[j].name+'</div>';
        
        $('#globalPlayerLoadingPlayList').hide();
        $('#globalPlayerAjaxAllPlaylists').html(html);
      }
    });
  }, function () {
    $('#globalPlayerPlaylistHolder').hide();
    $('#globalPlayerAjaxAllPlaylists').empty();
  });
  
  //Select play list from the global player
  $('.ajaxGlobalPlayerPlaylist').live('click', function () {
    var playListID = $(this).attr('id');
    var playListName = $(this).text();
    var objParent = $(this).parent();
    
    if (!isNaN(playListID)) {
      $('#globalPlayerPlayListNameHolder').text(playListName);
      $(':hidden#globalPlayerCurrentLibrary').val(playListID);
      
      $.ajax({
        type: 'POST',
        data: 'playlistID=' +playListID,
        cache: false,
        url: 'ajax/ajax.getPlaylist.php',
        success: function (html) {
          if (html != 0) {
            init_player_set_playlist('' +html+ '');
            objParent.hide();
          }
        }
      });
    }
    return false;
  });
  
  //Become a fan
  $('.ajaxBecomeAFan').live('click', function () {
    var celebID = this.id;
    
    if (!isNaN(celebID)) {
      $.ajax({
        type: 'POST',
        data: 'celebID=' +celebID,
        cache: false,
        url: 'ajax/ajax.becomeAFan.php',
        success: function (html) {
          if (html == 1) {
            location.reload(true);
          }
        }
      });
    }
  });
  
  //Toggle the container to allow the user to create a new playlist
  $('#profileNewPlaylistCreator').live('click', function () {
    $('#profileNewPlaylistCreatorContainer').toggle();
  })
  
  //Handle the event to create a new play list from the profile section
  $('#profilePlaylistCreateNewPlaylist').live('submit', function () {
    var strForm = $(this).serialize();
    var playListName = $(this).find('#profilePlaylistNewPlaylistName');
    
    if (!isEmpty(playListName.val())) {
      $.ajax({
        type: 'POST',
        data: strForm,
        cache: false,
        url: 'ajax/ajax.createEmptyPlaylist.php',
        success: function (html) {
          if (html != 0) {
            $('#profileNewPlaylistCreatorContainer').toggle();
            $('#profileAllPlaylistsNav').append(html);
          }
        }
      });
    }
    return false;
  });
  
  //Delete a play list from the profile - playlist section
  $('.profilePlaylistRemoveButton').live('click', function () {
    var playListID = $(this).attr('id');
    
    if (!isNaN(playListID)) {
      var msgtxt ='Are you sure you want to delete this playlist?';
      jConfirm(msgtxt, 'Delete Playlist', function(r) {
              if(r){
                $.ajax({
                  type: 'POST',
                  data: 'playListID=' +playListID,
                  cache: false,
                  url: 'ajax/ajax.deletePlaylist.php',
                  success: function (userID) {
                    if (userID !== 0) {
                      window.location = 'http://www.newartist.com/profile.php?id='+userID+'&ref=playlists'
                    }
                  }
                });
              }
      });
    }
    return false;
  });
  
  //Delete a play list from the profile - playlist section
  $('.profilePlaylistRemoveButton_vid').live('click', function () {
    var playListID = $(this).attr('id');
    
    if (!isNaN(playListID)) {
      var msgtxt ='Are you sure you want to delete this playlist?';
      jConfirm(msgtxt, 'Delete Playlist', function(r) {
              if(r){
                $.ajax({
                  type: 'POST',
                  data: 'playListID=' +playListID,
                  cache: false,
                  url: 'ajax/ajax.deletePlaylist_vid.php',
                  success: function (userID) {
                    if (userID !== 0) {
                      window.location = 'http://www.newartist.com/profile.php?id='+userID+'&ref=playlists_vid'
                    }
                  }
                });
              }
      });
    }
    return false;
  });
  
  $('.profileMusicMakeDefault').live('click', function () {
    var songID = $(this).find('a:first').attr('id');
    
    $('.profileMusicMakeDefault').each(function () {
      $(this).find('a:first').text('Make Default');
    });
    $(this).find('a:first').text('Default Song');
    
    $.ajax({
      type: 'POST',
      data: 'songID=' +songID,
      cache: false,
      url: 'ajax/ajax.setDefaultSong.php',
      success: function (response) {
        //if (response == 1) {
          alert(response);
        //}
      }
    });
    
    return false;
  });
  
  //Delete video
  $('#profileVideoDeleteAction').live('click', function () {
    var songID = $(this).find('a').attr('id');
    var parentDIV = $(this).parent().parent().parent().parent();
    
    if (!isNaN(songID)) {
      var msgtxt ='Are you sure you want to delete this video?';
      jConfirm(msgtxt, 'Delete Video', function(r) {
              if(r){
        $.ajax({
          type: 'POST',
          data: 'songID=' +songID,
          cache: false,
          url: 'ajax/ajax.deleteVideo.php',
          success: function (response) {
            if (response == 1) {
              parentDIV.fadeOut().remove();
              
            }
          }
        });
      }});
    }
    return false;
  });
  
  //Make default Video
  $('#profileVideoDefaultAction').live('click', function () {
    var videoID = $(this).find('a').attr('id');
    var defvideoID = $("#profileVideoDefaultAction > a[class*='default']").attr('id');
    var parentDIV = $(this).parent().parent().parent().parent();
    
    if (!isNaN(videoID)) {
      //var deleteConfirm = confirm('Are you sure you want to delete this song?');
      
        $.ajax({
          type: 'POST',
          data: 'videoID=' +videoID,
          cache: false,
          url: 'ajax/ajax.makeDefaultVideo.php',
          success: function (html) {
            //if (response == 1) {
              $("#profileVideoDefaultAction > a[class*='default']").replaceWith("<a id=\"" + defvideoID + "\" href=\"#\">Make Default</a>");
              $("#profileVideoDefaultAction > a[id*='"+videoID+"']").replaceWith("<a class=\"default\" style=\"color: rgb(55, 201, 74);\" id=\"" + videoID + "\" href=\"#\">Default</a>");
              $.gritter.add({
            	title: 'Default Video Notice!',
            	text: 'Successfully added video as Dfault.',
              image: 'js/grumble/themes/smoke/success.png' //check image
            });
           // }
          }
        });
      
    }
    return false;
  });
  
    //Make default Song
  $('#profileMusicDefaultAction').live('click', function () {
    var songID = $(this).find('a').attr('id');
    var defsongID = $("#profileMusicDefaultAction > a[class*='default']").attr('id');
    var parentDIV = $(this).parent().parent().parent().parent();
  $('div#globalStatus').show;  
    if (!isNaN(songID)) {
      //var deleteConfirm = confirm('Are you sure you want to delete this song?');
      
        $.ajax({
          type: 'POST',
          data: 'songID=' +songID,
          cache: false,
          url: 'ajax/ajax.makeDefaultSong.php',
          success: function (html) {
            //if (response == 1) {
              $("#profileMusicDefaultAction > a[class*='default']").replaceWith("<a id=\"" + defsongID + "\" href=\"#\">Make Default</a>");
              $("#profileMusicDefaultAction > a[id*='"+songID+"']").replaceWith("<a class=\"default\" style=\"color: rgb(55, 201, 74);\" id=\"" + songID + "\" href=\"#\">Default</a>");
              $.gritter.add({
            	title: 'Default Song Notice!',
            	text: 'Successfully added song as Dfault.',
              image: 'js/grumble/themes/smoke/success.png' //check image
            });
           // }
          }
        });
      
    }
    return false;
  });
  
  //Delete song
  $('#profileMusicDeleteAction').live('click', function () {
    var songID = $(this).find('a').attr('id');
    var parentDIV = $(this).parent().parent().parent().parent();
    
    if (!isNaN(songID)) {
       var msgtxt ='Are you sure you want to delete this song?';
      jConfirm(msgtxt, 'Delete Song', function(r) {
              if(r){
        $.ajax({
          type: 'POST',
          data: 'songID=' +songID,
          cache: false,
          url: 'ajax/ajax.deleteSong.php',
          success: function (response) {
            if (response == 1) {
              parentDIV.fadeOut().remove();
              
            }
          }
        });
     } });
    }
    return false;
  });
  
  //Show the container to change out song from the Music area in the profile
  $('#profileMusicEditAction').live('click', function () {
    var parentDIV = $(this).parent().parent().parent().parent();
    var hiddenContainer = parentDIV.find('.jsHiddenSongChangeContainer');
    var currentSongNameContainer = parentDIV.find('.ajaxSongName');
    
    currentSongNameContainer.hide();
    hiddenContainer.removeClass('globalHidden');
    
    parentDIV.find('#jsNewSongName').focus();
    
    return false;
  });
  
  $('.ajaxChangeSongName').submit(function () {
    var strForm = $(this).serialize();
    var songName = $(this).find('#jsNewSongName');
    var hiddenContainer = $(this).parent().parent().parent().find('.jsHiddenSongChangeContainer');
    var currentSongName = $(this).parent().parent().parent().find('.ajaxSongName');
    
    if (!isEmpty(songName.val())) {
      $.ajax({
        type: 'POST',
        data: strForm,
        cache: false,
        url: 'ajax/ajax.changeSongName.php',
        success: function (response) {
          if (response == 1) {
            hiddenContainer.addClass('globalHidden');
            currentSongName.text(songName.val());
            currentSongName.show();
          }
        }
      });
    }
    return false;
  });
  
  $('#ajaxChangeVideoName').submit(function () {
    var strForm = $(this).serialize();
    var songName = $(this).find('#jsNewSongName');
    var hiddenContainer = $(this).parent().parent().parent().find('.jsHiddenSongChangeContainer');
    var currentSongName = $(this).parent().parent().parent().find('.ajaxSongName');
    
    if (!isEmpty(songName.val())) {
      $.ajax({
        type: 'POST',
        data: strForm,
        cache: false,
        url: 'ajax/ajax.changeVideoName.php',
        success: function (response) {
          if (response == 1) {
            hiddenContainer.addClass('globalHidden');
            currentSongName.text(songName.val());
            currentSongName.show();
          }
        }
      });
    }
    return false;
  });
  
  $('#cancelNameChange').live('click', function () {
    var parentDIV = $(this).parent().parent().parent();
    
    parentDIV.find('.ajaxSongName').show();
    parentDIV.find('.jsHiddenSongChangeContainer').addClass('globalHidden');
    
    return false;
  });
  
  //$('.ajaxStarRating .jsStars').starRating();
  $('.ajaxVote').Vote();
  $('.ajaxRemoveVote').RemoveVote();
});

function isEmpty(str) {
  var strText = String(str).replace(/^\s\s*/, '').replace(/\s\s*$/, '');
  
  if (strText == '')
    return true;
  else
    return false;
}

function isEmail(str) {
 var emailReg = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
 
 if (emailReg.test(String(str)))
  return true;
 else
  return false; 
}

function showDialog (id) {
  $('#globalShadow').show();
  $('#ajaxLoading').show();
  $('#dialogBox').fadeIn('fast');
  $.ajax({
    type: 'POST',
    url: 'ajax/ajax.Dialog.php',
    data: 'id=' + id,
    cache: false,
    success: function (html) {
      $('#ajaxLoading').fadeOut();
      $('#DOM_Control_dialog').html(html);
    }
  });
}

function closeDialog() {
  $('#dialogBox').fadeOut('fast');
  $('#globalShadow').hide();
}

/* Plugins */

/* Vote Plugin */
jQuery.fn.Vote = function () {
  $(this).live('click', function () {
    var songID = $(this).attr('id');
    var current = $(this).parent();
    
    current.hide();
    
    if (!isNaN(songID)) {
    $.ajax({
      type: 'POST',
      data: 'songID=' +songID, 
      url: 'ajax/ajax.Vote.php', 
      success: function (html) {
        if (html != 0) {
          $('.ajaxVote-'+songID).parent()
                                .show()
                                .html(html)
        }
      }
      });
    }
    return false;
  });
};

/* Remove Vote Plugin */
jQuery.fn.RemoveVote = function () {
  $(this).live('click', function () {
    var songID = $(this).attr('id');
    var current = $(this).parent();
    
    current.hide();
    
    if (!isNaN(songID)) {
    $.ajax({
      type: 'POST',
      data: 'songID=' +songID, 
      url: 'ajax/ajax.removeVote.php', 
      success: function (html) {
        if (html != 0) {
          $('.ajaxVoted-'+songID).parent()
                                 .show()
                                 .html(html)
        }
      }
      });
    }
    return false;
  });
};


jQuery.fn.autoExpand = function () {
  $(this).live('focus blur', function (event) {
    var html = $(this).val().split('\n');
    var self = this;
    var b = 1;
    
    if (event == 'focus') {
      for(x = 0; x < html.length; x++)
        if (html[x].length >= self.cols)
          b += math.floor(html[x].length / self.cols);
      
      b += html.length;
      if (b > self.rows)
        self.rows = b;
    }
    else {
      
    }
    
  });
};