
jQuery.fn.gapfilling = function(options){
    var options = jQuery.extend({
    },options);
    return this.each(function() {
        if(options.window){
            var hw = $(options.window).height();
            var o = $("#"+options.window).offset();
            if ( ( jQuery("#"+options.window).height() + o.top + 5 ) < $(window).height() ){
                if ( jQuery(this).scrollTop() ){
                    jQuery(this).attr("rows", jQuery(this).attr("rows") + 1);
                }
            }
        }
    });
};

jQuery.fn.pcenter = function(options){
    var options = jQuery.extend({
    },options);
    return this.each(function() {
        jQuery(this).css("position","absolute");
        jQuery(this).css("left",(jQuery(window).width() / 2 - jQuery(this).outerWidth()/2 + (jQuery(window).scrollLeft() ? (jQuery(window).scrollLeft() -16) : 0 )));
        jQuery(this).css("top",(jQuery(window).height()/2 - jQuery(this).outerHeight()/2 + jQuery(window).scrollTop()));
        if( jQuery(this).outerHeight() > jQuery(window).height() ){
	    jQuery(this).height(jQuery(window).height()-(jQuery(this).outerHeight()-jQuery(this).height()*2));
            jQuery(this).css("top",(jQuery(window).height()/2 - jQuery(this).outerHeight()/2 + jQuery(window).scrollTop()))
        }
    });
};

jQuery.fn.pbottom = function(options){
    var options = jQuery.extend({
    },options);
    return this.each(function() {
        jQuery(this).css("position","fixed");
        jQuery(this).css("left",(jQuery(window).width() / 2 - jQuery(this).outerWidth()/2 + (jQuery(window).scrollLeft() ? jQuery(window).scrollLeft() -16 : 0 )));
        jQuery(this).css("top",(jQuery(window).height()- 4 - jQuery(this).outerHeight() + jQuery(window).scrollTop()));
    });
};

jQuery.fn.pright = function(options){
    var options = jQuery.extend({
    },options);
    return this.each(function() {
        jQuery(this).css("position","fixed");
        jQuery(this).css("left",(jQuery(window).width() - jQuery(this).outerWidth() + (jQuery(window).scrollLeft() ? jQuery(window).scrollLeft() -16 : 0 )));
        jQuery(this).css("top",(jQuery(window).height()/2 - jQuery(this).outerHeight()/2 + jQuery(window).scrollTop()));
    });
};

jQuery.fn.prightTop = function(options){
    var options = jQuery.extend({
    },options);
    return this.each(function() {
        jQuery(this).css("position","fixed");
        jQuery(this).css("left",(jQuery(window).width() - jQuery(this).outerWidth() + (jQuery(window).scrollLeft() ? jQuery(window).scrollLeft() -16 : 0 )));
        jQuery(this).css("top","0");
    });
};
jQuery.fn.prightBottom = function(options){
    var options = jQuery.extend({
    },options);
    return this.each(function() {
        jQuery(this).css("position","fixed");
        jQuery(this).css("left",(jQuery(window).width() - jQuery(this).outerWidth() + (jQuery(window).scrollLeft() ? jQuery(window).scrollLeft() -16 : 0 )));
        jQuery(this).css("top",(jQuery(window).height() - jQuery(this).outerHeight() + jQuery(window).scrollTop()));
    });
};

jQuery.fn.pleft = function(options){
    var options = jQuery.extend({
    },options);
    return this.each(function() {
        jQuery(this).css("position","fixed");
        jQuery(this).css("left", 0 );
        jQuery(this).css("top",(jQuery(window).height()/2 - jQuery(this).outerHeight()/2 + jQuery(window).scrollTop()));
    });
};

jQuery.fn.pleftBottom = function(options){
    var options = jQuery.extend({
    },options);
    return this.each(function() {
        jQuery(this).css("position","fixed");
        jQuery(this).css("left",0);
	jQuery(this).css("top",(jQuery(window).height() - jQuery(this).outerHeight() + jQuery(window).scrollTop()));
    });
};

jQuery.fn.ptopCenter = function(options){
    var options = jQuery.extend({
    },options);
    return this.each(function() {
        jQuery(this).css("position","fixed");
        jQuery(this).css("left",(jQuery(window).width()/2 - jQuery(this).outerWidth()/2 + (jQuery(window).scrollLeft() ? jQuery(window).scrollLeft() -16 : 0 )));
        jQuery(this).css("top",0);
    });
};
jQuery.fn.pwindow = function(options){
    var options = jQuery.extend({
    },options);
    return this.each(function() {
        jQuery(this).css("position","absolute");
        jQuery(this).css("left",0);
        jQuery(this).css("top",0);
        jQuery(this).css("width",( jQuery(window).width() - 48 - ( jQuery(window).scrollTop() ? 16 : 0 ) ));
        jQuery(this).css("height",( jQuery(window).height() - 48 - ( jQuery(window).scrollLeft() ? 16 : 0 ) ));
	jQuery(this).children("table").attr("width","100%");
	if (jQuery(this).find("textarea").attr("rows") == "-1") {
	    jQuery(this).find("textarea").height(0);
	    jQuery(this).find("textarea").height(jQuery(window).height()-jQuery(this).height())
	}
    });
};

