/*
 * Vertical Align & Horizontal Align
 */

(function ($) {
	$.fn.vAlign = function() {
		return this.each(function(i){
			var h = $(this).height();
			var oh = $(this).outerHeight();
			var mt = (h + (oh - h)) / 2;
			$(this).css("margin-top", "-" + mt + "px");
			$(this).css("top", "50%");
			$(this).css("position", "absolute");
		});
	};
})(jQuery);
 
(function ($) {
	$.fn.hAlign = function() {
		return this.each(function(i){
			var w = $(this).width();
			var ow = $(this).outerWidth();
			var ml = (w + (ow - w)) / 2;
			$(this).css("margin-left", "-" + ml + "px");
			$(this).css("left", "50%");
			$(this).css("position", "absolute");
		});
	};
})(jQuery);

/* 
 * Création Seb: centrage vertical de 2 blocks
 */
(function ($) {
	$.fn.verticalAlignBlock = function() {
		return this.each(function(i){
			var hBox 	= $( this ).height( );
			var hParent = $( this ).parent( ).height( );
			if ( hBox > hParent ) { 
				// alert( 'Erreur verticalAlign: Le contenu ne peut etre plus grand que le conteneur.' );
				$( this ).css( 'border', '3px solid #ff0000' ).css( 'background', '#ff8888' );
			} else {
				var diff	= Math.floor( ( hParent / 2 ) - ( hBox / 2 ) );
				if ( diff < 0 ) {
					// alert( 'Erreur verticalAlign: Le script connait un probleme. (le resultat est negatif)' );
					$( this ).css( 'border', '3px solid #ff0000' ).css( 'background', '#ff8888' );
				} else {
					$( this ).parent( ).css( 'position', 'relative' );
					$( this ).css( 'position', 'relative' ).css( 'top', diff + 'px' );
				}
			}
		});
	};
})(jQuery);

/* 
 * Création Seb: centrage texte dans un block
 */
(function ($) {
	$.fn.verticalAlignText = function() {
		return this.each(function(i){
			
			var text	= $( this ).text( );
			
			$( this ).html( '<div class="valign-center"></div>' );
			$( this ).find( '.valign-center' ).text( text );

			$( '.valign-center' ).verticalAlignBlock( );
		});
	};
})(jQuery);

