/**
 *	Title: Jquery vAlign plugin
 *	Description:	Found here: http://cool-javascripts.com/jquery/vertical-alignment-of-contents-inside-an-element-using-jquery.html
 *
 *
 * @author Marc Raiser <marc.raiser@keboola.com>
 */

(function ($) {
    $.fn.vAlign = function(arg, container) {
        return this.each(function(i){
	   if(container == null) {
	      container = 'div';
	   }
	   var paddingPx = 0; //change this value as you need (It is the extra height for the parent element)
	   if ($(this).children(container).length == 0)
	   {
		   $(this).html("<" + container + ">" + $(this).html() + "</" + container + ">");
	   }
	   var el = $(this).children(container + ":first");
	   var elh = $(el).height(); //new element height
	   var ph = $(this).parent().height(); //parent height
	   if(elh > ph) { //if new element height is larger apply this to parent
	       $(this).height(elh + paddingPx);
	       ph = elh + paddingPx;
	   }

	   if (arg == 'middle')
	   {
			var nh = (ph - elh) / 2; //new margin to apply
	   }else if (arg == 'bottom'){
			var nh = (ph - elh) - 10; // for bottom alignment
	   }else{
			var nh = 10; // for top alignment do not add any margin
	   }
	   $(el).css({
		   'margin-top': nh
	   });

		});
     };
})(jQuery);
