/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

//global variables necessary to create elements in these namespaces, do not delete them!!!!

/**
 * This variable is a shortcut to the full URL of the SVG namespace
 * @final
 * @type String
 */
var svgNS = "http://www.w3.org/2000/svg";

/**
 * This variable is a shortcut to the full URL of the XLink namespace
 * @final
 * @type String
 */
var xlinkNS = "http://www.w3.org/1999/xlink";

window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty(); 

AnimatController = {
	blinkingAnimat : [],// 闪烁动画
    activeSymbolAnimat : function(id, newLink) {// 更新图元动画
        var element = document.getElementById(id);
        if(typeof(element) != 'undefined') {
            element.setAttributeNS(xlinkNS, "xlink:href", newLink);
        }
    }, 
    activeTextAnimat : function(id, textVal) {// 更新文本动画
        var element = document.getElementById(id);
        if(typeof(element) != 'undefined') {
            // 删除旧的文本元素
            var child = element.firstChild;
            while (child) {
                if ((child.nodeName == "tspan") || (child.nodeName == "#text")) {
                    var temp = child.nextSibling;
                    element.removeChild(child);
                    child = temp;
                } else {
                    child = child.nextSibling;
                }
            }

            // 添加新的文本元素
            var x = element.getAttributeNS(null, "x");
            var tspan = document.createElementNS(svgNS, "tspan");
            tspan.setAttributeNS(null, "dx", "0");
            tspan.setAttributeNS(null, "x", x);
            tspan.setAttributeNS(null, "dy", "0");
            var textContent = document.createTextNode(textVal);
            tspan.appendChild(textContent);
            element.appendChild(tspan);
        }
    },
    activeSVGAnimat : function(id, state) {// 激活或停止SVG标准动画
        var element = document.getElementById(id);
        if(typeof(element) != 'undefined') {
            if (state) {
                element.beginElement(0.5);
                var animName = element.getAttribute("name");
                if (animName == "StrokeBlinkingOnExpression" || 
                    animName == "FillBlinkingOnExpression" || 
                    animName == "NormalBlinkingOnExpression") {// 闪烁
                    AnimatController.blinkingAnimat.push(element)
                }
            } else {
                element.endElement();
            }
        }
    },
    resetBlinkingAnimat : function() {// 闪烁复归
        for(var i = 0; i < AnimatController.blinkingAnimat.length; i++) {
            AnimatController.blinkingAnimat[i].endElement();
        }
        AnimatController.blinkingAnimat = [];
    }
};


// 在闭包中运行主程序
new function(){
    
}();
