function parseVersion(version){
    var v = {major: 0, minor: 0, release: 0, value: 0};
    if(typeof(version) == 'string' && version.length > 0)
    {
        var r = version.split('.');
        if(version.length > 2)
        {
            v.major = parseInt(r[0]);
            v.minor = parseInt(r[1]);
            v.release = parseInt(r[2]);
            v.value = parseInt(r[0])*100000 + parseInt(r[1])*1000 + parseInt(r[2])
        }
        
    }
    return v;
}

//namespace Axisto
if(typeof(Axisto) == 'undefined')
    Axisto = {};

//namespace Axisto.PlayerLoaded
Axisto.Player = (function() {
    // private fields
    var prototypeRequired = {
        name: "Prototype",
        src: "js/prototype/1.6.0/prototype.js",
        version: "1.6.0",
        types: ["Prototype", "Element", "Element.Methods"]
    };
    
    // private members
    function isScriptLoaded(script){
        var isLoaded = false;
        if(script == null) 
            return isLoaded;
        
        for(var i=0; i<script.types.length; i++)
        {
            try
            {
                if(eval(script.types[i]) == 'undefined')
                {
                    isLoaded = false;
                    break;
                }
            }
            catch(ex)
            {
            }
        }
        return isLoaded;
    }
    
    // Everything returned in the object literal is public, but can access the
    // members in the closure created above.
    return {
        //public fields
        // public members
        init: function(){
            //load prototype
            if(isScriptLoaded(prototypeRequired))
            {
                if(parseVersion(prototypeRequired.Version).value < parseVersion(prototypeRequired.version).value)
                {
                    this.loadScript(prototypeRequired);
                }
            }
            else
            {
                this.loadScript(prototypeRequired);
            }
            
            //load axp
            this.loadScript({name: "axp", src: "js/axp/1.4.0/axp-loader.js"});
        },
        loadScript: function(script){
            //brute force, safari can't do dynamic element creation
            var src = script.version ? script.src+'?v='+script.version : script.src;
            document.write(unescape('%3Cscript src="' + src + '" type="text/javascript"%3E%3C/script%3E'));
        }
    };
})();

Axisto.Player.init();
