$(document).ready(function() {     
    $(".shadow").each(function(){            
        $(this).shadow();
    });                                   
});
        
jQuery.fn.extend({
    shadow: function(options) {
        Shadow(this, options);
    }
});


intShadowCount = 0;
function Shadow(element, options){
    
    var uniqueId = "shadow" + (++intShadowCount);
    $(element).wrap("<div id='" + uniqueId + "_br' class='shadow_br shadow_wrap'><div id='" + uniqueId + "_tl' class='shadow_tl shadow_wrap'><div id='" + uniqueId + "_blc' class='shadow_blc shadow_wrap'>" +
    "<div id='" + uniqueId + "_trc' class='shadow_trc shadow_wrap'></div></div></div></div>");
     
    var w = $(element).outerWidth(); 
    var h = $(element).outerHeight();               
    
    var imgShadowBR = "/images/dynamic/shadow.png";
    var imgShadowTL = "/images/dynamic/shadow_180.png";
    var imgShadowBLC = "/images/dynamic/shadow_bl.png";
    var imgShadowTRC = "/images/dynamic/shadow_tr.png";
    var imgShadowWidth = 800;
    var imgShadowHeight = 1000;
    var imgShadowPadding = 25;
    
    if(options){
        if(options["imgShadowWidth"] != null)
	        imgShadowWidth = parseInt(options["imgShadowWidth"]);
	    if(options["imgShadowHeight"] != null)
	        imgShadowHeight = parseInt(options["imgShadowHeight"]);
	    if(options["imgShadowPadding"] != null)
	        imgShadowBR = parseInt(options["imgShadowPadding"]);		     
        if(options["imgShadowBR"] != null)
	        imgShadowBR = options["imgShadowBR"];
	    if(options["imgShadowTL"] != null)
	        imgShadowTL = options["imgShadowTL"];
	    if(options["imgShadowBLC"] != null)
	        imgShadowBLC = options["imgShadowBLC"];
	    if(options["imgShadowTRC"] != null)
	        imgShadowTRC = options["imgShadowTRC"];
    }           
    
    $(".shadow_wrap").each(function(){
        //this.style.display = 'inline-table';
    });
    $("#" + uniqueId + "_br").css('float', 'left');
    $("#" + uniqueId + "_br").css('background', 'url(' + imgShadowBR + '?w=' + (w + 1) + '&h=' + (h + 1) + '&y=' + (imgShadowHeight - h) + '&x=' + (imgShadowWidth - w) + ') right bottom no-repeat');
    $("#" + uniqueId + "_tl").css('background', 'url(' + imgShadowTL + '?w=' + (w + 1) + '&h=' + (h + 1) + '&x=0&y=0) no-repeat');
    $("#" + uniqueId + "_blc").css('background', 'url(' + imgShadowBLC + ') 0px 100% no-repeat');
    $("#" + uniqueId + "_trc").css('padding', imgShadowPadding + 'px');
    $("#" + uniqueId + "_trc").css('background', 'url(' + imgShadowTRC + ') 100% 0px no-repeat'); 
}