﻿pandora.util.storage.prototype = {
	_local : null,
	_beType : new Array(String, Hash, Array, Object),
    _temp : [],
	
	_getLocal : function(){
		return this._local;
	},	
	
	initialize : function(){
		this._local = new Hash();
	},	
	
	appendData : function(obj){
		this._local.merge(obj);
	},

	appendHash : function(key, value){
		this._local.merge( {key:null} );
		this._local[key] = value;
		return this._local[key];
	},
	
	getChild : function(child){
		return this._getLocal()[child];
	},
	
	isKey : function(key){
		if(typeof (this._getLocal()[key]) == 'undefined') return false;
		else return true;
	},
	
	size : function(){
		return this._getLocal().keys().length;
	},
	
	update : function(dest, value){
		for(i in this._beType){
			if(this._getLocal()[dest] instanceof this._beType[i]) {
				if(value instanceof this._beType[i]) this._getLocal()[dest] = value;
				else throw new Error("pandora.util.localstorage.update : Object type error");
			}
			
		}		
	},
	
	update2 : function(key, iterator, cond, value){
		var target = this._getLocal()[key][iterator];
		for(var i=0; i<target.length; i++){
			if(target[i]['prg_id'].toString() == cond) target[i]['ment_cnt'] = value;
		}
	},
	
	update3 : function(value) {
		var stKeys = this._getLocal().keys();
		for(var i=0;i<stKeys.length;i++) {
			if(stKeys[i].indexOf("page") > -1 && stKeys[i].indexOf("prg_id") > -1) {
				if(stKeys[i]['prgList']) {
					for(var j=0;i<stKeys[i]['prgList'].length;j++) {
						if(stKeys[i]['prgList'][j]['prg_id'] == value['prg_id']) {
							Object.extend(stKeys[i]['prgList'][j], value);
							break;
						}
					}
				}
			}
		}
	},
	
	remove : function(dest){
		this._getLocal().remove(dest);
	},
	
	clear : function(){
		this._local = null;
		this.initialize();
	}	
};
	
var Storage = Class.create();
Object.extend(Storage.prototype, new pandora.util.storage());

var cStorageMgr = Class.create();
	cStorageMgr._instance_ = null;
	cStorageMgr.getInstance = function(){
			if(this._instance_==null) this._instance_ = new Storage();
			return this._instance_;
	};
