var IndexMediator = {

	CLASS_NAME_SELECTED             : 'selected',
	CLASS_NAME_SMOKED_GROUP_ENABLED : 'smoked',
	CLASS_NAME_FIRED                : 'fired',
	CLASS_NAME_INVISIBLE            : 'invisible',
	CLASS_NAME_HIDDEN               : 'hidden',
	CLASS_NAME_SMOKED_END           : 'smoked-end',

	FACTOR_SMOKE        : 10,
	TEMPERATURE_MIN     : 300,
	TEMPERATURE_MAX     : 950,
	TEMPERATURE_AVERAGE : 600,	
	COLOR_MIN_RGB       : Animator.toRgb('#821600'),
	COLOR_MAX_RGB       : Animator.toRgb('#FF4900'),
	COLOR_AVERAGE_RGB   : Animator.toRgb('#AB2700'),
	COLOR_END           : '#252525',

	oElementMeasurer           : null,
	oElementFire               : null,
	oElementAddCaption         : null,
	oElementIntro              : null,
	oElementHeaderArticles     : null,
	oElementHeaderGlosario     : null,
	oElementStartControl       : null,
	oElementSmokeControl       : null,
	oElementAshControl         : null,
	oElementMiddleControls     : null,
	aElementThirdControls      : null,
	aElementThirdGroups        : null,
	oElementBow                : null,
	aElementBows               : null,
	aElementBowPreviews        : null,
	oElementArticles           : null,
	aElementsArticles          : null,
	aElementsBanners           : null,
	aElementsKeywords          : null,
	aElementsProducts          : null,
	oElementSmoke              : null,
	aElementsSmoke             : null,

	oButtonShowFiredVersion    : null,
	oButtonSmokeControl        : null,
	oButtonAshControl          : null,
	aButtonThirdControls       : null,
	oButtonBowControl          : null,
	oButtonEndControl          : null,
	oPopupLoader               : null,
	oPopupLoaderProducts       : null,

	oSliderTemperature         : null,

	oAnimationController       : null,
	aAnimationSmokes           : [],

	bLoaded                     : false,
	bEnabledBanners             : false,
	bFireProcessing             : false,
	bShowedFiredVersion         : false,
	bAshFlickProcessing         : false,
	bSmokedEnd                  : false,
	oLabels                     : null,
	iInitialOffsetElementFire   : 0,
	iCurrentBowIndex            : 0,
	iCurrentAnimationSmokeIndex : -1,
	iSelectedKeywordIndex       : -1,
	iSelectedProductIndex       : -1,
	iTemperatureCurrent         : 600,
	aColorDiffsBeforeAverage    : null,
	aColorDiffsAfterAverage     : null,
	sClassNameSmokeGroups       : '',

	init : function(oLabels) {

		this.setLabels(oLabels);
		this.initElements();
		this.initObjects();

	},

	setLabels : function(oLabels) {

		this.oLabels = oLabels;

	},

	initElements : function() {

		this.oElementMeasurer           = document.getElementById('min-width');
		this.aElementsBanners           = Common.Dom.getElementsByClassName(document.getElementById('header'), 'banner', 'div');
		this.oElementFire               = document.getElementById('fire').getElementsByTagName('span')[0];
		this.oElementAddCaption         = document.getElementById('add-caption');
		this.oElementIntro              = document.getElementById('intro');
		this.oElementHeaderArticles     = document.getElementById('header-articles');
		this.oElementHeaderGlosario     = document.getElementById('header-glosario');
		this.oElementArticles           = document.getElementById('articles'); 
		this.aElementsArticles          = this.oElementArticles.getElementsByTagName('a');
		this.oElementStartControl       = document.getElementById('start-control'); 
		this.oElementSmokeControl       = document.getElementById('smoke-control');
		this.oElementMiddleControls     = document.getElementById('middle-controls');
		this.aElementThirdControls      = [document.getElementById('first-third-control'), document.getElementById('second-third-control'), document.getElementById('third-third-control')];
		this.aElementThirdGroups        = Common.Dom.getElementsByClassName(
			document.getElementById('second-third'),
			'group',
			'div'
			);
		this.oElementAshControl = document.getElementById('ash-control');
		this.aElementBows = Common.Dom.getElementsByClassName(
			document.getElementById('bows'),
			'bow',
			'div'
			);

		var oThis = this;

		for(var i = 0; i < this.aElementBows.length; i++) {
			Common.Event.add(
				this.aElementBows[i],
				'click',
				function() {

					oThis.removeBow();

				}
				);
		}

		this.oElementBow = document.getElementById('bow-preview');
		this.aElementBowPreviews = this.oElementBow.getElementsByTagName('div');

		this.oElementSmoke = document.getElementById('smoke');
		this.aElementsSmoke = [];

		var aElementSmokeGroups = this.oElementSmoke.getElementsByTagName('div');

		for(var i = 0, aElements; i < aElementSmokeGroups.length; i++) {

			aElements = aElementSmokeGroups[i].getElementsByTagName('span');

			this.aElementsSmoke[i] = [];

			for(var j = 0; j < aElements.length; j++) {

				aElements[j].style.marginLeft = -this.pixelsToEm(aElements[j].offsetWidth) / 2 + 'px';

				this.aElementsSmoke[i].push(
					{
						oElement    : aElements[j],
						iPathIndex  : 0,
						iPointIndex : 0
					}
					);
				
			}

			this.aAnimationSmokes.push(new AnimationSmoke(this.aElementsSmoke[i]));

			this.aAnimationSmokes[i].setStopCallbackFunction(
				function(i) {

					return function() {

						if(oThis.bSmokedEnd) {
							return;
						}

						oThis.iCurrentAnimationSmokeIndex = i >= oThis.aAnimationSmokes.length - 1? 0 : i + 1;

						var oAnimationSmoke = oThis.aAnimationSmokes[oThis.iCurrentAnimationSmokeIndex];

						oAnimationSmoke.reset();

						oThis.oAnimationController.addAnimation(oAnimationSmoke);
						oThis.oAnimationController.start();

					}

				}(i)
				);

		}

		this.iInitialOffsetElementFire = this.pixelsToEm(this.oElementFire.offsetTop);

		this.aColorDiffsBeforeAverage = [IndexMediator.COLOR_AVERAGE_RGB[0] - IndexMediator.COLOR_MIN_RGB[0], IndexMediator.COLOR_AVERAGE_RGB[1] - IndexMediator.COLOR_MIN_RGB[1], IndexMediator.COLOR_AVERAGE_RGB[2] - IndexMediator.COLOR_MIN_RGB[2]];
		this.aColorDiffsAfterAverage = [IndexMediator.COLOR_MAX_RGB[0] - IndexMediator.COLOR_AVERAGE_RGB[0], IndexMediator.COLOR_MAX_RGB[1] - IndexMediator.COLOR_AVERAGE_RGB[1], IndexMediator.COLOR_MAX_RGB[2] - IndexMediator.COLOR_AVERAGE_RGB[2]];

		this.aElementsKeywords = document.getElementById('glossary').getElementsByTagName('a');

		for(var i = 0; i < this.aElementsKeywords.length; i++) {
			Common.Event.add(
				this.aElementsKeywords[i],
				'click',
				function(iIndex) {

					return function(oEvent) {

						Common.Event.cancel(oEvent);

						oThis.oPopupLoader.load(oThis.aElementsKeywords[iIndex].href.match(/#term-(\d+)/)[1]);

						oThis.selectKeyword(iIndex);

					}

				}(i)
				);
		}

		this.aElementsProducts = document.getElementById('brands').getElementsByTagName('a');

		for(var i = 0; i < this.aElementsProducts.length; i++) {
			Common.Event.add(
				this.aElementsProducts[i],
				'click',
				function(iIndex) {

					return function(oEvent) {

						Common.Event.cancel(oEvent);

						oThis.oPopupLoaderProducts.load(oThis.aElementsProducts[iIndex].id.match(/brand-(\d+)/)[1]);

						oThis.selectProduct(iIndex);

					}

				}(i)
				);
		}

		Common.Event.add(
			window,
			'load',
			function() {

				Common.Class.add(
					oThis.oElementFire,
					'this'
					);
				
				oThis.oButtonShowFiredVersion = new ActionButton(
					oThis.oElementFire,
					[
						{
							fHandler : function() {

								oThis.showFiredVersion();

								return true;

							}
						}
					]
					);

				setTimeout(
					function() {

						oThis.showFiredVersion();

					},
					5000
					);

				oThis.bLoaded = true;

			}
			);

	},

	initObjects : function() {

		var oThis = this;

		this.oButtonSmokeControl = new ActionButton(
			Common.Dom.getElementsByClassName(this.oElementSmokeControl, 'this', 'span')[0],
			[
				{
					fHandler : function() {

						oThis.oAnimationController.pause();

						return true;

					},
					sLabel : this.oLabels.sSmokePause
				},
				{
					fHandler : function() {

						oThis.oAnimationController.resume();

						return true;

					},
					sLabel : this.oLabels.sSmokeResume
				}
			]
			);

		this.oButtonAshControl = new ActionButton(
			Common.Dom.getElementsByClassName(this.oElementAshControl, 'this', 'span')[0],
			[
				{
					fHandler : function() {

						oThis.flickAsh();

						return true;

					}
				}
			]
			);

		this.oButtonBowControl = new ActionButton(
			Common.Dom.getElementsByClassName(document.getElementById('bows'), 'this', 'span')[0],
			[
				{
					fHandler : function() {

						oThis.removeBow();

						return true;

					}
				}
			]
			);

		this.oButtonChangeBowControl =  new ActionButton(
			Common.Dom.getElementsByClassName(document.getElementById('bow-preview'), 'this', 'span')[0],
			[
				{
					fHandler : function() {

						oThis.reset();
						window.scrollTo(0, 0);
						oThis.changeBow();
						oThis.showFiredVersion();

						return true;

					}
				}
			]
			);

		this.oButtonEndControl =  new ActionButton(
			Common.Dom.getElementsByClassName(document.getElementById('end'), 'this', 'span')[0],
			[
				{
					fHandler : function() {

						oThis.reset();
						window.scrollTo(0, 0);
						oThis.changeBow();
						oThis.showFiredVersion();

						return true;

					}
				}
			]
			);

		this.aButtonThirdControls = [
			new ActionButton(
				Common.Dom.getElementsByClassName(this.aElementThirdControls[0], 'this', 'span')[0],
				[
					{
						fHandler : function() {

							oThis.smokeThird(0);

							return true;

						}
					}
				]
				),
			new ActionButton(
				Common.Dom.getElementsByClassName(this.aElementThirdControls[1], 'this', 'span')[0],
				[
					{
						fHandler : function() {

							oThis.smokeThird(1);

							return true;

						}
					}
				]
				),
			new ActionButton(
				Common.Dom.getElementsByClassName(this.aElementThirdControls[2], 'this', 'span')[0],
				[
					{
						fHandler : function() {

                			oThis.smokeThird(2);

							return true;

						}
					}
				]
			)
			];


		this.oSliderTemperature = xForm1.getWidgetById('field-temperature');

		xForm1.attachOuterObserver(this);

		this.oAnimationController = new AnimationController(1);

		this.oPopupLoader = new PopupLoader(
			new Popup(
				document.getElementById('popup-term')
				),
			'/ajax/glossary/',
			{
				oAnimationController : this.oAnimationController 
			}
			);

		this.oPopupLoader.attachObserver(
			Popup.EVENT_TYPE_ON_CLOSE,
			function() {

				oThis.unselectKeyword();

			}
			);

		this.oPopupLoaderProducts = new PopupLoader(
			new Popup(
				document.getElementById('popup-products')
				),
			'/ajax/products/',
			{
				oAnimationController : this.oAnimationController,
				sParamId : 'brand_id'
			}
			);

		this.oPopupLoaderProducts.attachObserver(
			Popup.EVENT_TYPE_ON_CLOSE,
			function() {

				oThis.unselectProduct();

			}
			);

	},

	selectKeyword : function(iIndex) {

		if(iIndex == this.iSelectedKeywordIndex) {
			return;
		}

		if(this.iSelectedKeywordIndex > -1) {
			Common.Class.remove(this.aElementsKeywords[this.iSelectedKeywordIndex], this.CLASS_NAME_SELECTED);
		}

		Common.Class.add(this.aElementsKeywords[iIndex], this.CLASS_NAME_SELECTED);

		this.iSelectedKeywordIndex = iIndex;

	},

	unselectKeyword : function() {

		if(this.iSelectedKeywordIndex == -1) {
			return;
		}

		Common.Class.remove(this.aElementsKeywords[this.iSelectedKeywordIndex], this.CLASS_NAME_SELECTED);

		this.iSelectedKeywordIndex = -1;

	},

	selectProduct : function(iIndex) {

		if(iIndex == this.iSelectedProductIndex) {
			return;
		}

		if(this.iSelectedProductIndex > -1) {
			Common.Class.remove(this.aElementsProducts[this.iSelectedProductIndex], this.CLASS_NAME_SELECTED);
		}

		Common.Class.add(this.aElementsProducts[iIndex], this.CLASS_NAME_SELECTED);

		this.iSelectedProductIndex = iIndex;

	},

	unselectProduct : function() {

		if(this.iSelectedProductIndex == -1) {
			return;
		}

		Common.Class.remove(this.aElementsProducts[this.iSelectedProductIndex], this.CLASS_NAME_SELECTED);

		this.iSelectedProductIndex = -1;

	},

	isShowedFiredVersion : function() {

		 return this.bShowedFiredVersion;

	},

	showNoFiredVersion : function() {				

		this.bShowedFiredVersion = false;			

		this.reset();

	},

	showFiredVersion : function() {

		if(this.bFireProcessing) {
			return;
		}
		
		this.bShowedFiredVersion = true;
		this.bFireProcessing = true;

		Common.Class.add(document.body, IndexMediator.CLASS_NAME_FIRED);

		this.oButtonChangeBowControl.disable();

		this.fire();

	},
		
	fire : function() {		

		var oThis = this;

		Common.Class.remove(this.oElementFire, 'this');

		this.fireFull(
			this.oElementFire,
			'#A35203',
			this.temperatureToRgb(this.TEMPERATURE_MAX),
			true,
			function() {

				oThis.fireFull(
					oThis.oElementAddCaption,
					'#A35203',
					oThis.temperatureToRgb(oThis.TEMPERATURE_MAX),
					true,
					function() {

						 oThis.fireFull(
							oThis.oElementIntro,
							'#DC7901',
							oThis.temperatureToRgb(oThis.TEMPERATURE_MAX),
							true,
							function() {

						 		oThis.fireFull(
									oThis.oElementHeaderArticles,
									'#A35203',
									'#FFFFFF',
									false,
									function() {

										for(var i = 0, bMain = false; i < oThis.aElementsArticles.length; i++) {

											bMain = Common.Class.match(oThis.aElementsArticles[i], 'main');

											oThis.fireFull(
												oThis.aElementsArticles[i],
												bMain? '#7A7500' : '#DC7901',
												bMain? '#FFFFFF' : '#9A9A9A'
												);

											if(i == oThis.aElementsArticles.length - 1) {
												oThis.fireFull(
													oThis.oElementHeaderGlosario,
													'#A35203',
													oThis.temperatureToRgb(oThis.TEMPERATURE_AVERAGE)
													);
											}

										}

										oThis.enableMainControls();
										oThis.oButtonChangeBowControl.enable();
										oThis.enableBanners();										

									}
									);

							}
							);

					}
					);

			}
			);

	},

	startSmoke : function() {

		this.iCurrentAnimationSmokeIndex = 0;

		this.aAnimationSmokes[this.iCurrentAnimationSmokeIndex].reset();

		this.oAnimationController.addAnimation(this.aAnimationSmokes[this.iCurrentAnimationSmokeIndex]);

		this.oAnimationController.start();

	},

	enableBanners : function() {

		if(this.bEnabledBanners) {
			return this.startSmoke();
		}

		for(var i = 0, oThis = this; i < this.aElementsBanners.length; i++) {
			Animator.fadeIn(this.aElementsBanners[i], { iFramesCount : 30, fStopCallbackFunction : i == this.aElementsBanners.length - 1? function() { oThis.startSmoke(); } : null });
		}

		this.bEnabledBanners = true;
				
	},

	enableMainControls : function() {

		this.oElementBow.style.top = this.oElementBow.offsetTop + 'px';

		this.hideElement(this.oElementStartControl);

		var oThis = this;

		this.oAnimationController.addAnimation(
			new AnimationEquation(
				this.oElementBow,
				{
					aProperties  : ['top'],
					aValuesStart : [this.oElementBow.offsetTop],
					aValuesEnd   : [0],
					aUnits       : ['px'],
					iFramesCount : 15,
					aEquations   : [AnimationEquation.Quartic.easeOut],
					fStopCallbackFunction : function(oAnimation) {

						oThis.showElement(oThis.oElementSmokeControl);
						oThis.showElement(oThis.oElementMiddleControls);						

					}
				}
				)
			);

	},

	fireFull : function(
		oElement,
		sColorStart,
		sColorEnd,
		bWithFadeOut,
		fStopCallbackFunction
		) {

		Animator.colour(
			oElement,
			{
				sColorStart           : sColorStart,
				sColorEnd             : sColorEnd,
				iFramesCount          : 15,
				oAnimationController  : this.oAnimationController,
				fStopCallbackFunction : function(oAnimation) {

					if(!bWithFadeOut) {
						return fStopCallbackFunction? fStopCallbackFunction(oAnimation) : false;
					}

					Animator.fadeOut(
						oAnimation.getElement(),
						{
							bOnlyHidden           : true,
							fStopCallbackFunction : function(oAnimation){ setTimeout(function() { fStopCallbackFunction(oAnimation) }, 30)}
						}
						);					

				}
			}
			);

	},

	flickAsh : function() {

		if(this.bAshFlickProcessing) {
			return;
		}

		this.bAshFlickProcessing = true;

		this.oAnimationController.addAnimation(
			new AnimationEquation(
				this.oElementArticles,
				{
					aValuesStart : [0],
					aValuesEnd   : [20],
					aUnits       : ['em'],
					iFramesCount : 30,
					aEquations   : [AnimationEquation.Quartic.easeOut],
					fStopCallbackFunction : function() {

						oThis.oElementArticles.style.left = '0';
						
					}
				}
				)
			);

		this.oAnimationController.start();

		var oThis = this;

		Animator.fadeOut(
			this.oElementArticles,
			{
				iFramesCount          : 30,
				bOnlyHidden           : true,
				oAnimationController  : this.oAnimationController,
				fStopCallbackFunction : function() {

					if(oThis.bSmokedEnd) {

						oThis.bAshFlickProcessing = false;						
						oThis.oButtonAshControl.disable();						

						return;

					}

					Animator.fadeIn(
						oThis.oElementArticles,
						{
							iFramesCount          : 35,
							bOnlyHidden           : true,
							oAnimationController  : this.oAnimationController,
							fStopCallbackFunction : function() {

								oThis.bAshFlickProcessing = false;

							}							
						}
					);
					
					oThis.oAnimationController.start();

				}
			}
			);

	},

	smokeThird : function(iIndex) {

		this.hideElement(this.aElementThirdControls[iIndex]);

		var
			oThis = this,
			iTemperatureStart = this.iTemperatureCurrent
			;

		this.oAnimationController.addAnimation(
			new AnimationEquation(
				this.oElementHeaderGlosario,
				{
					aProperties       : null,
					iFramesCount      : 15,
					fCallbackFunction : function(oAnimation) {

						oThis.oSliderTemperature.setValue(
							new ValueNumber(
								AnimationEquation.linear(
									oAnimation.getFrameCurrent(),
									iTemperatureStart,
									IndexMediator.TEMPERATURE_MAX - iTemperatureStart,
									oAnimation.iFramesCount
									)
								)
							);

					}
				}
				)
			);

		this.oAnimationController.addAnimation(
			new AnimationEquation(
				this.aElementThirdGroups[iIndex],
				{
					aProperties           : ['top', 'marginBottom'],
					aValuesStart          : [0, 0],
					aValuesEnd            : [-this.aElementThirdGroups[iIndex].offsetHeight, -this.aElementThirdGroups[iIndex].offsetHeight],
					aEquations            : [AnimationEquation.Cubic.easeIn, AnimationEquation.Cubic.easeIn],
					aUnits                : ['px', 'px'],
					iFramesCount          : 50,
					fStopCallbackFunction : function() {
			 			
						oThis.hideElement(oThis.aElementThirdGroups[iIndex]);

						if(iIndex < oThis.aElementThirdControls.length - 1) {

							oThis.oAnimationController.addAnimation(
								new AnimationEquation(
									oThis.oElementHeaderGlosario,
									{
										aProperties	      : null,
										iFramesCount	  : 15,
										fCallbackFunction : function(oAnimation) {

											oThis.oSliderTemperature.setValue(
												new ValueNumber(
													AnimationEquation.linear(
														oAnimation.getFrameCurrent(),
														IndexMediator.TEMPERATURE_MAX,
														IndexMediator.TEMPERATURE_AVERAGE - IndexMediator.TEMPERATURE_MAX,
														oAnimation.iFramesCount
														)
													)
												);

										},
										fStopCallbackFunction : function() {											

											oThis.showElement(oThis.aElementThirdControls[iIndex + 1]);
																						
										}
									}
									)
								);

						}
						else {
							oThis.endSmoke();							
						}

					}
				}
				)
			);

		this.oAnimationController.start();

	},

	endSmoke : function() {

		this.bSmokedEnd = true;

		this.oAnimationController.stop();

		this.oButtonSmokeControl.setState(0);
		this.oButtonSmokeControl.disable();

		if(this.iCurrentAnimationSmokeIndex > -1) {

			var oAnimationSmoke = this.aAnimationSmokes[this.iCurrentAnimationSmokeIndex];

			this.oAnimationController.addAnimation(oAnimationSmoke);
			this.oAnimationController.start();

		}

		var oThis = this;

		this.oAnimationController.addAnimation(
			new AnimationEquation(
				this.oElementFire,
				{
					aProperties       : null,
					iFramesCount      : 40,
					fCallbackFunction : function(oAnimation) {

						oThis.oSliderTemperature.setValue(
							new ValueNumber(
								AnimationEquation.linear(
									oAnimation.getFrameCurrent(),
									IndexMediator.TEMPERATURE_MAX,
									IndexMediator.TEMPERATURE_MIN - IndexMediator.TEMPERATURE_MAX,
									oAnimation.iFramesCount
									)
								)
							);

					},
					fStopCallbackFunction : function() {

						oThis.oSliderTemperature.disable();
						oThis.setTemperature(0);						

						Animator.colour(
							oThis.oElementFire,
							{
								sColorStart          : oThis.temperatureToRgb(IndexMediator.TEMPERATURE_MIN),
								sColorEnd            : IndexMediator.COLOR_END,
								iFramesCount         : 30,
								oAnimationController : oThis.oAnimationController
							}
						);


					}
				}
				)
			);

		this.oAnimationController.start();

	},

	// this callback use xForm

	update : function() {

		this.setTemperature(this.oSliderTemperature.getChildren()[0].getValue().get());

	},

	setTemperature : function(iTemperature) {

		this.iTemperatureCurrent = iTemperature;

		this.oElementHeaderGlosario.style.color = this.temperatureToRgb(iTemperature);

		var sClassNameSmokeGroups = this.temperatureToClassName(iTemperature);

		if(this.sClassNameSmokeGroups == sClassNameSmokeGroups) {
			return;
		}

		Common.Class.replace(
			this.oElementSmoke,
			this.sClassNameSmokeGroups,
			sClassNameSmokeGroups
			);

		this.sClassNameSmokeGroups = sClassNameSmokeGroups;

	},
	
	removeBow : function() {

		this.oButtonBowControl.disable();

		var oElementBow = this.aElementBows[this.iCurrentBowIndex];

		oElementBow.parentNode.style.height = oElementBow.offsetHeight + 'px';
		oElementBow.style.position = 'absolute';

		this.oAnimationController.addAnimation(
			new AnimationEquation(
				this.aElementBows[this.iCurrentBowIndex],
				{
					aProperties       : ['top'],
					iFramesCount      : 40,
					aValuesStart      : [0],
					aValuesEnd        : [80],
					aUnits            : ['em'],
					aEquations        : [AnimationEquation.Cubic.easeIn]
				}
				)
			);

		this.oAnimationController.start();

	},

	changeBow : function() {

		this.hideElement(this.aElementBows[this.iCurrentBowIndex]);
		this.hideElement(this.aElementBowPreviews[this.iCurrentBowIndex]);

		Common.Class.remove(document.body, 'bow-' + this.iCurrentBowIndex);

		this.iCurrentBowIndex = this.aElementBows[this.iCurrentBowIndex + 1]? this.iCurrentBowIndex + 1 : 0;

		Common.Class.add(document.body, 'bow-' + this.iCurrentBowIndex);

		this.showElement(this.aElementBows[this.iCurrentBowIndex]);
		this.showElement(this.aElementBowPreviews[this.iCurrentBowIndex]);

		this.aElementBows[this.iCurrentBowIndex].style.position = 'relative';
		this.aElementBows[this.iCurrentBowIndex].style.top = '0';
		this.aElementBows[this.iCurrentBowIndex].parentNode.style.height = 'auto';

	},

	reset : function() {

		Animator.stop();
		this.oAnimationController.stop();

		Common.Class.remove(document.body, IndexMediator.CLASS_NAME_FIRED);		

		/*
		this.showElement(this.aElementSmokeGroups[0]);

		for(var i = 0, aHrefs; i < this.aElementSmokeGroups.length; i++) {

			Common.Class.remove(
				this.aElementSmokeGroups[i],
				IndexMediator.CLASS_NAME_SMOKED_GROUP_ENABLED
				);

			Common.Dom.setStyle(
				this.aElementSmokeGroups[i],
				'left: 0; top: ' + (i > 0? 0 : '1.5em') + '; margin-bottom: 0;'
				);

			aHrefs = this.aElementSmokeGroups[i].getElementsByTagName('a');

			for(var j = 0; j < aHrefs.length; j++) {				
				Common.Dom.setStyle(
					aHrefs[j],
					'margin-left: 0; margin-top: 0'
					);
			}

		}
        */

		this.showElement(this.oElementStartControl);

		this.oElementFire.style.color = '';
		this.oElementIntro.style.color = '';
		this.oElementAddCaption.style.color = '';
		this.oElementHeaderArticles.style.color = '';

		for(var i = 0; i < this.aElementsArticles.length; i++) {
			this.aElementsArticles[i].style.color = '';
		}

		Common.Dom.setOpacity(this.oElementFire, 1);
		Common.Dom.setOpacity(this.oElementIntro, 1);
		Common.Dom.setOpacity(this.oElementAddCaption, 1);
		Common.Dom.setOpacity(this.oElementArticles, 1);

		this.removeHidden(this.oElementFire);
		this.removeHidden(this.oElementIntro);
		this.removeHidden(this.oElementAddCaption);
		this.removeHidden(this.oElementArticles);

		this.hideElement(this.oElementSmokeControl);
		this.hideElement(this.oElementMiddleControls);

		this.showElement(this.aElementThirdControls[0]);
		this.hideElement(this.aElementThirdControls[1]);
		this.hideElement(this.aElementThirdControls[2]);

		for(var i = 0; i < this.aElementThirdGroups.length; i++) {

			Common.Dom.setStyle(
				this.aElementThirdGroups[i],
				'top: 0; margin-bottom: 0;'
				);

			this.showElement(this.aElementThirdGroups[i]);

		}

		// reset smoke

		for(var i = 0; i < this.aElementsSmoke.length; i++) {
			for(var j = 0; j < this.aElementsSmoke[i].length; j++) {
				this.aElementsSmoke[i][j].oElement.style.top = '101%';
			}
		}

		// enable buttons

		this.oButtonAshControl.enable();
		this.oButtonSmokeControl.enable();
		this.oButtonSmokeControl.setState(0);

		this.oSliderTemperature.enable();
		
		this.iTemperatureCurrent = IndexMediator.TEMPERATURE_AVERAGE;

		this.oSliderTemperature.setValue(new ValueNumber(this.iTemperatureCurrent));
		this.setTemperature(this.iTemperatureCurrent);		

		// reset bow		

		this.aElementBows[this.iCurrentBowIndex].style.position = 'relative';
		this.aElementBows[this.iCurrentBowIndex].style.top = '0';

		this.oButtonBowControl.enable();		

		this.oElementHeaderGlosario.style.color = '';

		this.bSmokedEnd = false;
		this.bShowedFiredVersion = false;
		this.bFireProcessing = false;

	},

	pixelsToEm : function(iPixels) {

		return iPixels / this.oElementMeasurer.offsetHeight;	

	},

	emToPixels : function(dEm) {

		return this.oElementMeasurer.offsetHeight * dEm;	

	},

	showElement : function(oElement) {

		Common.Class.remove(
			oElement,
			IndexMediator.CLASS_NAME_INVISIBLE
			);

	},

	hideElement : function(oElement) {

		Common.Class.add(
			oElement,
			IndexMediator.CLASS_NAME_INVISIBLE
			);

	},

	removeHidden : function(oElement) {

		Common.Class.remove(
			oElement,
			IndexMediator.CLASS_NAME_HIDDEN
			);

	},

	temperatureToRgb : function(iTemperature) {

		var dPercent;

		if(iTemperature < IndexMediator.TEMPERATURE_AVERAGE) {

			dPercent = (iTemperature - IndexMediator.TEMPERATURE_MIN)/(IndexMediator.TEMPERATURE_AVERAGE - IndexMediator.TEMPERATURE_MIN);

			return 'rgb(' + (Math.round(this.aColorDiffsBeforeAverage[0] * dPercent) + IndexMediator.COLOR_MIN_RGB[0]) + ',' + (Math.round(this.aColorDiffsBeforeAverage[1] * dPercent) + IndexMediator.COLOR_MIN_RGB[1]) + ',' + (Math.round(this.aColorDiffsBeforeAverage[2] * dPercent) + IndexMediator.COLOR_MIN_RGB[2]) + ')';

		}

		dPercent = (iTemperature - IndexMediator.TEMPERATURE_AVERAGE)/(IndexMediator.TEMPERATURE_MAX - IndexMediator.TEMPERATURE_AVERAGE);

		return 'rgb(' + (Math.round(this.aColorDiffsAfterAverage[0] * dPercent) + IndexMediator.COLOR_AVERAGE_RGB[0]) + ',' + (Math.round(this.aColorDiffsAfterAverage[1] * dPercent) + IndexMediator.COLOR_AVERAGE_RGB[1]) + ',' + (Math.round(this.aColorDiffsAfterAverage[2] * dPercent) + IndexMediator.COLOR_AVERAGE_RGB[2]) + ')';

	},

	temperatureToClassName : function(iTemperature) {

		if(iTemperature < 300) {
		    return 'color-0';
		}

		if(iTemperature < 450) {
		    return 'color-300';
		}

		if(iTemperature < 600) {
			return 'color-450';
		}

		if(iTemperature < 800) {
			return 'color-600';
		}

		if(iTemperature < 950) {
			return 'color-800';
		}

		return 'color-950'; 

	}

};