/*
Script: dpe.js
	Contains <_DPE>

Author:
	Olivier Gasc, <gasc.olivier@gmail.com>

License:
	MIT-style license.

Class: _DPE

Arguments:
Options:

Description:
	Classe gérant le DPE du site
*/

/* Class */
var _DPE = new Class({
    Implements: Options,

    options: {
		container: null,
		indicateur: null,
		ligne: null
	},

	range: [
		{ min: 0, max: 50},
		{ min: 51, max: 90},
		{ min: 91, max: 150},
		{ min: 151, max: 230},
		{ min: 231, max: 330},
		{ min: 331, max: 450},
		{ min: 451, max: 1000000}
	],

	value: null,
	niv: 0,

    initialize: function(options) {
        this.setOptions(options);

		var coordsContainer = this.options.container.getCoordinates();
		var coordsIndicateur = this.options.indicateur.getCoordinates();
		var coordsLigne = this.options.ligne.getCoordinates();

		this.options.indicateur.setStyles({
			top : coordsContainer.top + 1,
			left : coordsContainer.left + coordsContainer.width - $('gemco').getCoordinates().left
		});
		this.options.ligne.setStyles({
			top : coordsContainer.top + 1 + (coordsIndicateur.height / 2 - (coordsLigne.height / 2).round()),
			left : coordsContainer.left - $('gemco').getCoordinates().left
		});
    },

	scrollTo: function(value) {
		if (value) {
			this.value = value;

			var coordsContainer = this.options.container.getCoordinates();
			var coordsIndicateur = this.options.indicateur.getCoordinates();
			var coordsLigne = this.options.ligne.getCoordinates();

			this.range.each(function(e, i) {console.log(e);
				if (this.value >= e.min && this.value <= e.max) {
					this.niv = i;
				}
			}.bind(this));

			var top = coordsContainer.top + (20 * this.niv) + ((this.value - this.range[this.niv].min) / (this.range[this.niv].max - this.range[this.niv].min) * 20) - (coordsIndicateur.height / 2);

			if (this.niv == 0)
				top = coordsContainer.top + 1;
			else if (this.niv == 6)
				top = coordsContainer.top + 140 - coordsIndicateur.height;

			this.options.indicateur.setStyle('top', top.round());
			this.options.ligne.setStyle('top', top.round() + (coordsIndicateur.height / 2) - (coordsLigne.height / 2).round());
		}
	}
});
