var firstRun = 0;
var flashTextCounter = 0;

function getStyle(el,styleProp){
  var x = document.getElementById(el);
	if (x.currentStyle){
		var y = x.currentStyle[styleProp];
	}else if (window.getComputedStyle){
		var y = document.defaultView.getComputedStyle(x,null).getPropertyValue(styleProp);
	}
	return y;
}
function Dec2Hex(Dec){
  var hexChars = "0123456789ABCDEF";
  var a = Dec % 16;
  var b = (Dec - a)/16;
  hex = "" + hexChars.charAt(b) + hexChars.charAt(a);
  return hex;
}
function createFlashText(color,object){
  if(typeof sIFR == "function"){
    sIFR.replaceElement(object, named({sFlashSrc: "/swf/arialnarrow.swf", sColor: color, sWmode: "transparent"}));
  };
}
function replaceHeaderWithFlash(tag){
    var h = document.getElementsByTagName(tag);
    for(var i=h.length-1;i>=0;i--){
      // Get css-parameters
      var headerText = h[i].innerHTML;
      h[i].setAttribute("id","flashText"+flashTextCounter);
      var cssColor = getStyle("flashText"+flashTextCounter,"color");

      if(cssColor.substring(0,1) != "#"){
        var pattern = /\)| |rgb\(/gi;
        var hextemp = cssColor.replace(pattern, "").split(",");
        cssColor = Dec2Hex(hextemp[0]) + Dec2Hex(hextemp[1]) + Dec2Hex(hextemp[2]);
      }else{
        cssColor = cssColor.replace("#","");
      }
      if(cssColor.length != 6){
        cssColor = cssColor.substring(0,1) + cssColor.substring(0,1) +
        cssColor.substring(1,2) + cssColor.substring(1,2) +
        cssColor.substring(2,3) + cssColor.substring(2,3);
      }

      createFlashText(cssColor,tag+"#flashText"+flashTextCounter);
      flashTextCounter++;
    }
}

function initUnobtrusiveJs(){
    if(firstRun != 0)return;
    firstRun++;
    //replaceHeaderWithFlash("H1");
    //replaceHeaderWithFlash("H2");
    //replaceHeaderWithFlash("H3");
}


if(document.addEventListener){
    document.addEventListener("DOMContentLoaded", initUnobtrusiveJs, false);
}
window.onload = initUnobtrusiveJs;

