window.onload = function() {
	if (SWFObject) {
        createFlashTitles("h1", "pagetitle", "0xED1C24", 15, "", 365, 20);
        createFlashTitles("h5", "largeicon", "0xED1C24", 15, "", 105, 20);
        createFlashTitles("h5", "icon", "0xED1C24", 15, "", 125, 20);
        //createFlashTitles("h5", null, "0xED1C24", 15, "", 165, 20);
        // fixed (doesn't work in IE6):
        createFlashTitles("h5", null, "0xED1C24", 15, "", 155, 20);
	}
};

function createFlashTitles(containerTag, className, color, size, label, width, height) {
	var tags = document.getElementsByTagName(containerTag);
	for (i = 0; i < tags.length; i++) {
        var bContinue = (className == null);

        if (className != null) {
            var re = new RegExp("\\b" + className + "\\b", "i");
            bContinue = (tags[i].className.search(re) > -1);
        }
        
        if (bContinue) {
	        var customWidth = tags[i].style.width;
	        if (!isNaN(parseInt(customWidth, 10)))
	            width = parseInt(customWidth, 10);
	        var brCount = 1;
	        var tagHtml = getXHTML(tags[i], false, false);
	        // only create the flash title if it hasn't been created already
	        if (tagHtml.search(/<object/) == -1) {
	            brCount += (tagHtml.split(/<br \/>/i).length - 1);
	            brCount += (tagHtml.split(/<br\/>/i).length - 1);
	            brCount += (tagHtml.split(/<br>/i).length - 1);
		        createFlashTitle(tags[i], color, size, label, width, brCount * height);
            }
        }
	}
}

// Flash titles
createFlashTitle = function(container, color, size, label, width, height) {
	if (label == "") {
		label = getXHTML(container, false, false);
	}
	var so = new SWFObject("/wps/themes/html/EPN_MarketingPortal/swf/title.swf", container, width, height, "8", "#FFFFFF");// ds
	so.addParam("wmode", "Transparent");
	so.addParam("scale", "noScale");
	so.addVariable("fvColor", color);
	so.addVariable("fvSize", size);
	so.addVariable("fvLetterSpacing", 0);
	so.addVariable("fvLabel", escape(label));
	so.useExpressInstall("swf/expressinstall.swf");
	so.write(container);
};

// Better innerHTML
getXHTML = function(obj, encode, bOuter) {
  // bOuter -> true = outerHTML, false = innerHTML
  // It is an option to pass innerXHTML() a string indicating an id attribute
  if (typeof obj == "string") {
	obj = document.getElementById(obj)
  }
  
  var open = '';
  var content = '';
  var close = '';
  var tagname = obj.nodeName.toLowerCase();
  var emptytag = (obj.nodeName.match(/area|base|basefont|br|col|frame|hr|img|input|isindex|link|meta|param/i)) ? true : false; 

  // Write open tag
  if (bOuter)
  {
	  open = '<'+tagname;
	  for (var i=0; i<obj.attributes.length; i++) {
		if (obj.attributes[i].specified && obj.attributes[i].value != "null")
		  open += ' '+obj.attributes[i].name.toLowerCase()+'="'+obj.attributes[i].value+'"';
	  }
	  open += (emptytag) ? ' />' : '>';
  }

  if (!emptytag) {
	// Write tag content
	for (var i=0; i<obj.childNodes.length; i++) {
	  var node = obj.childNodes[i];
	  if (node.nodeType==3)
	  {  
		nodecontent = node.data.replace(/</gi, "&lt;");
		nodecontent = nodecontent.replace(/>/gi, "&gt;");
		content += nodecontent; //node.data; //nodecontent;
	  }
	  else if (node.nodeType==1)
		content += getXHTML(obj.childNodes[i], false, true);
	  else
		content += " ";
	}
	
	if (bOuter)
	{
		// Write closing tag
		close = '</'+tagname+'>';
	}
  }
  
  // URI encode the content if desired
  return (typeof(encode)=="undefined" || encode==true) ? encodeURIComponent(open+content+close) : open+content+close;
};

