LeftMenu = Class.create( {
	initialize : function(){
		this.iInitOffset = $('leftMenuAndIcon').positionedOffset().top;
		this.iOffsetDecal = 10;
		
		Event.observe(window, 'scroll', this.onScroll.bind(this));
		Event.observe(window, 'resize', this.onScroll.bind(this));
		this.onScroll();
	},
	onScroll: function(){
		var iDocScrollOFfset 	= document.viewport.getScrollOffsets()[1]; 
		var oContentWrapperLayout = $('contentWrapper').getLayout();
		
		var iMenuHeight 	= $('leftMenuAndIcon').getHeight();
		var iDocHeight 		= document.viewport.getHeight();
		var iDocBasDePage 	= oContentWrapperLayout.get('top') + oContentWrapperLayout.get('padding-top') + oContentWrapperLayout.get('height');
		
		if(iMenuHeight < iDocHeight){
			if((iDocScrollOFfset + this.iOffsetDecal) > this.iInitOffset){
				if($('leftMenuAndIcon').getStyle('position')!='fixed'){
					$('leftMenuAndIcon').setStyle({position:'fixed'});
				}
				
				var oLayoutMenu = new Element.Layout('leftMenuAndIcon');
				var iBottomMenu = -oLayoutMenu.get('bottom')+oLayoutMenu.get('height')-oLayoutMenu.get('top')+this.iInitOffset;
				// var iDiff = Abs(iDocBasDePage - iBottomMenu);
				var iDiff;
				if (iDocBasDePage > iBottomMenu) iDiff = iDocBasDePage - iBottomMenu; else iDiff = iBottomMenu - iDocBasDePage;
				
				var iOffsetTop = Math.min(iDiff, this.iOffsetDecal);
				$('leftMenuAndIcon').setStyle({top:iOffsetTop+'px'});
				
			}else if($('leftMenuAndIcon').getStyle('position')=='fixed'){
				$('leftMenuAndIcon').setStyle({position:'static'});
			}
		}else if($('leftMenuAndIcon').getStyle('position')=='fixed'){
			$('leftMenuAndIcon').setStyle({position:'static'});
		}
	}
});

RightMenu = Class.create( {
	initialize : function(){
		this.iInitOffset = $('rightMenuAndIcon').positionedOffset().top;
		this.iOffsetDecal = 10;
		
		Event.observe(window, 'scroll', this.onScroll.bind(this));
		Event.observe(window, 'resize', this.onScroll.bind(this));
		this.onScroll();
	},
	onScroll: function(){
		var iDocScrollOFfset 	= document.viewport.getScrollOffsets()[1]; 
		var oContentWrapperLayout = $('contentWrapper').getLayout();
		
		var iMenuHeight 	= $('rightMenuAndIcon').getHeight();
		var iDocHeight 		= document.viewport.getHeight();
		var iDocBasDePage 	= oContentWrapperLayout.get('top') + oContentWrapperLayout.get('padding-top') + oContentWrapperLayout.get('height');
		
		if(iMenuHeight < iDocHeight){
			if((iDocScrollOFfset + this.iOffsetDecal) > this.iInitOffset){
				if($('rightMenuAndIcon').getStyle('position')!='fixed'){
					$('rightMenuAndIcon').setStyle({position:'fixed'});
				}
				
				var oLayoutMenu = new Element.Layout('rightMenuAndIcon');
				var iBottomMenu = -oLayoutMenu.get('bottom')+oLayoutMenu.get('height')-oLayoutMenu.get('top')+this.iInitOffset;
				// var iDiff = Abs(iDocBasDePage - iBottomMenu);
				var iDiff;
				if (iDocBasDePage > iBottomMenu) iDiff = iDocBasDePage - iBottomMenu; else iDiff = iBottomMenu - iDocBasDePage;
				
				var iOffsetTop = Math.min(iDiff, this.iOffsetDecal);
				$('rightMenuAndIcon').setStyle({top:iOffsetTop+'px'});
				
			}else if($('rightMenuAndIcon').getStyle('position')=='fixed'){
				$('rightMenuAndIcon').setStyle({position:'static'});
			}
		}else if($('rightMenuAndIcon').getStyle('position')=='fixed'){
			$('rightMenuAndIcon').setStyle({position:'static'});
		}
	}
});
		
