/**
 * See guide: http://www.learningjquery.com/2007/10/a-plugin-development-pattern
 */

//
// create closure
//
(function($) {
    //
    // plugin definition
    //
    $.fn.box = function(options) {
        // build main options before element iteration
        var opts = $.extend({}, $.fn.box.defaults, options);

        // iterate and reformat each matched element
        return this.each(function() {
            $this = $(this);
            
            // build element specific options
            var o = $.meta ? $.extend({}, opts, $this.data()) : opts;

            // update element styles
            $this.css({
                backgroundColor: o.background,
                color: o.foreground
            });

            // alert(o.foreground);

            // $this.css("background-color", o.background);
            // $this.css("color", o.foreground);

            //alert("poi");

            var markup = $this.html();

            // call our format function
            markup = $.fn.box.format(o, markup);

            $this.html(markup);
        });
    };

    //
    // define and expose our format function
    //
    $.fn.box.format = function(opt, txt) {
        var content = "<div style='padding: 10px; height: "+ opt.height + "'>" + txt + "</div>";

        var borderClass = "borders";

        if (opt.bordercolor == 'red') {
            borderClass = "redborders";
        } if (opt.bordercolor == 'pink') {
            borderClass = "pinkborders";
        }

        return "<div class='"
                + borderClass 
                + "'><i class='tl'></i><i class='tr'></i><i class='bl'></i><i class='br'></i>"
                + content
                + "</div>"
    };

    //
    // plugin defaults
    //
    $.fn.box.defaults = {
        height: 'auto',
        bordercolor: 'grey',
        // Not working under IE6 !!!
        // foreground: 'inherit',
        // background: 'inherit'
        foreground: 'black',
        background: 'white'

    };
    //
    // end of closure
    //
})(jQuery);


