var Listing = new Class({
	Implements: [Options, Events],
	options: {
 						
						orderField:false,
 						order:'ASC',
 						dataPath:'json/nodelist.json.php'
 					
  	},
	initialize: function(options) {
		this.setOptions(options);
		this.state = 'READY';
		
	},
	load:function(begin, end){
		this.state = 'LOADING';
		var params = {'begin':begin, 'end':end, 'order':this.options.order};
		if(this.options.orderField)
			params.orderField = this.options.orderField;	
		
		var request = new Request({
			url:this.options.dataPath,
			method:'get',
			data: params,
			onSuccess:this.fillElements.bind(this)
		}).send();
	},
	fillElements:function(obj){
		jsonObj = JSON.decode(obj);
		this.nbElems = jsonObj.length;
		
		if(this.nbElems == 0) this.state = 'DONE';
		else this.state = 'READY';
		
		this.elements = new Array();
		jsonObj.listing.each(function(item){
			var box = new Box({'id':item.id, 'name':item.name, 'time':item.time});
			this.elements.push(box.boxElem);
			
		}.bind(this));
		
		this.fireEvent('loaded');
	}
});

var Box = new Class({
	Implements: [Options, Events],
	options: {
 						id:'',
 						name:'',
 						time:''		
  },
 	
	initialize: function(options) {
		this.setOptions(options);
		this.getOpacity();
		this.makeElem();
	},
	getOpacity:function(){
		var hour = this.options.time.substring(11,13);
		this.opacity = (hour/24).round(2);
		
	},
	makeElem:function(){
		
		var background = new Element('div', {
			'class':'background',
			'opacity':this.opacity,
			'text':this.options.name
		});
		var textElem = new Element('div', {
			'class':'textElem',
			'text':this.options.name

		});
		
		this.boxElem = new Element('div',{'class':'box'});
		
		textElem.inject(this.boxElem);
		background.inject(this.boxElem);
		
	}
});