if (typeof madhouse === 'undefined') {
	var madhouse = {};
}

madhouse.share = function() {
	this.share = $('.shareBar');
	this.cont = this.share.parent('.wShareScroll');
	
	if (!this.share.length || !this.cont.length) {
		return;
	}
	
	this.shareHeight = this.share.height();
	this.scrollAdd = parseInt(this.share.css('top')) + this.shareHeight;
	this.stop = this.cont.position().top + this.cont.height();
	this.originalTop = 	this.share.css('top');

	this.setEvents();
};

madhouse.share.prototype.setEvents = function() {
	var self = this;

	$(window).bind('scroll', { self: self }, self.moveBox);
};

madhouse.share.prototype.moveBox= function(e) {
	e.preventDefault();

	var self = e.data.self,
		pos = $(window).scrollTop() + self.scrollAdd;

	if (pos > self.stop) {
		self.share.css({
			'position': 'absolute',
			'top': self.stop - self.shareHeight + 'px'
		});
	} else {
		self.share.css({
			'position': 'fixed',
			'top': self.originalTop
		});
	}
}

