/**
 * defines a simple Macro interface to mimic the RenderMacro class on the server
 */
jive.rte.Macro = function(shortname, url, macrotag, settingsHuh, displayHuh, paramSets, params, enabled, button){
    var that = this;

    /**
     * gets the unique name for this macro
     * i.e. "code" or "youtube"
     */
    this.getName = function(){
        return shortname;
    }

    /**
     * gets the optional url for this macro
     */
    this.getUrl = function(){
        return url;
    }

    /**
     * returns true if it should be a button or not
     */
    this.isButton = function(){
        return button;
    }

    this.isEnabled = function(){
        return enabled;
    }

    this.isShowSettings = function(){
        return settingsHuh;
    }

    /**
     * Display in RTE Insert List?
     */
    this.isShowInMacroList = function(){
        return displayHuh;
    }
    
    /**
     * returns true if this macro accepts
     * raw text input, like a code macro,
     * or false if it doesn't, like
     * a youtube macro
     */
    this.getMacroType = function(){
        return macrotag;
    }

    /**
     * returns all param sets for this macro
     */
    this.getParameterSets = function(){
        return paramSets;
    }

    /**
     * returns an array of allowed parameters
     */
    this.getAllowedParameters = function(){
        return params;
    }

    /**
     * update the element's display w/ the latest
     * parameter value.
     */
    this.refresh = function(rte, ele){
        if(ele.getAttribute("jivemacro") == this.getName()){
            // i'm a span or an img
            if(this.getMacroType().toLowerCase() == "inline"){
                var str = ele.getAttribute("_title");
                if($def(str) && str != null && str.length > 0){
                    ele.innerHTML = str;
                    ele.attributes.removeNamedItem("_title");
                }else if(tinyMCE.activeEditor.dom.hasClass(ele, "default_title")){
                    var type = ele.getAttribute("jivemacro");
                    var id = ele.getAttribute("___default_attr");
                    var title = tinyMCE.activeEditor.plugins.jivemacros.getTitleFor(type, id);
                    if(title && ele.innerHTML != title[0]){
                        ele.innerHTML = title[0];
                    }
                    if(ele.innerHTML == ""){
                        ele.innerHTML = "unknown";
                    }
                }
                /*
                while(ele.childNodes.length > 1) ele.removeChild(ele.childNodes[0]);
                if(ele.childNodes.length == 0) ele.appendChild(document.createTextNode(""));
                var params = this.getAllowedParameters();
                for(var i=0;i<params.length;i++){
                    var val = ele.getAttribute("_" + params[i].name);
                    if(val != null && val.length > 0){
                        ele.childNodes[0].nodeValue = val;
//                            ele.appendChild(document.createTextNode(val));
                        return;
                    }
                }
                ele.childNodes[0].nodeValue = rte.getLang("jivemacros.macro." + this.getName(), this.getName());
                */
            }else if(this.getMacroType().toLowerCase() == "image"){
                var src = window.CS_BASE_URL + "/resources/scripts/tiny_mce3/plugins/jiveemoticons/images/spacer.gif";
                ele.setAttribute("src", src);
                ele.setAttribute("mce_src", src);
            }
        }
    }
}