  function copy_to_clipboard(field) {
    var val = eval("document." + field)
    val.select()

    if (document.all) {
      range = val.createTextRange();
      range.execCommand("Copy");
      alert('Quote successfully copied. Press Ctrl + V to paste');
    }
  }

$(document).ready(function(){
  $("div.alphabet div.letter").click(function(item){
    // var letter = $(this).html().toLowerCase();
    var letter = item.target.id;
    
    if (letter == '#') {
      letter = 'num';
    }

    window.location = '/browse/' + letter + '.html';
  });

  // ---------------------------------------

  // focus/blur effects for input fields
  $('input[type="text"]').focus(function() {
    $(this).addClass("textbox_on");
  });

  $('input[type="text"]').blur(function() {
    $(this).removeClass("textbox_on");
  });

  // hover effect for submit button
  $("input.submitbutton").hover(function() {
    $(this).removeClass("faded");
    $(this).css('cursor', 'pointer');
  }, function() {
    $(this).addClass("faded");
  });

  // ---------------------------------------

  // stuff to do when a rating icon is clicked
  $("img.rate").click(function(item) {
    var quoteid  = item.target.id;
    var src      = item.target.src.indexOf('plus');
    var quotediv = quoteid;
    var ratediv  = "rate_" + quoteid;

    if (src != -1) {
      var rating = 1;
    } else {
      var rating = -1;
    }

    $.post("/rate.php", { id: quoteid, rating: rating }, function(data) {
      // "plus" not found in src value. Must be a negative rating...
      if (rating == -1) {
        var colorclass = 'red';
      } else {
        var colorclass = 'green';
      }
      
      $('#' + quotediv).fadeOut('slow', function() { 
                                       // $('#' + quotediv).removeClass('quote');
                                       $('#' + quotediv).addClass(colorclass);
                                       
                                       // update the rating instantly, for the user to see
				       var oldrating = parseInt($('#rating_' + quoteid).html());
				       var newrating = (rating == -1) ? oldrating - 1 : oldrating + 1;
				            
				       if (!newrating) {
				         newrating = "0";
				       }
				            
				       $('#rating_' + quoteid).html(newrating);

				       if (newrating < 0) {
				         $('#ratingdiv_' + quoteid).removeClass('rate_gray');
				         $('#ratingdiv_' + quoteid).addClass('rate_red');
				       } else if (newrating == 0) {
				         if (oldrating == 1) {
  				           $('#ratingdiv_' + quoteid).removeClass('rate_green');
  				         } else {
  				           $('#ratingdiv_' + quoteid).removeClass('rate_red');
  				         }

				         $('#ratingdiv_' + quoteid).addClass('rate_gray');
				       } else if (newrating > 0) {
				         $('#ratingdiv_' + quoteid).removeClass('rate_gray');
				         $('#ratingdiv_' + quoteid).addClass('rate_green');
				        
				         if (oldrating == 0) {
				           $('#rating_' + quoteid).prepend('+');
				         }
				       }
				       
				       $('#' + ratediv).hide();
                                     });

      $('#' + quotediv).fadeIn("slow");

    });

    return false;
  });

  // ---------------------------------------

});
