/*
 *  yodelbar - Creates a dynamic, vertical sharing bar to the left of a WordPress post and hides it if browser window is too small
 *  Copyright 2010 Monjurul Dolon, http://mdolon.com/
 *  Released under the MIT, BSD, and GPL Licenses.
 *  More information: http://devgrow.com/yodelbar
 */
jQuery(document).ready(function() {
	var yodelbar = jQuery('.pagesidebar');
	var parent = jQuery(yodelbar).parent().width();
	var start = yodelbar_init();

	function yodelbar_init(){
		jQuery.event.add(window, "scroll", yodelbar_scroll);
		if(jQuery(yodelbar).offset()) return jQuery(yodelbar).offset().top;
	}
	function yodelbar_scroll() {
		var scrollposition = jQuery(window).scrollTop();
		var windowwidth = jQuery(window).width();
		var barheight = jQuery("#container").height() - 220 - jQuery(yodelbar).height();
		if(barheight > scrollposition) {
			jQuery(yodelbar).css('position',((scrollposition)>150) ? 'fixed' : 'relative');
			jQuery(yodelbar).css('top',((scrollposition)>145) ? '5px' : '');
			jQuery(yodelbar).css('left',((scrollposition)>150) ? windowwidth/2+270 : '');
		} else {
			jQuery(yodelbar).css('top',barheight-scrollposition); // Stops bar before end of page
		}
	}

});
