var Planeffect = window.Planeffect || {};

Planeffect.DragHeader = function() {
	var $window, $header_wrap;
	var header_height = 0;
	var stop_top = 0;
	var top_snap = 20;
	var stop_bottom = 100;

	return {
		init: function(id, handle) {
			$window = $(window);
			$header_wrap = $(id || '#header-wrap');
	
			header_height = $header_wrap.height() + parseInt($header_wrap.css('padding-top'));
			
			$window.resize(function(){
				stop_top = $window.height() - header_height - stop_bottom;
			}).resize();
			
			$(handle || '#drag-me').css({display: 'block'});
			
			$header_wrap.draggable({
				axis: "y",
				handle: handle || '#drag-me',
				scroll: false,
				drag: function(event, ui) {
					if (ui.position.top > stop_top) {
						ui.position.top = stop_top;
					} else if (ui.position.top < top_snap) {
						ui.position.top = 0;
					}
				}
			});
		}
	};
}();

