function wwStateContainer()
{
	this.attributes = new Object();
}

wwStateContainer.prototype.fromJSON = function(ob)
{
	for(var key in ob)
	{
		this.addKey(key,ob[key][0]);
		if(ob[key].length > 1) this.setValue(key,ob[key][1]);
	}
}

wwStateContainer.prototype.addKey = function(key,def)
{
	this.attributes[key] = new Object();
	this.attributes[key]['default'] = def;
}

wwStateContainer.prototype.copyEntry = function(state_container, key)
{
	if(!state_container.hasKey(key)) return;
	this.addKey(key,state_container.getDefaultValue(key));
	this.setValue(key,state_container.getValue(key));
}

wwStateContainer.prototype.clone = function()
{
	var res = new wwStateContainer();
	for(key in this.attributes)
	{
		res.copyEntry(this,key);
	}
	
	return res;
}

wwStateContainer.prototype.getNeededChanges = function(target_state)
{
	var res = new Array();
	for( key in this.attributes ){
		if(target_state.hasKey(key) && this.getValue(key) != target_state.getValue(key)){
			res.push(key);
		} 
	}
	
	return res;
}

wwStateContainer.prototype.apply = function(target_state)
{
	for( key in this.attributes ){
		if(target_state.hasKey(key) && !target_state.isDefaultValue(key)){
			this.setValue(key,target_state.getValue(key));
		}
	}
}

wwStateContainer.prototype.setValues = function(arr)
{
	for(key in arr)
	{
		this.setValue(key,arr[key]);
	}
}

wwStateContainer.prototype.setValue = function(key,value)
{
	//var old = key+" "+value+" "+this.attributes[key]['value'];
	if(this.hasKey(key))
	{
		if(value == this.attributes[key]['default'])
			delete this.attributes[key]['value'];
		else
			this.attributes[key]['value'] = value;
	}
	
	//alert(old+" "+this.attributes[key]['value']);
}

wwStateContainer.prototype.getDefaultValue = function(key)
{
	if(!this.hasKey(key)) return null;
	return this.attributes[key]['default'];
}

wwStateContainer.prototype.isDefaultValue = function(key)
{
	if(typeof(this.attributes[key]['value']) != 'undefined'){
		return false;
	}
	
	return true;
}

wwStateContainer.prototype.getValue = function(key)
{
	if(!this.hasKey(key)) return null;
	if(this.isDefaultValue(key))
	{
		return this.attributes[key]['default'];
	}
		
	return this.attributes[key]['value'];
}

wwStateContainer.prototype.hasKey = function(key)
{
	if(this.attributes[key]) return true;
	return false;
}

wwStateContainer.prototype.getKeys = function()
{
	return Object.keys(this.attributes);
}

wwStateContainer.prototype.getQueryString = function(replacements)
{
	res = new Object();
	
	if(!replacements) replacements = new Object();
	
	for(key in this.attributes)
	{
		if(typeof(replacements[key]) != 'undefined')
		{
			res[key] = replacements[key];
		}
		else
		{
			if(!this.isDefaultValue(key))
			{
				res[key] = this.getValue(key);
			}
		}
		
	}
	
	return $H(res).toQueryString();
}