// JavaScript Document

(function ($) {
		   
	$.fn.borderize = function (options) {
		var opts = $.extend({}, $.fn.borderize.defaults, options);
		
		return this.each(function(){
			var client = $(this);
			var wrapperWidth = client.width() + 8 - opts.left;
			var wrapperHeight = client.height() + 8 - opts.top;
			//var borderWidth = wrapperWidth - 23;
			//var borderHeight = wrapperHeight - 24;
			
			if (!client.hasClass('bordered')) {
							
			client.wrap($("<div></div>").css({
					'position' : 'relative', 
					'width' : wrapperWidth + 'px', 
					'height' : wrapperHeight + 'px',
					'overflow' : 'auto',
					'margin' : opts.margin
			}));
			
			client.css({ 'margin' : '3px 0px 0px 3px' });

		
			client.before($("<div></div>").css({
					'position' : 'absolute', 
					'top' : '0px', 
					'left' : '0px', 
					'width' : '12px', 
					'height' : '12px', 
					'z-index' : '999999',
					'background-image' : 'url(' + opts.imagePath + 'cadre-coins' + '.png)',
					'background-repeat' : 'no-repeat',
					'background-position' : '0px 0px'
			}));
			
			client.before($("<div></div>").css({
					'position' : 'absolute', 
					'top' : '0px', 
					'left' : '12px', 
					'width' : client.width() - 17 - opts.left + 'px', 
					'height' : '3px', 
					'z-index' : '999999',
					'background-image' : 'url(' + opts.imagePath + 'cadre-bordure-haut' + '.png)',
					'background-repeat' : 'repeat-x'
			}));
			
			client.before($("<div></div>").css({
					'position' : 'absolute', 
					'top' : '0px', 
					'right' : '0px', 
					'width' : '13px', 
					'height' : '12px', 
					'z-index' : '999999',
					'background-image' : 'url(' + opts.imagePath + 'cadre-coins' + '.png)',
					'background-repeat' : 'no-repeat',
					'background-position' : '-12px 0px'
			}));
			
			client.before($("<div></div>").css({
					'position' : 'absolute', 
					'top' : '12px', 
					'right' : '0px', 
					'width' : '5px', 
					'height' : client.height() - 19 - opts.top + 'px', 
					'z-index' : '999999',
					'background-image' : 'url(' + opts.imagePath + 'cadre-bordure-droite' + '.png)',
					'background-repeat' : 'repeat-y'
			}));
			
			client.before($("<div></div>").css({
					'position' : 'absolute', 
					'bottom' : '0px', 
					'right' : '0px', 
					'width' : '13px', 
					'height' : '15px', 
					'z-index' : '999999',
					'background-image' : 'url(' + opts.imagePath + 'cadre-coins' + '.png)',
					'background-repeat' : 'no-repeat',
					'background-position' : '-12px -12px'
			}));
			
			client.before($("<div></div>").css({
					'position' : 'absolute', 
					'bottom' : '0px', 
					'left' : '12px', 
					'width' : client.width() - 17 - opts.left + 'px', 
					'height' : '5px', 
					'z-index' : '999999',
					'background-image' : 'url(' + opts.imagePath + 'cadre-bordure-bas' + '.png)',
					'background-repeat' : 'repeat-x'
			}));
			
			client.before($("<div></div>").css({
					'position' : 'absolute', 
					'bottom' : '0px', 
					'left' : '0px', 
					'width' : '12px', 
					'height' : '15px', 
					'z-index' : '999999',
					'background-image' : 'url(' + opts.imagePath + 'cadre-coins' + '.png)',
					'background-repeat' : 'no-repeat',
					'background-position' : '0px -12px'
			}));
			
			client.before($("<div></div>").css({
					'position' : 'absolute', 
					'top' : '12px', 
					'left' : '0px', 
					'width' : '3px', 
					'height' : client.height() - 19 - opts.top + 'px', 
					'z-index' : '999999',
					'background-image' : 'url(' + opts.imagePath + 'cadre-bordure-gauche' + '.png)',
					'background-repeat' : 'repeat-y'
			}));
			
			client.addClass('bordered');
			
			}
			
			
		
		});
		
	};
	
	$.fn.borderize.defaults = {
		imagePath : "squelettes/images/bordures/",
		left: 0,
		top: 0,
		margin: "0px auto"
	}; 
	
})(jQuery);

