(function() {

	var adSideDiv;
	var adSideClassName = 'ad300x250';
	var adSideIframe;
	var adSideSrc = 'http://www.health.com/health/static/breast-cancer-iq/poll_ad.html';
	
	var adTopDiv;
	var adTopId = 'adTop';
	var adTopIframe;
	var adTopSrc = 'http://www.health.com/health/static/breast-cancer-iq/adTop.html';
	
	var adLeftDiv;
	var adLeftClassName = 'ad160x600';
	var adLeftIframe;
	var adLeftSrc = 'http://www.health.com/health/static/breast-cancer-iq/adLeft.html';
	
	var divs;
	var adCount = 0;

	window.handlePollOnload = function() {
	
		if (adCount === 0) {
			adCount++;
			return;

				
		} else {

			/**
			 * Ad Side
			 */
			if (typeof adSideDiv === 'undefined') {
				divs = document.getElementsByTagName('div');
				for(var i = 0, len = divs.length; i < len; ++i) {
					if (divs[i].className === adSideClassName) {
						adSideDiv = divs[i];
						break;
					}
				}
			}

			// Build and cache adSideIframe
			if (typeof adSideIframe === 'undefined') {
				adSideIframe = document.createElement('iframe');
				adSideIframe.width = 300;
				adSideIframe.height = 250;
				adSideIframe.frameBorder = 'no';
				adSideIframe.scrolling = 'no';
				adSideIframe.id = 'adSideFrame';
			}
	
			while(adSideDiv.hasChildNodes()) {
				adSideDiv.removeChild(adSideDiv.firstChild);
			}
			
			adSideDiv.appendChild(adSideIframe);
			adSideIframe.src = adSideSrc;


			/**
			 * Ad Top
			 */
			if (typeof adTopDiv === 'undefined') {
				adTopDiv = document.getElementById(adTopId);			
			}

			// Build and cache adTopIframe
			if (typeof adTopIframe === 'undefined') {
				adTopIframe = document.createElement('iframe');
				adTopIframe.width = 728;
				adTopIframe.height = 90;
				adTopIframe.frameBorder = 'no';
				adTopIframe.scrolling = 'no';
				adTopIframe.id = 'adTopIframe';
			}

			while(adTopDiv.hasChildNodes()) {
				adTopDiv.removeChild(adTopDiv.firstChild);
			}
			
			adTopDiv.appendChild(adTopIframe);
			adTopIframe.src = adTopSrc;

			
			/**
			 * Ad Left
			 */
			if (typeof adLeftDiv === 'undefined') {
				divs = document.getElementsByTagName('div');
				for(var i = 0, len = divs.length; i < len; ++i) {
					if (divs[i].className === adLeftClassName) {
						adLeftDiv = divs[i];
						break;
					}
				}
			}

			// Build and cache adLeftIframe
			if (typeof adLeftIframe === 'undefined') {
				adLeftIframe = document.createElement('iframe');
				adLeftIframe.width = 160;
				adLeftIframe.height = 600;
				adLeftIframe.frameBorder = 'no';
				adLeftIframe.scrolling = 'no';
				adLeftIframe.id = 'adLeftIframe';
			}

			while(adLeftDiv.hasChildNodes()) {
				adLeftDiv.removeChild(adLeftDiv.firstChild);
			}
			
			adLeftDiv.appendChild(adLeftIframe);
			adLeftIframe.src = adLeftSrc;
		}
		
		adCount++;
	};
	
	
})();

