/* Create a closure to maintain scope of the '$'
   and remain compatible with other frameworks.  */

(function($) {
	
	//same as $(document).ready();
	$(function() {

        $('#opentable').hide().center();
        
        $('<a href="#" class="close">close</a>').appendTo($('#opentable'));
        
        // Keep #opentable centered w/o using pos:fixed
        $(window).resize(function() { $('#opentable').center(); });
        $(window).scroll(function() { $('#opentable').center(); });

        $('.reserve').click(function(e) {
            $('#opentable').fadeIn().center();
            e.preventDefault();
        });

        $('.close').live('click',function(e) {
            e.preventDefault();
            var parent = $(this).parent().attr('id');
            $('#'+parent).fadeOut();
        });

        $('#OT_Find_a_Table').live(function() {
            $(this).unbind('click');
        });

	});

	$(window).bind("load", function() {
	});
	
})(jQuery);

// Center Function
(function($){
    $.fn.extend({
        center: function () {
            return this.each(function() {
                var top = ( ($(window).height() - $(this).outerHeight()) / 2 ) + $(window).scrollTop();
                var left = ( ($(window).width() - $(this).outerWidth()) / 2 ) + $(window).scrollLeft();
                $(this).css({position:'absolute', margin:0, top: top+'px', left: left+'px'});
            });
        }
    }); 
})(jQuery);

