function defaultInputText(){
  var default_values = new Array();
  $("input.default-value").focus(function() {
    if (!default_values[this.id]) {
      default_values[this.id] = this.value;
    }
    if (this.value == default_values[this.id]) {
      this.value = '';
    }
    $(this).blur(function() {
      if (this.value === '') {
        this.value = default_values[this.id];
      }
    });
  });
}


// Main Menu Throbber

var intervalID;

function nowInterval( fn, time ) {
  fn();
  return setInterval( fn, time );
} 

function fadeMenu(){
  var elem = $(this);
  intervalID = nowInterval(function(){
    elem.animate({opacity:0.4}, 'fast');
    elem.animate({opacity:1.0}, 'fast');
  }, 500);
}

function stopMenuAnimation(){
  clearInterval(intervalID);
}

function animateMenu(){
  $("#nav ul.menu li").each(function(){
    $(this).hover( fadeMenu, stopMenuAnimation);
  });
}

// TODO CHANGEME
function openWindow(windowHTML) {
  var htmlHeader =
      "<html>"
    + "<head>"
    + "<title>Audio Player</title>"
    + '<script type="text/javascript" src="/sites/all/modules/swftools/jw5/swftools_jw5.js"></script>'
    + '<script type="text/javascript" src="/sites/all/libraries/swfobject/swfobject.js"></script>'
    + '<script type="text/javascript" src="/sites/all/modules/swftools/swftools.js"></script>'
    + '<script type="text/javascript" src="/sites/all/modules/swftools/wijering4/swftools_wijering4.js"></script>'
    + "<style>body{background:#07151c;}</style>"
    + "</head>"
    + "<body>";
  var htmlFooter =
      "<p><a href=\"javascript:self.close()\">Close Window</a></p>"
    + "</body>"
    + "</html>";
  newWindow=window.open('','audioWindow','width=310,height=24,toolbar=no,location=no,scrollbars=no,status=no,resizable=no,fullscreen=no');
  newWindow.document.open();
  newWindow.document.write(htmlHeader);
  newWindow.document.write(windowHTML);
  newWindow.document.write(htmlFooter);
  newWindow.document.close();
  newWindow.focus();
}

function popupPlayer(container){
  var markup = container.html();
  $('<div class="tiny popout"><a class="popup" href="#">Pop-out</a></div>')
    .insertBefore(container)
    .click(function(){
      openWindow(markup);
      return false;
    });
}

if (Drupal.jsEnabled) {
  $(document).ready( function() {
      defaultInputText();
      animateMenu();
  });
}


