/*
'
'	Code expects prototype.js already loaded.
'
'	To specify where the ad goes:
'
'	<div id="insertAdHere"></div>
'
'
'	To disable the ad placement completely:
'
'	<div id="insertAdCancel"></div>
'
'
'	To specify an ad to REPLACE the normal one (must be within the same table cell):
'
'	<div id="insertAdOverride"></div>
'
*/

//--- This is performed upon completion of page load
var insertAd_timer = setTimeout( function() {

	/* Is the Cancel tag present on the page? */
	var temp = $("insertAdCancel"); if( temp != null ) { return; }

	// The ad itself (rather, its container) (If not found, exit)
	var ad = $("insertAd"); if( ad == null ) { alert("not found"); return; }
	
	//If an override ad exists, use that instead
	if( $("insertAdOverride") != null ) ad = $("insertAdOverride");



	// Get the parent object (the TD for this section)
	var container = ad.up("td");

	// Prepare to loop though the children elements...
	var kids = container.descendants();

	var idx = 0;
	var break_counter = 0;
	var e = "";

	var nowElem = ad;

	temp = $("insertAdHere");
	if( temp != null ) { //--- We've been told where to put this ad.

		nowElem = temp;

	} else while ( nowElem.nextSibling ) { //--- We have to determine where to put the ad manually.
		nowElem = $(nowElem.nextSibling);

		if( nowElem.tagName == "P" ||
			nowElem.tagName == "BR" ||
			nowElem.tagName == "DIV" ||
			nowElem.tagName == "H1" ||
			nowElem.tagName == "H2" ||
			nowElem.tagName == "H3" ||
			nowElem.tagName == "H4" ||
			nowElem.tagName == "H5" ||
			nowElem.tagName == "H6" ||
			nowElem.tagName == "H7"
			 )
			break_counter++;

		//---- Insert the ad 3 "section breaks" from starting position.
		if( break_counter >= 4 ) break;

	}//-- End of search for location




	//--- Perform actual insertion
	ad.up("td").insertBefore(ad, nowElem.nextSibling );
	ad.setStyle({ display:'block' }).load('/inc/insertAd.html');
			



}, 1000);
