/* author Terry Wooton */

$(document).ready(function() {
  $.fn.add_layer = function(bg,params) {
    $(this).each(function() {
  
      s = $(this).extend({},params || {});      
      
      $last = ($(this).find('.add_background:last').length > 0 ? $(this).find('.add_background:last') : $(this));
  		$last.html('<div class="add_background"><div>'+$last.html()+'</div></div>');
  		$last = $(this).find('.add_background:last');
  		$last.css({'background':bg,'width':'100%','height':'100%'});

      $last = $(this).find('.add_background div:last');
            
      if(s.insideCss){
   		  $last.css(s.insideCss);
  		}
      if(s.insideClass)
  		  $last.addClass(s.insideClass);  		  
    });
  }      
});

$(function(){
	$('.boxy').add_layer("#c6fdff");
	$('.boxy').add_layer("url('images/box_mid_left.jpg') left repeat-y");
	$('.boxy').add_layer("url('images/box_mid_right.jpg') right repeat-y");
	$('.boxy').add_layer("url('images/box_mid_top.jpg') top repeat-x");
	$('.boxy').add_layer("url('images/box_mid_bottom.jpg') bottom repeat-x");
	$('.boxy').add_layer("url('images/box_left_top.jpg') top left no-repeat");
	$('.boxy').add_layer("url('images/box_right_top.jpg') top right no-repeat");
	$('.boxy').add_layer("url('images/box_right_bottom.jpg') bottom right no-repeat");
	$('.boxy').add_layer("url('images/box_left_bottom.jpg') bottom left no-repeat",
	{
    	insideCss : {'padding':'30px 10px 10px 10px'},
        insideClass: 'innerBox'
    });
});
