// jQuery Context Menu Plugin
//
// Version 1.01
//
// Cory S.N. LaViska
// A Beautiful Site (http://abeautifulsite.net/)
//
// More info: http://abeautifulsite.net/2008/09/jquery-context-menu-plugin/
//
// Terms of Use
//
// This plugin is dual-licensed under the GNU General Public License
//   and the MIT License and is copyright A Beautiful Site, LLC.
//
// Modified by Philip Weir:
//   Added highlighting of selected row and submenu support
//   Added sub menu functions
//   Added bind to contextmenu event
//   Adjust menu position for screen boundaries
//   Shrunk with Google Closure Compiler (Simple Optimizations)
jQuery&&function(){$.extend($.fn,{contextMenu:function(a,d){if(void 0==a.menu)return!1;void 0==a.inSpeed&&(a.inSpeed=150);void 0==a.outSpeed&&(a.outSpeed=75);0==a.inSpeed&&(a.inSpeed=-1);0==a.outSpeed&&(a.outSpeed=-1);$(this).each(function(){var b=$(this),j=$(b).offset();$("#"+a.menu).addClass("contextMenu");$(this).mousedown(function(k){$(this).mouseup(function(f){var c=$(this);$(this).unbind("mouseup");if(k.button==2){$(".contextRow").removeClass("contextRow");$(".contextMenu").hide();c.addClass("contextRow"); rcm_update_options(c);var e=$("#"+a.menu);$(this).submenu_render(e);if($(b).hasClass("disabled"))return false;var g,h;f.pageX?g=f.pageX:g=f.clientX+void 0;f.pageY?h=f.pageY:h=f.clientY+void 0;g+$(e).width()+10>$(document).width()&&$(document).width()-$(e).width()-10>0&&(g=$(document).width()-$(e).width()-10);h+$(e).height()+10>$(document).height()&&$(document).height()-$(e).height()-10>0&&(h=$(document).height()-$(e).height()-10);$(document).unbind("click",$(this).document_click);$("#"+a.menu+" li ul").hide(); $("#"+a.menu+" li div").hide();$(e).css({top:h,left:g}).fadeIn(a.inSpeed);$(document).bind("keypress",{menu:e},$(this).menu_keypress);$("#"+a.menu).find("a").unbind("click");$("#"+a.menu).find("li a:not(.disabled)").click(function(){$(document).unbind("click",$(this).document_click).unbind("keypress",$(this).menu_keypress);$(".contextMenu").hide();c.removeClass("contextRow");d&&d($(this).attr("href").substr(1),$(c),{x:g-j.left,y:h-j.top,docX:g,docY:h});return false});setTimeout(function(){$(document).bind("click", {menu:e,o:a},$(this).document_click);$("iframe").load(function(){(this.contentDocument?this.contentDocument:this.contentWindow?this.contentWindow.document:null).onclick=function(){$(document).click()}});$("iframe").contents().mouseup(function(){$(document).click()})},0)}if(!rcmail.drag_active){f.cancelBubble=true;f.stopPropagation&&f.stopPropagation()}})});var c,i;$("#"+a.menu).children("li").mouseenter(function(){if($(this).hasClass("submenu")){if($(this).hasClass("submenu")&&!c&&!$(this).children("*:not(a, span)").is(":visible")){window.clearTimeout(i); i=null;var b=this;c=window.setTimeout(function(){$("#"+a.menu).children("li.submenu").children("div.popupmenu").children("ul.scrollable").scrollTop(0);$("#"+a.menu).children("li.submenu").children("div.popupmenu").children("div.scroll_up_act").addClass("scroll_up_pas").removeClass("scroll_up_act");$("#"+a.menu).children("li.submenu").children("div.popupmenu").children("div.scroll_down_pas").addClass("scroll_down_act").removeClass("scroll_down_pas");$("#"+a.menu).children("li.submenu").children("*:not(a, span)").hide(); doc_height=$(document).height();$(b).children("*:not(a, span)").css({left:$("#"+a.menu).width()-2,top:0});$(b).children("*:not(a, span)").show();$(b).children("*:not(a, span)").offset().left+$(b).children("*:not(a, span)").width()+10>$(document).width()&&$(document).width()-$(b).children("*:not(a, span)").width()-$("#"+a.menu).width()>0&&$(b).children("*:not(a, span)").css({left:$(b).children("*:not(a, span)").width()*-1});y=($(b).children("*:not(a, span)").offset().top+$(b).children("*:not(a, span)").height()+ 10-doc_height)*-1;y<0&&$(b).children("*:not(a, span)").offset().top+y>0&&$(b).children("*:not(a, span)").css({top:y});$(b).children("div.popupmenu").length&&$(b).children("div.popupmenu").children().show();c=null},a.submenu_delay)}}else i=window.setTimeout(function(){$("#"+a.menu).children("li.submenu").children("*:not(a, span)").hide();i=null},a.submenu_delay)});$("#"+a.menu).children("li.submenu").mouseleave(function(){window.clearTimeout(c);c=null});$(this).mouseleave(function(){window.clearTimeout(c); c=null});$.browser.mozilla?$("#"+a.menu).each(function(){$(this).css({MozUserSelect:"none"})}):$.browser.msie?$("#"+a.menu).each(function(){$(this).bind("selectstart.disableTextSelect",function(){return false})}):$("#"+a.menu).each(function(){$(this).bind("mousedown.disableTextSelect",function(){return false})});$(b).add($("ul.contextMenu")).bind("contextmenu",function(){return false})});return $(this)},disableContextMenuItems:function(a){if(void 0==a)return $(this).find("a").addClass("disabled"), $(this);$(this).each(function(){if(void 0!=a)for(var d=a.split(","),b=0;b<d.length;b++)$(this).find('a[href="'+d[b]+'"]').addClass("disabled")});return $(this)},enableContextMenuItems:function(a){if(void 0==a)return $(this).find("a.disabled").removeClass("disabled"),$(this);$(this).each(function(){if(void 0!=a)for(var d=a.split(","),b=0;b<d.length;b++)$(this).find('a[href="'+d[b]+'"]').removeClass("disabled")});return $(this)},disableContextMenu:function(){$(this).each(function(){$(this).addClass("disabled")}); return $(this)},enableContextMenu:function(){$(this).each(function(){$(this).removeClass("disabled")});return $(this)},destroyContextMenu:function(){$(this).each(function(){$(this).unbind("mousedown").unbind("mouseup")});return $(this)},submenu_render:function(a){$(a).show();$(a).children("li.submenu").children().show();$(a).children("li.submenu").children("div.popupmenu").each(function(){ul_overflow=$(this).children("ul").css("overflow");$(this).children("ul").css({overflow:"visible"});$(this).children("div").css({width:$(this).children("ul").width()+ "px"});$(this).css({width:$(this).children("ul").width()+"px"});$(this).children("ul").css({overflow:ul_overflow});$(this).children("div").click(function(a){var b=$(this).parent().children("ul");$(this).hasClass("scroll_up_act")?($(b).scrollTop($(b).scrollTop()-18),$(this).parent().children("div.scroll_down_pas").addClass("scroll_down_act"),$(this).parent().children("div.scroll_down_pas").removeClass("scroll_down_pas"),0==$(b).scrollTop()&&($(this).removeClass("scroll_up_act"),$(this).addClass("scroll_up_pas"))): $(this).hasClass("scroll_down_act")&&($(b).scrollTop($(b).scrollTop()+18),$(this).parent().children("div.scroll_up_pas").addClass("scroll_up_act"),$(this).parent().children("div.scroll_up_pas").removeClass("scroll_up_pas"),$(b).prop("scrollHeight")-$(b).scrollTop()==$(b).outerHeight()&&($(this).removeClass("scroll_down_act"),$(this).addClass("scroll_down_pas")));a.cancelBubble=!0;a.stopPropagation&&a.stopPropagation()});$(this).children("ul").mousewheel($(this).submenu_mousewheel)});$(a).children("li.submenu").children("*:not(a, span)").hide(); $(a).hide()},submenu_mousewheel:function(a,d){0<d?$(this).parent().children("div.scroll_up_act").click():0>d&&$(this).parent().children("div.scroll_down_act").click()},menu_keypress:function(a){switch(a.keyCode){case 13:$(a.data.menu).find("li a.hover").trigger("click");break;case 27:$(document).trigger("click")}},document_click:function(a){$(document).unbind("click",$(this).document_click).unbind("keypress",$(this).menu_keypress);$(".contextRow").removeClass("contextRow");$(a.data.menu).fadeOut(a.data.o.outSpeed); return!1}})}(jQuery);