// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults
$(document).ready(function() {
  $('input.clearme').focus(function(i) {
    if (this.value == this.title) {
      this.value = "";
      $(this).removeClass('clearme');
    }
  });
  $('input.clearme').blur(function(i) {
    if (this.value == "") {
      this.value = this.title;
      $(this).addClass('clearme')
    }
  });
  $('#subscriber_form').submit(function() {
    $.post('/subscribers', $(this).serialize(), function(data) {
      if (data.status == "success") {
        $('#subscriber_form_wrap').html(data.message);
      }
    }, "json");
    return false;
  });

  $.ajaxSetup ({
    cache: false
  });

  initMenu();

});

function initMenu() {

  $('#menu div').hide();
  //$('#menu div:first').show();
  $('#menu h2').click(
    function() {
      var checkForA = this.childNodes[0].parentNode.getElementsByTagName('a')[0];
      /*if(checkForA)
      {
        //document.location = checkForA + "#" + this.childNodes[0].parentNode.getElementsByTagName('a')[0].name;
        //return false;
        var stage = $("#stage");
        stage.location.href = checkForA;
        //alert(stage.src);
      }*/


      var checkElement = $(this).next();

      if((checkElement.is('div')) && (checkElement.is(':visible'))) {
        checkElement.slideUp('normal');
        return false;
        }
      if((checkElement.is('div')) && (!checkElement.is(':visible'))) {
        $('#menu div:visible').slideUp('normal');
        checkElement.slideDown('normal');
        return false;
        }

      }
    );

  /*if (window.location.hash)
  {
    var id = window.location.hash + "1";
    window.location.hash = "";
    $(id).slideDown('normal');
  }*/
}

