STORAGE = {}; //Namespace

STORAGE.Storage_cl = new Class.create({
    initialize: function (useCookie) {
        useCookie = ((useCookie === undefined || useCookie === "") ? false : useCookie);
        this.isCookieActive = useCookie;
    },
    addItem_px: function (key, value) {
        var object = {data: value, key: key};
        if (this.isCookieActive) {

        } else {
            localStorage.setItem(key, JSON.stringify(object));
        }
    },
    removeItem_px: function (key) {
        if (this.isCookieActive) {

        } else {
            localStorage.removeItem(key);
        }
    },
    getItem_px: function (key) {
        try {
            if (this.isCookieActive) {


            } else {
                var strItem = localStorage.getItem(key);
                var item = JSON.parse(strItem);
                return item.data;
            }
        } catch (e) {
            console.log(e);
            return null;
        }
    },
    getItemWithDefault_px: function (key, defaultValue) {
        try {
            if (this.isCookieActive) {

            } else {
                var strItem = localStorage.getItem(key);
                var item = JSON.parse(strItem);
                return item.data;
            }
        } catch (e) {
            console.log(e);
            return defaultValue;
        }
    },
    addItemList_px: function (listname, value) {
        var object = {data: [], listname: listname};
        if (this.isCookieActive) {

        } else {
            if (this.getList_px(listname) !== null) {
                var list = this.getList_px(listname);
                list.push(value);
                object.data = list;
                localStorage.setItem('list_' + listname, JSON.stringify(object));
                return object.data.length - 1;
            } else {
                object.data.push(value);
                localStorage.setItem('list_' + listname, JSON.stringify(object));
                return 0;
            }
        }
    },
    removeItemList_px: function (listname, index) {
        var object = {data: [], listname: listname};
        try {
            if (this.isCookieActive) {

            } else {

                if (this.getList_px(listname) !== null) {
                    var list = this.getList_px(listname);
                    var removedItem = list[index];
                    object.data = this.removeFromList_p(list, index);
                    localStorage.setItem('list_' + listname, JSON.stringify(object));
                    return removedItem;
                }
            }
        } catch (e) {
            console.log(e);
            return null;
        }
    },
    getList_px: function (listname) {
        try {
            if (this.isCookieActive) {


            } else {

                var strList = localStorage.getItem('list_' + listname);
                var list = JSON.parse(strList);
                //console.log("getList_px('" + listname + "'): ");
                //console.log(list.data);
                return list.data;
            }
        } catch (e) {
            console.log(e);
            return null;
        }
    },
    deleteList_px: function (listname) {
        try {
            if (this.isCookieActive) {


            } else {
                if (this.getList_px(listname) !== null) {
                    var list = this.getList_px(listname);
                    localStorage.removeItem('list_' + listname);
                    return list;
                }

            }
        } catch (e) {
            console.log(e);
            return null;
        }
    },
    removeFromList_p: function (array, index) {

        if (index === 0) {
            array.splice(0, 1);
            return array;
        } else if (index === array.length - 1) {
            array.splice(array.length - 1, 1);
            return array;
        } else {
            array.splice(index, 1);
            return array;
        }
    }
});