/* -------------------------------------------------- *
 * RoundIt Plugin for jQuery                          *
 * Version 1.0                                        *
 * -------------------------------------------------- *
 * Author:    Aaron Kuzemchak                         *
 * URL:       http://aaronkuzemchak.com/              *
 * Copyright: 2008                                    *
 * -------------------------------------------------- */


// allows use of $ function in plugin
(function($) {

	// the core plugin
	$.fn.roundIt = function(settings) {
	
		// default settings
		var defaults = {
			topLeft: "images/tl.gif", // top-left image url
			topRight: "images/tr.gif", // top-right image url
			bottomRight: "images/br.gif", // bottom-right image url
			bottomLeft: "images/bl.gif", // bottom-left image url
			offset: 0 // amount to offset images
		};
		
		// merge default settings and user-defined ones
		var settings = jQuery.extend(defaults, settings);
		
		// loop through all matched elements
		// don't do anything if using IE6
		if(!$.browser.msie || ($.browser.msie && $.browser.version != "6.0")) {
		    return this.each(function() {
    		
			    // prepend images to element
			    $(this).prepend('<img src="' + settings.topLeft + '" alt="" class="tl" /><img src="' + settings.topRight + '" alt="" class="tr" /><img src="' + settings.bottomRight + '" alt="" class="br" /><img src="' + settings.bottomLeft + '" alt="" class="bl" />');
    			
			    // apply css to images
			    $(this).find(".tl, .tr, .br, .bl").css({ // apply to all
				    position: "absolute"
			    }).end().find(".tl").css({ // apply to top-left
				    left: settings.offset,
				    top: settings.offset
			    }).end().find(".tr").css({ // apply to top-right
				    right: settings.offset,
				    top: settings.offset
			    }).end().find(".br").css({ // apply to bottom-right
				    right: settings.offset,
				    bottom: settings.offset
			    }).end().find(".bl").css({ // apply to bottom-left
				    left: settings.offset,
				    bottom: settings.offset
			    });
		    });
		}
	};
})(jQuery);