// VERTICALLY ALIGN FUNCTION (MARGIN)
$.fn.vAlign = function() {
	return this.each(function(i){
	var ah = $(this).height();
	var ph = $(this).parent().height();
	var mh = (ph - ah) / 2;
	
	mh = (mh >= 0) ? mh : 0;

	$(this).css('margin-top', mh);
	});
};

// VERTICALLY ALIGN FUNCTION (PADDING)
$.fn.vAlignP = function() {
	return this.each(function(i){
	var ah = $(this).height();
	var ph = $(this).parent().height();
	var mh = (ph - ah) / 2;
	
	mh = (mh >= 0) ? mh : 0;

	$(this).css('padding-top', mh);
	});
};

 $.fn.smartBackgroundImage = function(url, fade){
	var t = this;
	//create an img so the browser will download the image:
	if (jQuery.support.opacity && fade)
    {
        $(this).css("opacity",0);
    }
    
	$('<img />')
		.attr('src', url)
		.load(function(){ //attach onload to set background-image
			t.each(function(){ 
				$(this).css('backgroundImage', 'url('+url+')' );
				if (jQuery.support.opacity && fade)
			    {
			        $(this).fadeTo(2000,1);
			    }
			});
		});
	return this;
}
