/*
 * Box
 * Created by Alberto Arena
 * Box is made for the jQuery library.
 */

/* 
 * @name box
 * @type jQuery
 * @param Map options Optional settings
 * @option Number width Width in pixels of the box
 * @option Number height Height in pixels of the box
 * @option String radius Radius of corners. Default: 8px
 */
jQuery.fn.extend({
	box: function(options) {
		jQueryBox(this, options);
	}
});

function jQueryBox( element, options ) {
	if ( element.data("jquerybox") )
		return;

	var boxWidth = element.css("width");;
	var boxHeight = element.css("height");;
	var boxRadius = "8px";
	var boxHeader = "";
	var boxFooter = "";
	var debug = false;
	
	if(options){
		if(options["width"] != null)
			boxWidth = parseInt(options["width"]);
		if(options["height"] != null)
			boxHeight = parseInt(options["height"]);
		if(options["radius"] != null)
			boxRadius = options["radius"];
		if(options["header"] != null)
			boxHeader = options["header"];
		if(options["footer"] != null)
			boxFooter = options["footer"];
		if(options["debug"] == true )
			debug = true;
	}

	element.css("width",boxWidth);
	element.css("height",boxHeight);
	element.data("jquerybox",true);
	
	var boxRadiusInt = parseInt(boxRadius);
	element.addClass("box-corner"+boxRadiusInt+"-all");
	$.uicornerfixClass('box-corner'+boxRadiusInt,boxRadius);

	if ( boxHeader != "" ) {
		var headerId = element.attr("id") + "-header";
		if ( element.filter('#'+headerId).length == 0 ) {
			element.prepend('<div id="'+headerId+'">'+boxHeader+"</div>");
		}
	}
	if ( boxFooter != "" ) {
		element.wrap("<div style='position:relative'></div>");	
		var footerId = element.attr("id") + "-footer";
		element.append('<div id="'+footerId+'" style="position:absolute;bottom:0;margin:0;padding:0;padding-bottom:6px;"><div style="position:relative; top:40%; margin-left:5px;">'+boxFooter+"</div></div>");
	}
}