(function($){$.fn.sidebar=function(method){var defaults={colWidth:'180px',showOn:'click',stickTo:'left'},methods={init:function(opts){return this.each(function(){var $sidebar=$(this);var props=$.extend({},defaults,opts);if(!$sidebar.hasClass('sidebar'))$sidebar.addClass('sidebar');if(props.stickTo=='right')$sidebar.addClass('sidebar-right');if(props.showOn=='hover')props.showOn='mouseenter mouseleave';$sidebar.addClass('sidebar-js').css('top',(($(window).height()-$sidebar.height())/2)).find('a[href="#"]').bind('click',function(e){e.preventDefault();}).end().children('li').children('a').bind(props.showOn,function(){if($(this).siblings().hasClass('sidebar-active'))return false;methods.hide();$(this).append('<span class="sidebar-arrow"></span>').siblings().each(function(){$(this).css({'margin-left':'50px','margin-right':'50px','opacity':0,'top':0}).show();var totalHeight=$(this).height()+$(this).offset().top;var windowHeight=$(window).height()+$(window).scrollTop();var newTop=0;if(totalHeight>windowHeight){newTop=parseInt($(this).css('top'),10)-(totalHeight-windowHeight);};$(this).css({'top':newTop}).animate({'margin-left':'20px','margin-right':'20px','opacity':1.0},200);}).addClass('sidebar-active');return false;});if($.browser.msie||props.colWidth!=defaults.colWidth){for(var i=2;i<10;i++){var newLeft=23+i+(parseInt(props.colWidth,10)*(i-2));var newRight='auto';if(props.stickTo=='right'){newRight=newLeft;newLeft='auto';};$sidebar.find('li').find('ul:nth-child('+i+')').css({'left':newLeft,'right':newRight,'width':props.colWidth});}}});},hide:function(){$('.sidebar-active').animate({'margin-left':'50px','margin-right':'50px','opacity':0},200,function(){$(this).removeClass('sidebar-active').hide();});$('span.sidebar-arrow').remove();}};$(window).resize(function(){$('.sidebar').each(function(){$(this).css('top',($(window).height()/2-$(this).height()/2));});});$(document).click(function(e){if($(e.target).parents().hasClass('sidebar'))return;methods.hide();});if(methods[method]&&method.toLowerCase()!='init'){return methods[method].apply(this,Array.prototype.slice.call(arguments,1));}else if(typeof method==='object'||!method){return methods.init.apply(this,arguments);}else{$.error('Method "'+method+'" does not exist in sidebar');}}})(jQuery);

