﻿/*
    Requires:
        Phizz.js
        SWFObject.js
*/

Phizz.SWFText = {

    minHeight: null,

    embedByClass: function(className, fontSWF, fontSize, fontColor) {
        if (className == null || typeof (className) != "string" || className.length == 0) return;
        this.embedObjects(Phizz.Dom.ByClass(className), fontSWF, fontSize, fontColor);
    },

    embedByID: function(id, fontSWF, fontSize, fontColor) {
        this.embedObjects([Phizz.Dom.ByID(id)], fontSWF, fontSize, fontColor);
    },

    embedByTag: function(tagName, fontSWF, fontSize, fontColor) {
        if (tagName == null || typeof (tagName) != "string" || tagName.length == 0) return;
        this.embedObjects(Phizz.Dom.ByTagName(tagName), fontSWF, fontSize, fontColor);
    },

    embedByTagAndClass: function(tagName, className, fontSWF, fontSize, fontColor) {
        if (className == null || typeof (className) != "string" || className.length == 0) return;
        if (tagName == null || typeof (tagName) != "string" || tagName.length == 0) return;
        this.embedObjects(Phizz.Dom.ByClass(className, tagName), fontSWF, fontSize, fontColor);
    },

    embedObject: function(obj, fontSWF, fontSize, fontColor) {
        this.embedObjects([obj], fontSWF, fontSize, fontColor);
    },

    embedObjects: function(objArray, fontSWF, fontSize, fontColor) {
        if (objArray == null || /*!(objArray instanceof Array) ||*/ objArray.length == 0) return;
        if (fontSWF == null || typeof (fontSWF) != "string" || fontSWF.length == 0) return;
        fontSize = fontSize || "24";
        fontColor = fontColor || "0x000000";
        for (var i = 0; i < objArray.length; i++) {
            objArray[i].style.width = objArray[i].offsetWidth + "px";
            objArray[i].style.height = objArray[i].offsetHeight + "px";
            var text = objArray[i].firstChild.nodeValue;
            objArray[i].innerHTML = "<div id=\"".concat("SWFText_", i, "\">", text, "</div>");
            swfobject.embedSWF(fontSWF, "SWFText_".concat(i), "100%", "100%", "9.0.0", null, {
                id: "SWFText_".concat(i),
                text: encodeURIComponent(text),
                size: fontSize,
                color: "0x".concat(fontColor),
                maxWidth: objArray[i].offsetWidth
            }, {
                allowFullScreen: "false",
                allowScriptAccess: "sameDomain",
                loop: "false",
                menu: "false",
                play: "false",
                quality: "best",
                scale: "noscale",
                wmode: "transparent"
            });
        }
    },

    resize: function(id, width, height) {
        var obj = Phizz.Dom.ByID(id).parentNode;
        obj.style.width = width + "px";
        obj.style.height = (this.minHeight != null && this.minHeight > height ? this.minHeight : height) + "px";
    }

}
