/*
    -----------------------------------------------------------
    jQuery Plug in to center Elements into a Parent Container
    
    By Laureano Arcanio
    
    larcanio@gmail.com
    laureano.arcanio@pylabs.com
    
    26/11/2009
    
    -----------------------------------------------------------
    Example:
    
    $(document).ready(function() {
        $("#child").center({
        		vertical: true,
            horizontal: true
        })
    });
    
    
    Demo HTML
    
    <div id="container">
        <div id="child">
        
        </div>
    </div>

    Demo CSS
    
    <style>
        #container {
            height: 400px;
            width: 400px;
            border: 1px solid black;
        }
        #child {
            height: 100px;
            width: 100px;
            border: 1px solid black;
        }
    </style>

*/

jQuery.fn.center = function(params) {
    // Plug in to center Elements into parent Container
	var options = {
		vertical: true,
		horizontal: true
	}
	
	var op = jQuery.extend(options, params);
    
    // Child and Parent Objects
    var parent = $(this).parent();
    var child = $(this);

    var p_width = parent.width();
    var p_height = parent.height(); 
    var c_width = child.width();
    var c_height = child.height(); 

    var blank_w = (p_width - c_width) / 2;
    var blank_h = (p_height - c_height) / 2;

    if (op.horizontal)
        child.css({'margin-left': blank_w});
    if (op.vertical)
        child.css({'margin-top': blank_h});

    // Removes the Parent Padding
    parent.css({'padding:': '0px'})
    
    return child;
};



