$(document).ready(function() {
  /* To help with form styling */
  $("input[type='text'],input[type='password'],textarea").addClass("text-field");
  $("input[type='radio']").addClass("radio");
  $("input[type='checkbox']").addClass("checkbox");
  //$("input[type='radio']:first").attr("checked", true);
  $("input[type='submit']").addClass("submit");
  $("input.submit").bind("mouseover mouseout", function(){$(this).toggleClass("hover")});
  $("ul#global-nav li.admin").bind("mouseover mouseout", function(){$(this).toggleClass("hover")});
  
  /* Drop down menu */
  $('.expand').bind('mouseover mouseout', function(){ $(this).toggleClass('hover'); });
  $('#nav select#artist_id').change(function(){window.location = $(this).attr('value')})
  //$('.sortable').sortable();
  //$('.sortable').sortable('option', 'handle', 'span');
  /* Load Flash MP3 Player */
  //swfobject.embedSWF("/flash/mp3-player.swf", "mp3-player", "1", "1", "9.0.0","expressInstall.swf", {/*flashvars*/}, {/*params*/}, {/*attributes*/});

  $('.playable').bind('click', play);
  $('.news-item:last, .playlist li:last').addClass('last');
  $('.playlist li:first').addClass('first');
  
  //$(".crop img").load(function() {
  //  frame = $(this).parent(".crop");
  //  image = $(this);
  //  scaleFactor = Math.min(frame.innerWidth(), frame.innerHeight()) / Math.min(image.width(), image.height());
  //  image.width(Math.ceil(image.width() * scaleFactor));
  //  image.height(image.height());
  //  image.show();
  //});
  
});

$(window).load(function() {
  $(".crop").each(function() {
    frame = $(this);
    image = $(this).children("img:first");
    scaleFactor = Math.min(frame.innerWidth(), frame.innerHeight()) / Math.min(image.width(), image.height());
    image.width(Math.ceil(image.width() * scaleFactor));
    image.height(image.height());
    image.show();
  })

});

function play() {
  // Either stop the current song
  if ($(this).hasClass('playing')) {
    globalAudioPlayer.stopInPlayer();
    $(this).removeClass('playing');
  }
  // Or start a new one
  else {
    var release = $.trim($($(this).parent()[0]).attr('id'));
    var track = $.trim($(this).attr('id'));
    var songUrl = '/stuff/stream/' + release + '/' + track + '.mp3';
    globalAudioPlayer.playInPlayer(songUrl, $(this).attr('id'));
    $('.playing').removeClass('playing');
    $(this).addClass('playing');
  }
};