/*
 * jQuery JavaScript plugin
 * http://skajewski.com/
 *
 * Copyright (c) 2009 Piotr Skajewski
 * Dual licensed under the MIT and GPL licenses.
 * http://docs.jquery.com/License
 *
 * Date: 2010-06-03 01:41:21 +0000 (Thu, 03 Jun 2010)
 * Revision: 1
 */

(function($){
	$.fn.imgCorner = function(options) {
		//set images corner
		var element = this;
		var elWidth = $(this).outerWidth();
		var elHeight = $(this).outerHeight();
		var imgWidth = 10;
		var imgHeight = 10;
		var defaults = {
			source : {
				float: "left",
				padding: "10px",
				bg: "#ffffff"
			},
			tl : {
				width: imgWidth,
				height: imgHeight,
				bg: 'url(images/mmslt.png)'
			},
			tc : {
				height: imgHeight,
				bg: "#ffffff"
			},
			tr : {
				width: imgWidth,
				height: imgHeight,
				bg: "url(images/mmsrt.png)"
			},
			lc : {
				width: imgWidth,
				bg: "#ffffff"
			},
			rc : {
				width: imgWidth,
				bg: "#ffffff"
			},
			bl : {
				width: imgWidth,
				height: imgHeight,
				bg: "url(images/mmslb.png)"
			},
			bc : {
				height: imgHeight,
				bg: "#ffffff"
			},
			br : {
				width: imgWidth,
				height: imgHeight,
				bg: "url(images/mmsrb.png)"
			}
		};
		var options = $.extend(defaults, options);
		var randId = Math.floor(Math.random()*10000000000);
		var TL = "_" + randId + "imgCornerTL";
		var TC = "_" + randId + "imgCornerTC";
		var TR = "_" + randId + "imgCornerTR";
		var LC = "_" + randId + "imgCornerLC";
		var RC = "_" + randId + "imgCornerRC";
		var BL = "_" + randId + "imgCornerBL";
		var BC = "_" + randId + "imgCornerBC";
		var BR = "_" + randId + "imgCornerBR";
		var CM = "_" + randId + "imgCornerMain";
		var DC = "_" + randId + "imgCornerDC";

		var before = '<div class="' + TL + '"></div><div class="' + TC + '"></div><div class="' + TR + '"></div><div class="' + DC + '"></div><div class="' + LC + '"></div>';
		var after = '<div class="' + RC + '"></div><div class="' + DC + '"></div><div class="' + BL + '"></div><div class="' + BC + '"></div><div class="' + BR + '"></div>';

		$(element).wrap('<div class="' + CM + '" />');
		$(element).css({"float":"left","background":options.source.bg});
		$(element).before(before);
		$(element).after(after);

		$("." + TL).css({'width' : options.tl.width,'height' : options.tl.height,'background' : options.tl.bg,'float':'left'});
		$("." + TC).css({'width' : elWidth,'height' : options.tc.height,'background':options.tc.bg,'float' : 'left'});
		$("." + TR).css({'width' : options.tr.width,'height' : options.tr.height,'background' : options.tr.bg,'float':'left'});

		$("." + LC).css({'width' : options.lc.width,'height' : elHeight,'background':options.lc.bg,'float' : 'left'});
		$("." + RC).css({'width' : options.rc.width,'height' : elHeight,'background':options.rc.bg,'float' : 'left'});

		$("." + BL).css({'width' : options.bl.width,'height' : options.bl.height,'background' : options.bl.bg,'float' : 'left'});
		$("." + BC).css({'width' : elWidth,'height' : options.bc.height,'background' : options.bc.bg,'float' : 'left'});
		$("." + BR).css({'width' : options.br.width,'height' : options.br.height,'background' : options.br.bg,'float' : 'left'});

		$("." + CM).css({'width' : elWidth + options.tl.width + options.tr.width,'height' : elHeight + options.tl.height + options.bl.height,"float" : options.source.float,"margin-top" : options.source.padding});
		//$("." + CM).before('<div class="' + DC + '" />');
//		$("." + DC).css('clear','both');
	};
})(jQuery);

/*
 * Use example:
 * $("class name or id name").imgCorner();
 */

