﻿$(document).ready(function () {
    $("#navigation").treeview({
        persist: "category",
        collapsed: true,
        unique: true
    });
    set_footer_at_bottom();
    //$(window).resize(function() { set_footer_at_bottom(); });
    setupButtons();
});


function set_footer_at_bottom() {
    $('#leftmenu').height($(document).height() - 164 - 45);
    //$('.page').height($(document).height());
    /*alert($(document).height() + 'px');
    $('#subBody').css({
    height: $(document).height() + 'px'
    });*/
}

$('.btn').each(function () {
    var b = $(this);
    var tt = b.text() || b.val();
    if ($(':submit,:button', this)) {
        $('<a>').insertAfter(this).addClass(this.className).attr('id', this.id);
        $(this).remove();
    }
    b.text('').css({
        cursor: 'pointer'
    }).prepend('<i></i>').append($('<span>').text(tt).append('<i></i><span></span>'));
});


function setupButtons() {
    //all hover and click logic for buttons
    $(".fg-button:not(.ui-state-disabled)").hover(

          function () {
              $(this).addClass("ui-state-hover");
          }, function () {
              $(this).removeClass("ui-state-hover");
          }).mousedown(function () {
              $(this).parents('.fg-buttonset-single:first').find(".fg-button.ui-state-active").removeClass("ui-state-active");
              if ($(this).is('.ui-state-active.fg-button-toggleable, .fg-buttonset-multi .ui-state-active')) {
                  $(this).removeClass("ui-state-active");
              }
              else {
                  $(this).addClass("ui-state-active");
              }
          }).mouseup(function () {
              if (!$(this).is('.fg-button-toggleable, .fg-buttonset-single .fg-button,  .fg-buttonset-multi .fg-button')) {
                  $(this).removeClass("ui-state-active");
              }
          });
      };

(function ($) {
  // VERTICALLY ALIGN FUNCTION
  $.fn.vAlign = function () {
      return this.each(function (i) {
          var ah = $(this).height();
          var ph = $(this).parent().height();
          var mh = (ph - ah) / 2;
          $(this).css('margin-top', mh);
      });
  };
})(jQuery);
