/**
* @author Alexander Grein, http://www.typo3-webagentur.com
 */

var MENU_ID = '#mainmenu';
var CONTENT_ID = '#maincontent';
var MENU_CLOSED_HEIGHT = 25;
var COOKIE_OPTIONS = { path: '/', expires: 10 };
var MENU_STATE = 'menu_state';
var FIRST_TIME = true;

var MainMenu = {
  init: function(MenuState){
    MENU_HEIGHT = jQuery(MENU_ID).height();
    jQuery(CONTENT_ID).css({ "margin-bottom": MENU_CLOSED_HEIGHT });
    if(MenuState == 'closed') {
      jQuery(MENU_ID).css({ 'height': MENU_CLOSED_HEIGHT + 'px'});
    } else {
      jQuery(MENU_ID).css({ 'height': MENU_HEIGHT - ((jQuery.browser.msie && jQuery.browser.version <= 6) ? 1 : 0) + 'px'});
    }
    jQuery.cookie(MENU_STATE, MenuState, COOKIE_OPTIONS);
  },
  animateMainMenu: function(waitTime, finalHeight, MenuState){
    waitTime = waitTime || 0;
    finalHeight = finalHeight || MENU_CLOSED_HEIGHT;
    MenuState = MenuState || 'closed';
    jQuery(MENU_ID).wait(waitTime).animate({ 
      height: finalHeight + 'px'}, 
      700, 
      'swing', 
      function(){
        jQuery.cookie(MENU_STATE, MenuState, COOKIE_OPTIONS);
        FIRST_TIME = false;
      }
    );
    if(waitTime == 0) {
      jQuery(MENU_ID).dequeue();
    }
    if(!FIRST_TIME && jQuery.cookie(MENU_STATE) == 'open') {
      jQuery(MENU_ID).dequeue();
    }
  }
}

jQuery.fn.wait = function(time, type) {
    time = time || 0;
    type = type || 'fx';
    return this.queue(type, function() {
        var self = this;
        setTimeout(function() {
            jQuery(self).dequeue();
        }, time);
    });
};

var Menu = {
  init: function() {
    jQuery(MENU_ID).css({position: 'fixed'});
    if(jQuery.cookie(MENU_STATE) == undefined || jQuery.cookie(MENU_STATE) == false) {
      MainMenu.init('open');
      MainMenu.animateMainMenu(5000, MENU_CLOSED_HEIGHT, 'closed');
    } else {
      FIRST_TIME = false;
      MainMenu.init(jQuery.cookie(MENU_STATE));
      if(jQuery.cookie(MENU_STATE) == 'open') {
        MainMenu.animateMainMenu(0, MENU_CLOSED_HEIGHT, 'closed');
      }
    }
    var enter = function(){
      FIRST_TIME = false;
      MainMenu.animateMainMenu(0, MENU_HEIGHT, 'open');
    };
    var leave = function(){
      MainMenu.animateMainMenu(0, MENU_CLOSED_HEIGHT, 'closed');
    };
    jQuery(MENU_ID).mouseenter(enter);
    jQuery(MENU_ID).mouseleave(leave);
  }
}

jQuery(document).ready(function(){
  Menu.init();
  jQuery('.instructor').columnFilters({alternateRowClassNames:['','listrow-odd']});
  jQuery('div.csc-frame.csc-frame-frame2 .tx-seminars-pi1 table').columnFilters({alternateRowClassNames:['','listrow-odd'],excludeColumns:[3,4,5,6]});
});


