
// BIG BORDER
function border_lg(){
	$(this).removeClass("wait_for_load");
	theHeight = $(this).closest("*[rel='border_lg']").height() - 30;
	$(this).closest("*[rel='border_lg']").append('<table class="border_lg" cellspacing="0" cellpadding="0"><tr><td class="border_lg_tl" width="15" height="15" align="left" valign="top"><img src="/img/border_lg_tl.png" /></td><td class="border_lg_t"><img src="/img/spacer.gif" width="1" height="1" /></td><td class="border_lg_tr" width="15" height="15" align="right" valign="top"><img src="/img/border_lg_tr.png" /></td></tr><tr><td class="border_lg_l" height="'+theHeight+'"><img src="/img/spacer.gif" width="1" height="1" /></td><td height="'+theHeight+'"><img src="/img/spacer.gif" width="1" height="1" /></td><td class="border_lg_r" height="'+theHeight+'"><img src="/img/spacer.gif" width="1" height="1" /></td></tr><tr><td class="border_lg_bl" width="15" height="15" align="left" valign="bottom"><img src="/img/border_lg_bl.png" /></td><td class="border_lg_b"><img src="/img/spacer.gif" width="1" height="1" /></td><td class="border_lg_br" width="15" height="15" align="right" valign="bottom"><img src="/img/border_lg_br.png" /></td></tr></table>');
}


// SMALL BORDER
function border_sm(){
	$(this).removeClass("wait_for_load");
	theHeight = $(this).closest("*[rel='border_sm']").height() - 10;
	$(this).closest("*[rel='border_sm']").append('<table class="border_sm" cellspacing="0" cellpadding="0"><tr><td class="border_sm_tl" width="5" height="5" align="left" valign="top"><img src="/img/border_sm_tl.png" /></td><td class="border_sm_t"><img src="/img/spacer.gif" width="1" height="1" /></td><td class="border_sm_tr" width="5" height="5" align="right" valign="top"><img src="/img/border_sm_tr.png" /></td></tr><tr><td class="border_sm_l" height="'+theHeight+'"><img src="/img/spacer.gif" width="1" height="1" /></td><td height="'+theHeight+'"><img src="/img/spacer.gif" width="1" height="1" /></td><td class="border_sm_r" height="'+theHeight+'"><img src="/img/spacer.gif" width="1" height="1" /></td></tr><tr><td class="border_sm_bl" width="5" height="5" align="left" valign="bottom"><img src="/img/border_sm_bl.png" /></td><td class="border_sm_b"><img src="/img/spacer.gif" width="1" height="1" /></td><td class="border_sm_br" width="5" height="5" align="right" valign="bottom"><img src="/img/border_sm_br.png" /></td></tr></table>');
}

// TRY TO CATCH ON LOAD
$(document).ready(function(){

	/*
	
		1) WAITS FOR THE IMAGE TO LOAD
		2) DETECTS WRAPPER HEIGHT AFTER IMAGE LOADS
		3) CREATES A TABLE THE FULL SIZE OF THE CONTAINER WITH THE BORDER
		
		Note: You will need to manually crop any contained content to not extend beyond corner borders if borders are transparent
	
	*/
	
	$("*[rel='border_lg'] .wait_for_load").load(border_lg);
	$("*[rel='border_sm'] .wait_for_load").load(border_sm);

});

// RUN THROUGH ONCE AGAIN AFTER EVERYTHING HAS LOADED
$(window).load(function(){

	$("*[rel='border_lg'] .wait_for_load").each(border_lg);
	$("*[rel='border_sm'] .wait_for_load").each(border_sm);

})
