(function(d){var e=d(document),r=/maxthon[\/: ]2/i.test(navigator.userAgent)?0:2,i={contextMenu:"contextMenu",contextMenuActive:"contextMenuActive"};d.fn.contextMenu=function(a,k,l,m){a.juery||(a=d(a));if(!a.length)return this;a.addClass(i.contextMenu);this.each(function(){var b=d(this),n=b.offset();b.bind("contextMenu",function(j,f){d("ul."+i.contextMenu).blur();var g=f.pageX,h=f.pageY;a.css({visibility:"hidden",display:"block"});var o=a[0].offsetHeight,p=a[0].offsetWidth,s=e.scrollLeft(),t=e.scrollTop();
if(h+o-t>(document.compatMode=="CSS1Compat"?document.documentElement.clientHeight:document.body.clientHeight))h-=o;if(g+p-s>(document.compatMode=="CSS1Compat"?document.documentElement.clientWidth:document.body.clientWidth))g-=p;a.css({top:h,left:g,visibility:"visible"});b.addClass(i.contextMenuActive);typeof l=="function"&&l(b);e.unbind("mousedown.contextMenu");var q=function(){e.unbind("mousedown.contextMenu");a.hide();b.removeClass(i.contextMenuActive);typeof m=="function"&&m(b);return false},u=
function(c){a.find("*").index(c.target)!=-1||q()};a.blur(q);setTimeout(function(){e.bind("mousedown.contextMenu",u)},0);a.find("a").unbind("click.contextMenu").bind("click.contextMenu",function(c){c.stopPropagation();c.preventDefault();a.blur();c=this.getAttribute("href",2);c=c.substr(c.lastIndexOf("#")+1);k&&k(c,b,{x:g-n.left,y:h-n.top,docX:g,docY:h})});return false}).mousedown(function(j){j.button==r&&(j.stopPropagation(),e.mousedown(),b.bind("mouseup.contextMenu",function(f){f.stopPropagation();
b.unbind("mouseup.contextMenu");b.trigger("contextMenu",[f])}))})}).add(a).bind("contextmenu",function(){return false});if(d.browser.mozilla)a.css("MozUserSelect","none");else d.browser.msie?a.bind("selectstart.disableTextSelect",function(){return false}):a.bind("mousedown.disableTextSelect",function(){return false});return this}})(jQuery);
