﻿/* 
This class allows panels to slide out but ensures the user has time to mouse over.
This also ensures that panels that have another panel with a class of .dropDown inside of them
that when moused over, the panel doesn't collapse.
This also allows the developer to add handlers for onshow, onhide.
*/

function SlideOut(target, onShow, onHide, dropDownSelector) {
    this.jObj = target;
    this.onShow = onShow;
    this.onHide = onHide;
    this.dropDownSelector = (dropDownSelector == null ? ".dropDown" : dropDownSelector);
};

SlideOut.prototype.SetHandlers = function(onShow, onHide) {
    this.onShow = onShow;
    this.onHide = onHide;
}

SlideOut.prototype.EnsureOpen = function() {
    this.jObj.find(".dropDown");
    jDropDown.data("isShowing", true);
}

//binds all of the events to work
SlideOut.prototype.Start = function() {
    var _me = this;

    //Manages the filter drop downs for the grids
    this.jObj.hover(function() {
        var jDropDown = $(this).find(_me.dropDownSelector);     //get the drop down
        jDropDown.data("isShowing", true);                      //set the drop down flag
        jDropDown.hover(function() {                            //set the drop down hover methods
            $(this).data("isShowing", true);                    //when the expanded drop down is hovered, set it showing flag to true
        },
        function() {
            $(this).data("isShowing", false);                   //when the expanded drop down is unhovered, set its showing flag to false, wait 300 milliseconds and see if it should hide
            var _this = $(this);
            setTimeout(function() { if (!_this.data("isShowing")) { _this.hide(); if (_me.onHide != null) _me.onHide.call(_me); } }, 300);
        })
        jDropDown.slideDown(300);
        if (_me.onShow != null) {
            _me.onShow.call(_me);
        }
    }, function() {
        var jDropDown = $(this).find(_me.dropDownSelector);
        jDropDown.data("isShowing", false);
        var _this = jDropDown;
        setTimeout(function() { if (!_this.data("isShowing")) { _this.hide(); if (_me.onHide != null) _me.onHide.call(_me); } }, 300);
    });
}