if (typeof WsTools == "undefined") var WsTools = new Object();
WsTools.ContentPath = function()
{
    this.folder = null;
    this.subFolder = null;
    this.mediaCode = null;

    try
    {
        var hash = new WsTools.LocationHash();
        var path = hash.get("path", null);
        if (path == null || path == "")
        {
            return;
        }

        if (path.substr(0, 1) != "/")
        {
            path = "/" + path;
        }
        var folders = path.split("/");
        if (folders.length >= 2)
        {
            this.folder = folders[1];
        }
        if (folders.length >= 3)
        {
            this.subFolder = folders[2];
        }
        if (folders.length >= 4)
        {
            this.mediaCode = folders[3];
        }
    }
    catch(e)
    {
    }
}
WsTools.ContentPath.prototype = {
    getFolder: function()
    {
        return this.folder;
    },
    getSubFolder: function()
    {
        return this.subFolder;
    },
    getMediaCode: function()
    {
        return this.mediaCode;
    },
    clearMediaCode: function()
    {
        this.mediaCode = null;
    }
}


WsTools.LocationHash = function(qs)
{
    this.params = {};

    if (qs == null)
    {
        qs = location.hash.substring(1, location.hash.length);
    }
    if (qs.length == 0)
    {
        return;
    }

    // Turn <plus> back to <space>
    // See: http://www.w3.org/TR/REC-html40/interact/forms.html#h-17.13.4.1
    qs = qs.replace(/\+/g, ' ');
    var args = qs.split('&'); // parse out name/value pairs separated via &

    // split out each name=value pair
    for (var i = 0; i < args.length; i++)
    {
        var pair = args[i].split('=');
        var name = decodeURI(pair[0]);
        this.params[name] = (pair.length == 2) ? decodeURI(pair[1]) : name;
    }
}

WsTools.LocationHash.prototype = {
    get: function(key, default_)
    {
        var value = this.params[key];
        return (value != null) ? value : default_;
    }
}

var contentPath = new WsTools.ContentPath();
