// control sizing of overlays

$(document).ready(function() {
	
	// create a copy of the standard .show() function
	var _oldShow = $.fn.show;

    // overwrite .show() to allow triggering of "beforeShow" and "afterShow" events.  
	// The "beforeShow" event will allow us to properly size the overlay div for lightboxes
	// based on current page dimensions (document width & height) regardless of any changes 
	// to the size of the current document that may have been made since the load
	
	$.fn.show = function(speed, oldCallback) {
        return $(this).each(function() {
                var
                        obj         = $(this),
                        // create a new callback function that first runs the explicit callback function,
						// then triggers the "afterShow" event
						newCallback = function() {
                                if ($.isFunction(oldCallback)) {
                                        oldCallback.apply(obj);
                                }

                                // trigger "afterShow" event
								obj.trigger('afterShow');
                        };

                // trigger "beforeShow" event
                obj.trigger('beforeShow');

                // use the old function (which we copied earlier) to show the element passing the new callback
                _oldShow.apply(obj, [speed, newCallback]);
        });
    }
	
	$(".overlay").bind("beforeShow",function() {
		$(this).css({'width':$(document).width()+"px"});
		$(this).css({'height':$(document).height()+"px"});							 
	});
	
});
