;(function($){var PLUGIN_NAME = "navigationMenuManager";
var ImplementationClass = function(target, config) {
var settings = $.extend({}, $[PLUGIN_NAME].defaults, config), myself = this;
$(target).data(PLUGIN_NAME, myself);
var currentMenuID = null, $pullDownMenus = null, pullDownOptions = {}, touch = window.ontouchstart===null ? true : false;
function _constructor_() {
currentMenuID = null;
$pullDownMenus = $("a[data-pulldown]", $(target));
$pullDownMenus.each(function(){
var menuID = $(this).data("pulldown");
var $element = $("#" + menuID);
pullDownOptions[menuID] = { element : $element, height : $element.height() };
$element.height(0);
});
if(touch) {
$(settings.clearTarget).bind('touchstart', clearMenu);
$pullDownMenus.each(function(){ $(this).bind('touchstart', touchMenu); });
} else {
$pullDownMenus.hover(pullDown, function(){});
$(target).parent().hover(function(){}, closeMenu);
}
$("a:not([data-pulldown])", $(target)).hover(closeMenu, function(){});
}
$.extend( myself, { havingnopoint : "" });
_constructor_();
function clearMenu(event) {
if($(event.target).parents(settings.mainArea).length > 0) { return; }
if(currentMenuID && $(event.target).parent().data('pulldown') != currentMenuID) { closeMenu(); }
}
function touchMenu(event) {
var menuID = $(this).data("pulldown");
if(currentMenuID == menuID) {
closeMenu();
} else {
if(currentMenuID != null && currentMenuID in pullDownOptions) {var $old = pullDownOptions[currentMenuID].element;$old.stop().height(0).hide();}
openMenu(menuID);
}
}
function pullDown(event) {
var menuID = $(this).data("pulldown");
if(currentMenuID == menuID) { return; }
if(currentMenuID != null) { var $old = pullDownOptions[currentMenuID].element; $old.stop().height(0).hide(); }
openMenu(menuID);
}
var $currentAnime = null;
function openMenu(menuID) {
currentMenuID = menuID;
if($currentAnime != null) {$currentAnime.stop().height(0).hide();}
if(currentMenuID in pullDownOptions) {
var options = pullDownOptions[menuID];
$currentAnime = options.element;
options.element.stop()
.animate({ opacity: 'show', height: options.height + 20 }, { duration : 200 })
.animate({ height: options.height-10 }, { duration : 80 })
.animate({ height: options.height+5 }, { duration : 50 })
.animate({ height: options.height }, { duration : 30, complete:function(){$currentAnime = null;} });
if(settings.hoverOnAction) {settings.hoverOnAction(touch, currentMenuID);}
}
}
function closeMenu() {
if(currentMenuID == null) { return; }
if($currentAnime != null) { $currentAnime.stop().height(0).hide(); }
if(currentMenuID in pullDownOptions) {
var options = pullDownOptions[currentMenuID];
options.element.animate({ opacity: 'hide', height: 0 }, { duration: 150, complete: function () { currentMenuID = null; } });
if(settings.hoverOffAction){ settings.hoverOffAction(touch, currentMenuID); }
}
}
}; $[PLUGIN_NAME] = {defaults : {clearTarget: "#wrapper", mainArea: "#navi", hoverOnAction: null, hoverOffAction: null}};
$.fn[PLUGIN_NAME] = function(config){return this.each(function(i){new ImplementationClass(this, config);});};
})(jQuery);