/*Sidebar fixed Function*/
var ScrollSidebar = new Class({
  
  Implements: [Options],
  
  options: {
    offsets: { x:0, y:0 },
    mode: 'vertical',
    positionVertical: 'top',
    positionHorizontal: 'right',
    speed: 400
  },
  
  initialize: function(menu,options) {
    /* initial options */
    this.setOptions(options);
    this.menu = $(menu);
    this.move = this.options.mode == 'vertical' ? 'y' : 'x';
    this.property = this.move == 'y' ? 'positionVertical' : 'positionHorizontal';
    /* ensure a few things */
    var css = { position: 'absolute', display:'block' };
    css[this.options.positionVertical] = this.options.offsets.y;
    css[this.options.positionHorizontal] = this.options.offsets.x;
    this.menu.setStyles(css).set('tween',{ duration: this.options.speed });
    /* start listening */
    this.startListeners();
	
  },
  
  startListeners: function() {
    var action = function() {
      //this.setPosition($(document.body).getScroll()[this.move] + this.options.offsets[this.move]);
	  var bodyScroll = $(document.body).getScroll();
	  var getScrollY = bodyScroll.y;
	  // alert(getScrollY);
	  // if the window scroll is less than 150
	  if(getScrollY > 150){
		// this.setPosition($(document.body).getScroll()[this.move] + this.options.offsets[this.move]);
		  this.setPosition($(document.body).getScroll()[this.move] + -145);
	  }else{
	  // else
	  this.setPosition(0); 
	 
	  }
	  //alert($(document.body).getScroll()[this.move]);
    }.bind(this);
    window.addEvent('scroll',action);
    window.addEvent('load',action);
  },
  
  setInitPosition: function(pos) {
	//if(animate == true){
    	this.menu.setStyle('top',pos+'px');
	//}else{
		// this.menu.tween(this.options[this.property],move);
	//}
    return this;
  },
  
  setPosition: function(move) {	
    	this.menu.tween(this.options[this.property],move);
    return this;
  }
});

window.addEvent('load',function(){
	$('fixed-scroll').set('opacity',1); //opacity effect for fun
	// var bodyScroll = $(document.body).getScroll();
	 //var getScrollY = bodyScroll.y;
});

/* usage */
window.addEvent('domready',function() {
  $('fixed-scroll').set('opacity',1); //opacity effect for fun
  var sidebar = new ScrollSidebar('fixed-scroll',{
    offsets: {
      x: 0,
      y: 0
    }
  });
});
