// jQuery Bullnose Plugin
// v 1.1
// Added: Show corners.

(function($) {
    
    $.fn.bullNose = function(options){
        
        // default configuration properties
        var defaults = {
            pathToImages:                '/images/',
            positionCornerAbsolute:    true,
            positionIncludeBorder:        false,
            topLeftImg:                'corner-top-left.gif',
            topRightImg:                'corner-top-right.gif',
            bottomLeftImg:            'corner-bottom-left.gif',
            bottomRightImg:            'corner-bottom-right.gif',
            imageWidth:                '10',
            imageHeight:                '10',
            imageIdPrefix:                'cornerImage',
            imageClass:                'cornerImage',
            showTopLeft:                true,
            showTopRight:                true,
            showBottomLeft:            true,
            showBottomRight:            true
        };
        
        var options = $.extend(defaults, options);  
        
        this.each(function() {
            
            // Build the string to insert the images
            var stringImages = '';
            
            if (options.showTopLeft) {
                stringImages += '<img src="' + options.pathToImages + options.topLeftImg + '" width="' + options.imageWidth + '" height="' + options.imageHeight + '" alt="" class="' + options.imageClass + '" id="' + options.imageIdPrefix + 'TopLeft" />';
            }
            if (options.showTopRight) {
                stringImages += '<img src="' + options.pathToImages + options.topRightImg + '" width="' + options.imageWidth + '" height="' + options.imageHeight + '" alt="" class="' + options.imageClass + '" id="' + options.imageIdPrefix + 'TopRight" />';
            }
            if (options.showBottomLeft) {
            stringImages += '<img src="' + options.pathToImages + options.bottomLeftImg + '" width="' + options.imageWidth + '" height="' + options.imageHeight + '" alt="" class="' + options.imageClass + '" id="' + options.imageIdPrefix + 'BottomLeft" />';
            }
            if (options.showBottomRight) {
            stringImages += '<img src="' + options.pathToImages + options.bottomRightImg + '" width="' + options.imageWidth + '" height="' + options.imageHeight + '" alt="" class="' + options.imageClass + '" id="' + options.imageIdPrefix + 'BottomRight" />';
            }
            
            // Append the images to the container
            $(this).append(stringImages)
            
            // if positionCornerAbsolute is set to true, position the images using jQuery
            if (options.positionCornerAbsolute) {
                if ($(this).css('position') == 'static') {
                    $(this).css('position','relative');
                };
                
                $('.' + options.imageClass).css('position','absolute');
                
                var border = '0';
                if (options.positionIncludeBorder) {
                    border = '1';
                }
                
                $('#' + options.imageIdPrefix + 'TopLeft').css('left','-'+border+'px');
                $('#' + options.imageIdPrefix + 'TopLeft').css('top','-'+border+'px');
                
                $('#' + options.imageIdPrefix + 'TopRight').css('right','-'+border+'px');
                $('#' + options.imageIdPrefix + 'TopRight').css('top','-'+border+'px');
                
                $('#' + options.imageIdPrefix + 'BottomLeft').css('left','-'+border+'px');
                $('#' + options.imageIdPrefix + 'BottomLeft').css('bottom','-'+border+'px');
                
                $('#' + options.imageIdPrefix + 'BottomRight').css('right','-'+border+'px');
                $('#' + options.imageIdPrefix + 'BottomRight').css('bottom','-'+border+'px');
            }
        
        });
        
    };

})(jQuery);
