/**
 * @fileoverview frozAutoCenter plugin
 * @author Lawrence Natividad
 * @copyright Copyright ( c ) 2010 Frozynart Designs
 * @license Licensed under MIT ( http://www.frozynart.com/license/mit )
 * @version: 1.0 2010-04-29
 */
 
( function( $ ) {
    /**
     * Auto centering of elements
     * @namespace frozAutoCenter Plugin Namespace
     * @requires jQuery 1.2.6 and above
     * @example jQuery( "#id-of-list-that-contains-thumbnails" ).frozAutoCenter
     * @return {jQuery Object}
     */
    jQuery.fn.frozAutoCenter = function( options ) {
        var opts                            = jQuery.extend( {}, jQuery.fn.frozAutoCenter.defaults, options );
        jQuery.fn.frozAutoCenter.opts       = opts;
        var $this                           = jQuery( this );
        
        if ( opts.relativeTo === null ){
            return false;
        }
        
        if (opts.verticalCenter === false){
            var canvas = jQuery(opts.relativeTo).width();
            var size = $this.innerWidth();
            if (canvas >= size){
                var spacing = ((canvas - size)/2).toFixed(0);
                var finalSpacing = Number(spacing) + Number(opts.offsetLeft);
                $this.css({left: finalSpacing + 'px'});
            }
        } else {
            var canvas = jQuery(opts.relativeTo).height();
            var size = $this.innerHeight();
            if (canvas >= size){
                var spacing = ((canvas - size)/2).toFixed(0);
                var finalSpacing = Number(spacing) + Number(opts.offsetTop);
                $this.css({top: finalSpacing + 'px'});
            }
        }
        
        return $this;
    };

    /** 
     * Sends a message to the console
     * @private
     */
    var _debug = function( message ) {
        if ( true === jQuery.fn.frozAutoCenter.opts.debug ) {
            console.log( message );
        }
    };
    
    /**
     * <pre> 
     * Settings
     *
     * Setting            Default            Description
     * ------------------------------------------------------------------------------------------
     * mainContent:    "header-content"   ID of block which contains slide contents
     *
     * </pre>
     */
    jQuery.fn.frozAutoCenter.defaults =   {
        verticalCenter: false,
        relativeTo: null,
        offsetTop: 0,
        offsetLeft: 0
    };
} )(jQuery);

