// new updated Atlas code
var advertising = {
	
	ad_call : null,
	
	// add call
	server : /^http\:\/\/ads\./,
	
	// empty ad test
	empty_ad : /((f{7}[a-e]{1})+|(AE[0-9]+\.gif))/g,
	
	render : function(value)
	{
		var invObj = 'INV' + value;
		try {
			var code = eval(value);
		} catch(er) { }
		
		var direct = false;
		if (typeof(code) == 'string') {
			var children = /\<([a-z]+)\s/i.exec(code);
			if (children[1] && ['iframe', 'a', 'img'].toString().indexOf(children[1].toLowerCase()) > -1) {
				direct = true;	
			}
		}
		
		if (direct == true) {
			// INSERT
			document.getElementById(value).innerHTML = code;
		} else {
			// COPY
			if (typeof(code) != 'undefined') {
				if (navigator.userAgent.indexOf('MSIE') > -1) {
					// IE
					document.getElementById(value).innerHTML =
						'<div id="TMP' + value + '" style="display:none">' +
						escape('<body><div id="adDiv">' + code + '</div>') +
						'</div><iframe name="' + invObj + '" width="0" height="0" frameborder="0" ' +
						'onload="advertising.relocateAd(this, \'' + value + '\');"></iframe>';
		
					window.frames[invObj].document.location = 'javascript:unescape(parent.document.getElementById(\'TMP' + value + '\').innerHTML)';
		
				} 
				
				else { 
					document.writeln('<div id="' + invObj + 
					'" style="display:none">' + code + 
					'<script type="text/javascript" defer="true">' +'document.getElementById(\'' + 
					value + 
					'\').innerHTML = ' + 
					'document.getElementById(\'' + 
					invObj + 
					'\').innerHTML;' + 
					'document.getElementById(\'' + invObj +'\').innerHTML = \'\';</script></div>');
				}
				
			}
		}
		
	},

	sponsor : function()
	{
		if (this.empty_ad.test(AAMB1) == false) {
			el = document.getElementById('AAMB1');
			el.innerHTML = "This printable version is sponsored by:<br />" + el.innerHTML;
		}
	},
	
	sponsor_text : function()
	{
		if (window.$ !== undefined){
			$(window).load(function(){
				$('div.searchTextAd').wrap('<div class="textAds"></div>').before('<h3>Sponsored Link</h3>');
				if (document.getElementById('main')) {
					// re-adjust column
					changeHeight('main');
				}
			});
		}
	},
	
	place : function()
	{
		for (aax=0; aax<AAMB.length; aax++) {
			if (this.empty_ad.test(eval(AAMB[aax])) == false && document.getElementById(AAMB[aax]) != null) {
				// place ad
				this.render(AAMB[aax]);
				
				// force ad size
				if (/[4567]{1}$/.test(AAMB[aax]) === true) {
					// get set size
					aamsz = /[0-9]+X([0-9]+)/.exec(aamszArray[AAMB[aax]]);
					if (aamsz != null) {
						document.getElementById(AAMB[aax]).parentNode.style.height = 'auto';
						document.getElementById(AAMB[aax]).style.height = aamsz[1] + "px";
					}
				}
			}
		}
		// re-adjust column
        /* 
                       * initHeight() function is now disabled, column re-adjustment should now be dealed with CSS
                       *
                       
		if (!(/\/print/.test(window.location.toString()))) {
		    initHeights(); 
		}
                      */
	},
	
	relocateAd : function(iframeObj, divName) 
	{
		var iframeDoc, 
		allScripts; 
		iframeDoc = iframeObj.contentWindow.document; 
		allScripts = iframeDoc.getElementsByTagName('script'); 
		for (s = 0; s < allScripts.length; s++) 
		if (allScripts[s].src) 
		allScripts[s].src = ''; 
		document.getElementById(divName).insertAdjacentElement('beforeEnd', iframeDoc.getElementById('adDiv')); 
	}
	
};
