/* Global Animations */
var fadeClose;
var toggleCart = new Animator({duration: 300}).addSubject(new NumericalStyleSubject($("cart"), 'opacity', 0, 1));
var toggleEmptyPlaylist = new Animator({duration: 300}).addSubject(new NumericalStyleSubject($("emptyPlaylist"), 'opacity', 1, 0));
var toggleNotices = new Animator().addSubject(new NumericalStyleSubject($("incomingMessages"), 'opacity', 1, 0)).addSubject(new NumericalStyleSubject($("incomingMessages"), 'height', 60, 0)).addSubject(new CSSStyleSubject($("incomingMessages"), "display: block;","display: none;"));
var displayNonePlaylist = new Animator({duration: 1}).addSubject(new CSSStyleSubject($("emptyPlaylist"), "display: block;","display: none;"));
var displayNoneCart = new Animator({duration: 1}).addSubject(new CSSStyleSubject($("cart"), "display: none;","display: block;"));
var toggleCartAndEmpty = new AnimatorChain([toggleEmptyPlaylist,displayNonePlaylist,toggleCart,displayNoneCart]);
var toggleNamePrice = new Animator().addSubject(new NumericalStyleSubject($("incomingMessages"), 'opacity', 1, 0)).addSubject(new NumericalStyleSubject($("incomingMessages"), 'height', 60, 0));

function highlightCart(){
  new Animator({duration: 1000}).addSubject(new CSSStyleSubject($("current_item"), "background-color: #FFFF99; color: #000000;","background-color: #649064; color: #FFFFFF;")).play();
  setTimeout('$("current_item").style.backgroundColor="transparent";',1100);
}

/* Closing the Notices */
function fadeOutClose(){
  if(fadeClose){
    fadeClose.seekTo(0);
  }
}
function fadeInClose(){
  if(fadeClose){
    fadeClose.seekTo(1);
  }else{
    fadeClose = new Animator().addSubject(new NumericalStyleSubject($("closeNotice"), 'opacity', 0.2, 1));
  }
}

var prevId = null;
function showNamePrice(id){
  if(prevId){$(prevId).innerHTML = '';}
  $(id).innerHTML = 'Name your price: <input id="namePrice" name="price" size="15" />' +
                    '<table cellspacing="0" cellpadding="0" onclick="buySong(parentNode.id);" class="buttonTable"><tbody><tr><td><div id="loginBTN" class="leftEnd">Get it Now</div></td><td><div><img alt="Right" src="../images/icons/buttonRight.png"/></div></td></tr></tbody></table>'
  $("namePrice").focus();
  prevId = id;
}

function buySong(id){
  document.location.href = '/shopping/buy_song/' + id.substring(0,2) + '?price=' + $('namePrice').value;
}