/*
Script: price.js

License:
        MIT-style license.

About:
		price.js for mootools framework <http://www.mootools.net/> (c) 2007 Valerio Proietti, MIT-style license.
		Class created by Sylvain Barraud, Yvan Cottet and Gregory Paccaud, <http://www.esl.ch/>.
		Last modification, 7 mars 2008.

Version: 1.0

Note:
		XHTML doctype is required.
		
*/

var Price = new Class({
	
	Implements : Options,

	options: {
		firstyear : 2012,
		secondyear : 2013
	},
	
	initialize : function(options) {
		this.setOptions(options);
		//this.initStyle();
		if ($('firstyear')) {
			this.initPriceTabs()
		}else{
			$$('.price'+this.options.secondyear).each(function(lol){
				lol.addClass('hide');
			})
		}
	},
	
	// -----------------------------------------------------------------
	
	initPriceTabs : function() {
		$$('.price'+this.options.secondyear).each(function(lol){	
			lol.addClass('hide');
		})
		
		$('firstyear').addClass('year_s').addEvent('click',function(){
			this.showYears(this.options.firstyear, this.options.secondyear);
		}.bind(this));
		$('secondyear').addEvent('click',function(){
			this.showYears(this.options.secondyear, this.options.firstyear);
		}.bind(this));
	},
	
	showYears : function(show,hide){
		//if this is not the same year then switch year
		$$('.price'+show).each(function(lol){
			
			if(lol.hasClass('hide')){
				$('firstyear').toggleClass('year_s');
				$('secondyear').toggleClass('year_s');
				$$('.price'+show).each(function(lol){
					lol.toggleClass('hide');
				})
				
				$$('.price'+hide).each(function(lol){
					lol.toggleClass('hide');
				})
				
				$$('.periodcut').each(function(period){
					var date = period.getText();
					if (date.match(show)) {
						period.removeClass('hide');
					}else {
						period.addClass('hide');	
					}					   
				});
				
				lol.removeClass('hide');
			}
		})	
	}
	
});
