/**
 * Search data accessor and container.
 * 
 * Provides cookie accessing methods.
 * 
 * ----
 * 
 * LICENCE
 * 
 * This work is licensed under Creative Commons Attribution-Share Alike 3.0 (Germany).
 * For details on this licence visit http://creativecommons.org/licenses/by-sa/3.0/de/
 * 
 * All rights reserved
 * 
 * @author Jakob Hohlfeld | http://www.netronaut.de
 * @copyright 2010 by Jakob Hohlfeld
 * 
 */
var Minisearch_Data = new Class
({
	Implements: Events,
	
	cookie_name: null,
	options: new Hash({
		'location':'',
		'dates':{
			'arrival':0,
			'departure':0,
			'tolerance':{
				'arrival':0,
				'departure':0
			}
		},
		'persons':{
			'adults':2,
			'children':[]
		},
		'category':[0],
		'options':{
			'max_price':0,
			'max_beach_distance':0,
			'pets_allowed':false,
			'smoking':null
		}
	}),
	
	/**
	 * The constructor.
	 * 
	 * @param string cookie_name
	 */
	initialize: function ( cookie_name ) {
		this.cookie_name = cookie_name;
		this.read();
	},
	
	read: function () {
		this.options.extend(new Hash(JSON.decode(Cookie.read(this.cookie_name))));
	},
	
	write: function () {
		document.cookie = this.cookie_name + '=' + encodeURIComponent(JSON.encode(this.options.getClean())) + '; path=/; expires=' + new Date().clearTime().increment('day', 1).format('%c') + ';';
	}
})