﻿function fsHeading(swfPath, bgColor, cssPath)
{
    this.swfPath = swfPath;
    this.flashVersion = 6;
    this.flashHeadingBgColor = bgColor || "#FFFFFF";
    this.flashHeadingX = -2;
    this.flashHeadingY = -3;
    this.FlashCSSPath = cssPath || "flash.css";
    this.wMultiplier = 2;
    this.hMultiplier = 2;
    this.headings = new Array();
    this.debug = function()
    {
        var a = new Array();
        for(var i=0; i < arguments.length; i++)
        {
            a.push(arguments[i] + "\n\n");
        }
        alert(a.join(""));
    }     
    this.getExpando = function (el, prop) 
    {
        if(el[prop])
        {
            return el[prop];
        }
        else
        {
            for(var i=0;i < el.attributes.length; i++)
            {
	            if(el.attributes[i].nodeName == prop.toLowerCase())
	            {
		            return el.attributes[i].nodeValue;
		        }
		    }
            return null;
        }
    };

    this.flashEnabled = function ()
    {
        try
        {
            if(document.all)
            {
                return typeof(new ActiveXObject("ShockwaveFlash.ShockwaveFlash." + this.flashVersion)) != "undefined";
            }
            else
            {
                if(navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"] && navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin)
                {
                    var flashVersion = (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]).description;
                    return parseInt(flashVersion.charAt(flashVersion.indexOf(".") - 1)) >= this.flashVersion;
                }
            }
        }
        catch(e)
        {
            return false;
        }
    };

    this.replaceHeadings = function ()
    {
    //debugger;
        for(var i=1; i < 6; i++)
        {
            var colH = document.getElementsByTagName("H" + i);
            if(colH)
            {
                for(var c=colH.length-1; c > -1 ;c--)
                {
                    if(!this.flashEnabled())
                    {
                        colH[c].style.visibility = "visible";
                    }
                    else
                    {
                        this.headings[this.headings.length] = new simpleH(colH[c].offsetWidth, colH[c].offsetHeight, colH[c].innerHTML, (this.getExpando(colH[c],"bgColor") || this.flashHeadingBgColor), colH[c]); 
                    }
                }
            }
        }
        for(var j = 0; j < this.headings.length; j++)
        {
            this.replaceHeading(this.headings[j]);
        }
    };

    this.replaceHeading = function (oH)
    {
    
        var embed = document.createElement("embed");
        if(embed)
        {
            var w = (oH.width /oH.height) < 18 ? oH.width : oH.width;
            var h = (oH.width /oH.height) < 18 ? oH.height : oH.height * .8;
            var tw = (oH.width /oH.height) < 18 ? oH.width * 1.6 : oH.width * 1.6;
            var th = (oH.width /oH.height) < 18 ? oH.height * 1.6 : oH.height * 1.6;            
            var flashVars = "x=" + this.flashHeadingX + "&y=" + this.flashHeadingY + "&w=" + tw + "&h=" + th + "&html=" + encodeURIComponent("<" + oH.ptr.tagName + ">" + oH.html + "<\/" + oH.ptr.tagName + ">") + "&cssPath=" + this.FlashCSSPath;
            embed.setAttribute("type" ,"application/x-shockwave-flash");
            embed.setAttribute("src", this.swfPath + "?" + flashVars);
            embed.setAttribute("menu","false");
            embed.setAttribute("loop","true");
            embed.setAttribute("salign","TL");
            embed.setAttribute("wmode","transparent");
            embed.setAttribute("width",w);
            embed.setAttribute("height",h);
            embed.setAttribute("bgcolor",oH.bgColor);
            embed.setAttribute("specifysize","true");
            embed.setAttribute("play","true");
            embed.setAttribute("quality","High");
            embed.setAttribute("swliveconnect","true");
            embed.setAttribute("class","rsHeading")
            oH.ptr.parentNode.replaceChild(embed,oH.ptr);
        } 
    }
}

function simpleH(w, h, html, bgColor, ptr)
{
    this.width = w;
    this.height = h;
    this.html = html;
    this.bgColor = bgColor;
    this.ptr = ptr;
}

