﻿/*
	VERSION:    InnerBorder jQuery Plugin 1.0  (08-27-2008)	
	AUTHOR:     Oren Goldfinger
	REQUIRES:   jquery.js (1.2.6 or later)
	SYNTAX:     $(selector).innerBorder(options);  // Creates new inner border					
	OPTIONS:
		        borderColor   : string (default = "white")		
		        borderOpacity : decimal (default = 0.5)		
		        borderWidth   : integer (default = 10)
		        imageWidth    : integer (defaults to image width)
		        imageHeight    : integer (defaults to image height)
	EXAMPLE:
	            $("#myId").innerBorder();            
                $("#myId2").innerBorder({
                    borderColor:'blue',
                    borderWidth: 40,
                    borderOpacity: 0.20
                });
 */
(function($){
    $.fn.innerBorder = function(options) 
    {        
        var opts = $.extend({
                        borderColor: 'white',
                        borderOpacity: 0.5,
                        borderWidth: 10,
                        imageWidth: -1,
                        imageHeight: -1                        
                        }, options);        

        this.each(function()
        {               
            var objImage = $(this);

            var imageWidth = (opts.imageWidth == -1) ? objImage.width() : opts.imageWidth;
            var imageHeight = (opts.imageHeight == -1) ? objImage.height() : opts.imageHeight;
            var borderWidth = imageWidth - (opts.borderWidth * 2);
            var borderHeight = imageHeight - (opts.borderWidth * 2);

            objImage.width(imageWidth);
            objImage.height(imageHeight);
            
            // main container
            var container = $("<div></div>");
            container.addClass("innerBorder");
            container.css({                
                width:imageWidth,
                height:imageHeight,
                position:'relative'            
            });            
            
            // border div
            var border = $("<div></div>");
            border.css({
                opacity:opts.borderOpacity,
                width: borderWidth,
                height: borderHeight,
                border:"solid " + opts.borderWidth + "px " + opts.borderColor,
                position:'absolute'
            });         
                        
            // image container
            var imgContainer = $("<div></div>");
            container.css({                
                width:imageWidth,
                height:imageHeight
            });            
            
            objImage.wrap(container).before(border).wrap(imgContainer);                                
        });
    };
})(jQuery);
