// Doubleclick Targeting  Global Header Include
// 2007-10-02 - Written by Mike Tedesco
// Do not touch ever .... EVER!!

// Randomize page to blast through cache and improve page-refresh delivery of new ad units
//var axel = Math.random() + "";
//var ord = axel * 1000000000000000000;

// Derive path from document.  Convert or eliminate all angry URL controllers.
var path = parent.document.location.pathname.substring(1,parent.document.location.pathname.lastIndexOf('/'));
path = path.replace('dLife/do/ShowContent/','');  //Eliminate base controller
path = path.replace('diabetes/information/','');  //Eliminate base controller
path = path.replace('dLife/do/JForumWrapper/','forum/');  //Eliminate base controller
path = path.replace('dLife/do/recipe/ProcessRecipeSearch','recipesearch/');  //Convert base controller

// Create subtopic array from path structure and override with CMS values if present
//var subtopic = path.split('/',4);

function initAdDisplay(addID)
    {
    // Ad tags for graphic (not text links) must be implemented on dLife.com with a naming prefix/suffix pattern
		// This convention allows for dynamic detection of ad type and size, so that separation labels can be dynamically shown.
        var adDiv = document.getElementById(addID + "_js");
        var visibleObjectTagCount = adDiv.getElementsByTagName("object").length | adDiv.getElementsByTagName("iframe").length;
				var imageTag = adDiv.getElementsByTagName("img");
				var imageTagCount = imageTag.length;
				var label = document.getElementById(addID + "_label");

				//alert(addID + ": obj=" + visibleObjectTagCount + " img=" + imageTagCount);
				
				// Default to NOT show the label in the event that doubleclick is slow in serving a phat ad unit
				//label.style.display = "none";					
				
				if (visibleObjectTagCount > 0) {
					//Detect rich media first and display ad unit accordingly
					adDiv.style.display = "inline";
					label.style.display = "inline";

				} else if (imageTagCount > 0) {
					//Attempt to sniff image tag for its size and see if this is an invisible pixel
					if ( (adDiv.getElementsByTagName("img")[0].height == 1) && (adDiv.getElementsByTagName("img")[0].width == 1) ) {
						visibleImageTagCount = 0
					} else {
					  visibleImageTagCount = 1
				  }
				  
				  if (visibleImageTagCount == 1) {
						adDiv.style.display = "inline";
						label.style.display = "inline";
					} else {
						adDiv.style.display = "none";
						label.style.display = "none";					
					}
				
				} else {
					// Must not be any graphic to display
					adDiv.style.display = "none";
					label.style.display = "none";					
				}
				
		}



