// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults

jQuery.noConflict();

jQuery(document).ready(function($){
	 
  function showActive(p){
  	classes = $(p).attr('class')
	
	// If the entry is expanded don't do anything
	if(!classes.match("expanded")) {
	  $(p).find('.off-hover').hide();
	  $(p).find('.on-hover').show();
	}
  }

  function showPassive(p){
  	classes = $(p).attr('class')
	
	// If the entry is expanded don't do anything
	if (!classes.match("expanded")) {
	  $(p).find('.on-hover').hide();
	  $(p).find('.off-hover').show();
	}
  }
  
  // Hovering over an entry
  $('div.entry').hover( 
		  function() {  
		  	showActive(this);
		  } , 
		  function() {  
		    showPassive(this);
		  } 
  ); 
  
  // Special instructions for hovering over the vote
  // box of an expanded entry
  $('.numvote').hover( 
    function() { 
      var entry =  $(this).parents(".entry")
	  var classes = entry.attr('class')
	  if (classes.match("expanded")) {
	    entry.find('.numvote .off-hover').hide();
		entry.find('.numvote .on-hover').show();
	  }
	  } , 
	  function() {  
		var entry =  $(this).parents(".entry")
	    var classes = entry.attr('class')
		if (classes.match("expanded")) {
		  entry.find('.numvote .off-hover').hide();
		  entry.find('.numvote .on-hover').show();
		}
	  }   
   ); 
  
  function showWidget(entry){
  	entry.find('.thumbnail').hide(
	  1,
	  function(){ 
	    entry.find(".widget").show()
		entry.find(".on-expanded").show()	
	  }
	)  	
  }

  function pauseAndThenShowWidget(entry){
  	// This animation does not do anything.  It's a hack to simulate a "pause"
  	entry.find('.thumbnail').animate(
	  {width:"250px"},
	  "medium",
	  "linear",
	  function(){showWidget(entry)}
	)
  }
  
  $('.entry .close a').click(
    function(){	  
	  var entry = $(this).parents(".entry")
	  entry.removeClass("expanded")
	  entry.find(".on-expanded").hide()
	  entry.find(".widget").hide()
	  entry.find(".thumbnail").show()	
	  entry.find(".thumbnail img").animate(
	    {  
          width: "75px",
          height: "75px"
        }, 
	    'slow',
		'linear',
		function(){
			entry.find(".info").css('width','375px')
			entry.find(".thumbnail").css('width','75px')
			entry.find("ul.links li.listen").show()
		}
	  )
	  
	  return false;
	 
	}
  );
  
  $('a.play').click(
    function(){
	  var entry = $(this).parents(".entry")
	  entry.addClass("expanded")
	  entry.find(".info").css('width','215px')
	  entry.find(".off-expanded").hide()
	  entry.find(".numvote .checkmark").hide()
	  entry.find(".numvote .text").show()
	  entry.find(".thumbnail .button").hide()
	  entry.find(".thumbnail img").animate({  
        width: "250px",
        height: "250px"
      }, 
	  'slow', 
	  'linear',
	  function(){ pauseAndThenShowWidget(entry)} 
	);
	
	return false;
	}
  );
  
    $('#featured-song .song .close a').click(
    function(){	  
	  $('#featured-song').hide();
	  return false;
	 
	}
  );

});

