(function() {
	
	window.iStickyBar = window.iStickyBar || function(context, bar_el) {
		this.context = $(context);
	    this.bar_el = $(bar_el);
	    this.reposition();
	}
	
	iStickyBar.prototype.reposition = function() {
	    var window_height = $(window).height();
	    var document_scroll_offset = $(document).scrollTop();
	    var context_height = this.context.outerHeight();
	    
	    if ((document_scroll_offset + window_height) < context_height)
	    	this.bar_el.css('position', 'fixed');
	    else
	    	this.bar_el.css('position', 'absolute');
	};
	
})(document);


(function(document) {
	
	window.Inquiry = window.Inquiry || function() {
		var me = this;
		var el = this.el = $('#inquiry-panel');
		el.addClass('closed');
		
		$('.tab a', el).bind('click', function(e) {	
		    if (el.hasClass('closed')) me.open(); else me.close();
		    return false;
		});
		
		$(document).bind('keyup', function(e) {
		    var code = (e.keyCode ? e.keyCode : e.which);
		    if(code == 27) {
		    	if (!el.hasClass('closed')) me.close();
		    }
		});
		
		this.reposition();
	};
	
	Inquiry.prototype.open = function() {
	    this.el.animate({right: '0px' }, { duration: 400, easing: 'easeOutQuart', queue: false });
	    this.el.toggleClass('closed');
	};
	
	Inquiry.prototype.close = function() {
	    this.el.animate({ right: '-390px' }, { duration: 200, easing: 'easeOutQuart', queue: false });
	    this.el.toggleClass('closed');
	};
	
	Inquiry.prototype.reposition = function() {
	    $('#inquiry-panel').css('top', function() {
	    	return ($(window).height() - $(this).height()) / 2 + 'px';
	    });
	};
	
})(document);
