  function replaceHeadingWithFlash(headingId, textColour, backgroundColour, headingWidth, letterSpacing, lineHeight, pxToEMRatio, className, linkURL) {
    _replaceElementWithFlash(0, 49, 32, -4, headingId, textColour, backgroundColour, headingWidth, letterSpacing, -0.5, lineHeight, pxToEMRatio, className, linkURL);
  }
  function replaceSectionHeadingWithFlash(headingId, textColour, backgroundColour, headingWidth, letterSpacing, lineHeight, pxToEMRatio, className, linkURL) {
    _replaceElementWithFlash(-2, 26, 16, -2, headingId, textColour, backgroundColour, headingWidth, letterSpacing, -0.5, lineHeight, pxToEMRatio, className, linkURL);
  }
  function replaceBlockHeadingWithFlash(headingId, textColour, backgroundColour, headingWidth, letterSpacing, lineHeight, pxToEMRatio, className, linkURL) {
    _replaceElementWithFlash(-3, 16, 16, 0, headingId, textColour, backgroundColour, headingWidth, letterSpacing, -0.2, lineHeight, pxToEMRatio, className, linkURL);
  }
  function replaceAllSectionHeadingsWithFlash(headingTag, textColour, backgroundColour, headingWidth, letterSpacing, lineHeight, pxToEMRatio, className, linkURL) {
    if (!document.getElementsByTagName) return;
    var elements=document.getElementsByTagName(headingTag);
    var randomId='';
    var idValue;
    var excludedElements=new Array();
    for (var i=0; i<elements.length; i++) {
      idValue=elements[i].getAttribute('id');
      if (!idValue || idValue == '') {
        idValue='randomId-'+Math.round(Math.random()*10000)+'-'+Math.round(Math.random()*10000);
        elements[i].setAttribute('id', idValue);
      }
      if (idValue.substring(idValue.length-19)=="_ReplacedBySCFlash_") {
        excludedElements[excludedElements.length]=idValue;
        excludedElements[excludedElements.length]=idValue.substring(19);
      }
    }
    for (var i=0; i<elements.length; i++) {
      idValue=elements[i].getAttribute('id');
      var isExcluded=false;
      for (var j=0; j<excludedElements.length; j++) {
        if (idValue==excludedElements[j]) {
          isExcluded=true;
          break;
        }
      }
      if (!isExcluded) {
        replaceSectionHeadingWithFlash(idValue, textColour, backgroundColour, headingWidth, letterSpacing, lineHeight, pxToEMRatio, className, linkURL);
      }
    }
  }
  function replaceAllBlockHeadingsWithFlash(headingTag, textColour, backgroundColour, headingWidth, letterSpacing, lineHeight, pxToEMRatio, className, linkURL) {
    if (!document.getElementsByTagName) return;
    var elements=document.getElementsByTagName(headingTag);
    var randomId='';
    var idValue;
    var excludedElements=new Array();
    for (var i=0; i<elements.length; i++) {
      idValue=elements[i].getAttribute('id');
      if (!idValue || idValue == '') {
        idValue='randomId-'+Math.round(Math.random()*10000)+'-'+Math.round(Math.random()*10000);
        elements[i].setAttribute('id', idValue);
      }
      if (idValue.substring(idValue.length-19)=="_ReplacedBySCFlash_") {
        excludedElements[excludedElements.length]=idValue;
        excludedElements[excludedElements.length]=idValue.substring(19);
      }
    }
    for (var i=0; i<elements.length; i++) {
      idValue=elements[i].getAttribute('id');
      var isExcluded=false;
      for (var j=0; j<excludedElements.length; j++) {
        if (idValue==excludedElements[j]) {
          isExcluded=true;
          break;
        }
      }
      if (!isExcluded) {
        replaceBlockHeadingWithFlash(idValue, textColour, backgroundColour, headingWidth, letterSpacing, lineHeight, pxToEMRatio, className, linkURL);
      }
    }
  }
  function _replaceElementWithFlash(horizontalOffset, normalFontSize, smallFontSize, smallFontVerticalOffset, headingId, textColour, backgroundColour, headingWidth, letterSpacing, letterSpacingFix, lineHeight, pxToEMRatio, className, linkURL) {
    var normalFontCharGrid;
    var smallFontCharGrid;
    normalFontCharGrid=this['universCondensedBold'+normalFontSize+'CharGrid'];
    smallFontCharGrid=this['universCondensedBold'+smallFontSize+'CharGrid'];
//    eval('normalFontCharGrid=universCondensedBold'+normalFontSize+'CharGrid;');
//    eval('smallFontCharGrid=universCondensedBold'+smallFontSize+'CharGrid;');
    if (typeof normalFontCharGrid=="undefined") return;
    if (typeof smallFontCharGrid=="undefined") return;
    if (typeof swfobject=="undefined") return;
    if (swfobject.getFlashPlayerVersion().major < 8) return;
    if (!document.getElementById) return;
    var headingNode;
    var parentN;
    var parentNodeNewChildren=new Array();
    var newHeadingNode=false;
    var newHeadingNodeContent;
    var newHeadingNodeStyle;
    var newHeadingNodeNumberOfLines=0;
    var flashVarDump={};
    var parentNodeNewChildrenStyles=new Array();
    var parentNodeNewChildrenClasses=new Array();
    if (pxToEMRatio && !isNaN(pxToEMRatio)) {
      var dimensionUnit='em';
      var dimensionScale=pxToEMRatio;
    } else {
      var dimensionUnit='px';
      var dimensionScale=1;
    }
    if (headingNode=document.getElementById(headingId)) {
      parentN=headingNode.parentNode;
      if (parentN!=null) {
        for (var i=0;i<parentN.childNodes.length;i++) {
          if (!newHeadingNode && headingNode==parentN.childNodes[i]) {
            newHeadingNode=document.createElement('div');
            newHeadingNodeContent=parseContent(headingNode);
            newHeadingNodeContent=layoutContent(newHeadingNodeContent);
            k=0;
            for (var j=0;j<newHeadingNodeContent.length;j++) {
              if (!newHeadingNodeContent[j].isAWhitespace) {
                flashVarDump["word"+k+"Characters"]=newHeadingNodeContent[j].characters;
                flashVarDump["word"+k+"FontSize"]=newHeadingNodeContent[j].fontSize;
                flashVarDump["word"+k+"XPos"]=newHeadingNodeContent[j].xpos;
                flashVarDump["word"+k+"YPos"]=newHeadingNodeContent[j].ypos;
//                eval("flashVarDump.word"+k+"Characters='"+newHeadingNodeContent[j].characters+"';");
//                eval("flashVarDump.word"+k+"FontSize='"+newHeadingNodeContent[j].fontSize+"';");
//                eval("flashVarDump.word"+k+"XPos="+newHeadingNodeContent[j].xpos+";");
//                eval("flashVarDump.word"+k+"YPos="+newHeadingNodeContent[j].ypos+";");
                k++;
              }
            }
            flashVarDump.numOfWords=k;
            flashVarDump.headingWidth=headingWidth;
            flashVarDump.textColour=textColour;
            flashVarDump.letterSpacing=letterSpacing;
            if (!linkURL || linkURL!='') {
              flashVarDump.linkURL=linkURL;
            }
            newHeadingNode.appendChild(document.createElement('div'));
            newHeadingNode.childNodes[0].setAttribute('id', headingId);
            parentNodeNewChildren[parentNodeNewChildren.length]=newHeadingNode;
            parentNodeNewChildrenStyles[parentNodeNewChildrenStyles.length]=new Object();
            parentNodeNewChildrenStyles[parentNodeNewChildrenStyles.length-1]['width']=(headingWidth*dimensionScale)+dimensionUnit;
            parentNodeNewChildrenStyles[parentNodeNewChildrenStyles.length-1]['height']=(newHeadingNodeNumberOfLines*lineHeight*dimensionScale)+dimensionUnit;
            parentNodeNewChildrenStyles[parentNodeNewChildrenStyles.length-1]['overflow']='hidden';
            if (dimensionUnit=="em") {
              parentNodeNewChildrenStyles[parentNodeNewChildrenStyles.length-1]['fontSize']=Math.floor(1/pxToEMRatio)+"px";
            }
            parentN.childNodes[i].setAttribute('id', headingId+'_ReplacedBySCFlash_');
            parentNodeNewChildren[parentNodeNewChildren.length]=parentN.childNodes[i];
            parentNodeNewChildrenStyles[parentNodeNewChildrenStyles.length]=new Object();
            parentNodeNewChildrenStyles[parentNodeNewChildrenStyles.length-1]['display']='none';
            if (className) {
              parentNodeNewChildrenClasses[parentNodeNewChildrenClasses.length]=className;
            } else {
              parentNodeNewChildrenClasses[parentNodeNewChildrenClasses.length]=false;
            }
          } else {
            parentNodeNewChildren[parentNodeNewChildren.length]=parentN.childNodes[i];
            parentNodeNewChildrenStyles[parentNodeNewChildrenStyles.length]=new Object();
            parentNodeNewChildrenClasses[parentNodeNewChildrenClasses.length]=false;
          }
        }
        while (parentN.childNodes.length > 0) {
          parentN.removeChild(parentN.childNodes[0]);
        }
        for (var i=0;i<parentNodeNewChildren.length;i++) {
          parentN.appendChild(parentNodeNewChildren[i]);
          if (parentN.childNodes[i].style) {
            for (j in parentNodeNewChildrenStyles[i]) {
              if (typeof parentNodeNewChildrenStyles[i][j]=="string") {
                parentN.childNodes[i].style[j]=parentNodeNewChildrenStyles[i][j];
//                eval("parentN.childNodes[i].style."+j+"='"+parentNodeNewChildrenStyles[i][j]+"';");
              }
            }
          }
          if (parentNodeNewChildrenClasses[i]) {
            if (typeof parentNodeNewChildrenClasses[i]=="string") {
              parentN.childNodes[i].setAttribute('class', parentNodeNewChildrenClasses[i]);
              parentN.childNodes[i].setAttribute('className', parentNodeNewChildrenClasses[i]);
//              eval("parentN.childNodes[i].setAttribute('class', '"+parentNodeNewChildrenClasses[i]+"');");
//              eval("parentN.childNodes[i].setAttribute('className', '"+parentNodeNewChildrenClasses[i]+"');");
            }
          }
        }
        var flashParams={};
        flashParams.bgcolor="#"+backgroundColour;
        flashParams.wmode="transparent";
        flashParams.align="tl";
        flashParams.menu="false";
        swfobject.embedSWF("/media/flash/replaceHeadingWithFlash.swf", headingId, "100%", "100%", "8.0.0", false, flashVarDump, flashParams);
//        setTimeout(function (headingId, flashVarDump, flashParams) {swfobject.embedSWF("/media/flash/replaceHeadingWithFlash.swf", headingId, "100%", "100%", "8.0.0", false, flashVarDump, flashParams);}, 10, headingId, flashVarDump, flashParams);
      }
    }
    function parseContent(element, smallMode) {
      var list=new Array();
      var classValue = '';
      var classes=new Array();
      if (!smallMode) {
        if (element.attributes) {
          for( var i= 0;i<element.attributes.length;i++ ) {
            if(element.attributes[i].nodeName.toLowerCase()=='class') {
              classValue=element.attributes[i].nodeValue;
              break;
            }
          }
          classes=classValue.split(' ');
          for (var i=0;i<classes.length;i++) {
            if (classes[i]=='small') {
              smallMode=true;
              break;
            }
          }
        }
      }
      if (element.childNodes.length==0) {
        if (element.nodeValue) {
          for (var i=0;i<element.nodeValue.length;i++) {
            if (element.nodeValue.charCodeAt(i)<=32) {
              element.nodeValue=element.nodeValue.substr(0, i)+' '+element.nodeValue.substr(i+1);
            }
          }
          var words=element.nodeValue.split(' ');
          var index;
          var characterCode;
          for (var i=0;i<words.length;) {
            index=list.length;
            list[index]={};
            list[index].characters='';
            list[index].isAWhitespace=false;
            list[index].width=0;
            list[index].height=0;
            list[index].fontSize=12;
            for (var j=0;j<words[i].length;j++) {
              characterCode=words[i].charCodeAt(j);
              if (smallMode) {
                if (smallFontCharGrid[characterCode]) {
                  list[index].characters+=encodeAllCases(words[i].substr(j,1));
//                  list[index].characters+='%'+dec2hex(characterCode);
                  list[index].width+=smallFontCharGrid[characterCode]['width']+letterSpacing+letterSpacingFix;
                  list[index].height=Math.max(list[index].height, smallFontCharGrid[characterCode]['height']+smallFontVerticalOffset);
                  list[index].fontSize=smallFontSize;
                }
              } else {
                if (normalFontCharGrid[characterCode]) {
                  list[index].characters+=encodeAllCases(words[i].substr(j,1));
//                  list[index].characters+='%'+dec2hex(characterCode);
                  list[index].width+=normalFontCharGrid[characterCode]['width']+letterSpacing+letterSpacingFix;
                  list[index].height=Math.max(list[index].height, normalFontCharGrid[characterCode]['height']);
                  list[index].fontSize=normalFontSize;
                }
              }
            }
            index=list.length;
            list[index]={};
            list[index].characters=' ';
            list[index].isAWhitespace=true;
            list[index].width=0;
            if (++i<words.length) {
              if (smallMode) {
                list[index].width+=smallFontCharGrid[32]['width']+letterSpacing;
                list[index].height=Math.max(list[index].height, smallFontCharGrid[32]['height']+smallFontVerticalOffset);
                list[index].fontSize=smallFontSize;
              } else {
                list[index].width+=normalFontCharGrid[32]['width']+letterSpacing;
                list[index].height=Math.max(list[index].height, normalFontCharGrid[32]['height']);
                list[index].fontSize=normalFontSize;
              }
            }
          }
        }
      } else {
        var parsedItemList;
        var appendList;
        for (var i=0;i<element.childNodes.length;i++) {
          parsedItemList=parseContent(element.childNodes[i], smallMode);
          appendList=new Array();
          for (var j=0;j<parsedItemList.length;j++) {
            if (parsedItemList[j].characters.length>0 && parsedItemList[j].width>0) {
              appendList[appendList.length]=parsedItemList[j];
            }
          }
          if (appendList) {
            list=list.concat(appendList);
          }
        }
      }
      return list;
    }
    function layoutContent(content) {
      var widthBuffer=horizontalOffset;
      var lineBuffer=0;
      for (var i=0;i<content.length;i++) {
        if (!content[i].isAWhitespace && widthBuffer+content[i].width>headingWidth && widthBuffer!=horizontalOffset) {
          widthBuffer=horizontalOffset;
          lineBuffer++;
        }
        content[i].xpos=widthBuffer;
        widthBuffer+=content[i].width;
        content[i].ypos=lineHeight*lineBuffer+(lineHeight-content[i].height)*2/3;
      }
      newHeadingNodeNumberOfLines=lineBuffer+1;
      return content;
    }
    function dec2hex(n){
      n = parseInt(n); var c = 'ABCDEF';
      var b = n / 16; var r = n % 16; b = b-(r/16); 
      b = ((b>=0) && (b<=9)) ? b : c.charAt(b-10);    
      return ((r>=0) && (r<=9)) ? b+''+r : b+''+c.charAt(r-10);
    }
    function encodeAllCases(c) {
      switch(c) {
      case ':':
        return '%3A';
      case '/':
        return '%2F';
      case ';':
        return '%3B';
      case '?':
        return '%3F';
      case '&':
        return '%26';
      case '+':
        return '%2B';
      default:
        return encodeURI(c);
      }
    }
  }