var Ihm_Document = Class.create(Ihm_Abstract_Effect,
{
	initialize: function ($super, conf)
	{
		var options = {
				ihm_containerId: 'systemLoading',
				screen_containerId: 'systemOverlay',
				screenEffect_opacity: 0.0,
				screenEffect_backgroundColor: 'white'
		};

		Object.extend(options, conf || {});
		$super(options);
	},

	startScreenEffect: function ()
	{
		var element = $(this.options.screen_containerId);

		if(!element.visible()){
			element.setStyle({backgroundColor:this.options.screenEffect_backgroundColor, opacity:this.options.screenEffect_opacity}).show();
		}
	},

	stopScreenEffect: function ()
	{
		var element = $(this.options.screen_containerId);

		if(element.visible()) {
			element.hide();
		}
	},

	startIhmEffect: function ()
	{
		$(this.options.ihm_containerId).show();
	},

	stopIhmEffect: function ()
	{
		$(this.options.ihm_containerId).hide();
	},

	rezise: function ()
	{
		this.rezise_main();
		this.resize_display();
	},

	reziseForEvent: function ()
	{
		this.resize_display();
	},

	rezise_main: function ()
	{
		//this.rezise_mainMiddle();
		//this.rezise_mainBottom();
	},

	rezise_mainMiddle: function ()
	{
		var top = ($('mainMiddle').hasClassName('absolute')) ? (this.getMainMiddleTop()+'px') : (null);
		$('mainMiddle').setStyle({top:top});
	},

	rezise_mainBottom: function ()
	{
		var top = ($('mainBottom').hasClassName('absolute')) ? (this.getMainBottomTop()+'px') : (null);
		$('mainBottom').setStyle({top:top});
	},

	resize_display: function ()
	{
		var enableAbsoluteMode = (document.viewport.getHeight() >= 850);
		(enableAbsoluteMode) ? (this.rezise_display_absolute()) : (this.rezise_display_relative());

		var minWidth = parseInt($('mainTop').getStyle('min-width').replace('px', ''));

		if(document.viewport.getWidth() <= minWidth) {
			$J('#mainTop, #mainMiddle, #mainBottom').removeClass('highDefinition');
			$J('#mainTop, #mainMiddle, #mainBottom').removeClass('mediumDefinition');
			$J('#mainTop, #mainMiddle, #mainBottom').addClass('lowDefinition');
		}
		else if($('mainTop').getWidth() <= minWidth) {
			$J('#mainTop, #mainMiddle, #mainBottom').removeClass('highDefinition');
			$J('#mainTop, #mainMiddle, #mainBottom').removeClass('lowDefinition');
			$J('#mainTop, #mainMiddle, #mainBottom').addClass('mediumDefinition');
		}
		else {
			$J('#mainTop, #mainMiddle, #mainBottom').removeClass('mediumDefinition');
			$J('#mainTop, #mainMiddle, #mainBottom').removeClass('lowDefinition');
			$J('#mainTop, #mainMiddle, #mainBottom').addClass('highDefinition');
		}
	},

	rezise_display_absolute: function ()
	{
		$J('#mainTop, #mainMiddle, #mainBottom, #contents').removeClass('relative');
		$J('#mainTop, #mainMiddle, #mainBottom, #contents').addClass('relative');
		this.rezise_main();
	},

	rezise_display_relative: function ()
	{
		$J('#mainTop, #mainMiddle, #mainBottom, #contents').removeClass('absolute');
		$J('#mainTop, #mainMiddle, #mainBottom, #contents').addClass('relative');
		this.rezise_main();
	},

	auto: function ()
	{
		this.start();
		Event.observe(window, 'load', this.stop.bindAsEventListener(this));
		Event.observe(window, 'resize', this.reziseForEvent.bindAsEventListener(this));
	},

	start: function ()
	{
		this.startScreenEffect();
		this.startIhmEffect();
	},

	stop: function ()
	{
		this.rezise();
		this.stopIhmEffect();
		this.stopScreenEffect();
	},

	getMainMiddleTop: function ()
	{
		return $('mainTop').cumulativeOffset().top + $('mainTop').getHeight();
	},

	getMainBottomTop: function ()
	{
		return $('mainMiddle').cumulativeOffset().top + $('mainMiddle').getHeight(); //"cumulativeOffset" sur "mainMiddle" englobe la hauteur de "mainTop"
	},

	getMainBottomLeft: function ()
	{
		return $('mainBottom').cumulativeOffset().left;
	}
}
);
