
	var _BGIMG_ = { x:0, y:0, element: null };
	
	
	var TDADebugger = new Class({
		id: 'Debuger',
		styles: {
			background: 'rgba(255,102,0, .6)', //'#F60',
			margin : 0,
			padding: 0,
			position: 'fixed',
			zIndex: 100000000000000000000,
			top: 0,
			left: 0,
			width: '100%'		
		},
		
		closeBTN: new Element('a', {
			text: 'Effacer Debbugger',
			styles: {
				fontWeight: 'bold',
				fontSize: '14px',
				color: '#FFF'
			}
		}),
		
		div: new Element('div'),
		p: new Element('p'),
		
		initialize: function() {
			this.div.id = this.id;
			this.div.setStyles(this.styles);
			this.closeBTN.inject(this.div);
			this.p.inject(this.div);
			this.div.inject(document.body);
			var that = this;
			this.closeBTN.addEvent('click', function(e) { e.stop; that.remText(); });
			
		},
		
		addText: function(txt) {
			if($(this.id) != null)
				this.p.set('html', this.p.get('html')+'<br />'+txt );
		},
		
		remText: function() {
			this.p.set('html', '');
		},
		
		setText: function(txt) {
			if($(this.id) != null)
				this.p.set('html', txt);
		}
	});
	
	var DBUG = null;
	var TEST = null;
	
	window.addEvent('load', function(){
	
		/// debug sys
		var useDebug = null != window.location.hash && window.location.hash == '#DEBUG';
		TEST = (null != window.location.hash) && (window.location.hash == '#TEST');
		if(useDebug || TEST )
			DBUG = new TDADebugger();
			
		// when background image is ready ...
		var img = $$('#backgrounder img.wallPaper')[0];
		
		
		if(img) {
			setBGImg(img);
			_BGIMG_.element.erase('width');
			_BGIMG_.element.erase('height');
			window.addEvent('resize', preSetSize);
			
			// si ie6 on gère le scroll à la main, sinon position:fixed, c'est plus joli !
			//~ if (Browser.Engine.name=='trident' && Browser.Engine.version <= 5) //IE6
				//~ placeBackground(null)
				//~ window.addEvent('scroll', placeBackground);
			//~ else {
				$('backgrounder').setStyles({position: 'fixed', left: 0, bottom: 0});			
			//~ }

			preSetSize();
		}
		
		
	});
	
	/// for Safari Bug ?
	function preSetSize() {
		setSize.delay(100);
	}
		
	function setBGImg(img) {		
		_BGIMG_.element = img;
		//new Image({src:img.src, events: {load: function(ev){alert('loade')}}});		
		_BGIMG_.x = img.getSize().x;
		_BGIMG_.y = img.getSize().y;
		
		//
		//~ if(TEST) initScroll();
	}
	
	function placeBackground(e) {
		var bg = $('backgrounder');
		var wScr = window.getScroll();
		bg.setStyles({
			left : wScr.x+'px',
			top  : wScr.y+'px'
		});
	}
		
	function setSize() {
		var bg = $('backgrounder');
		//~ var backWidth  = Math.min(1600, TEST ? bg.getSize().x : 1150); //bg.getSize().x;
		var backWidth  = Math.min(1600, (TEST ? bg.getSize().x : 1280) ); //bg.getSize().x;
		var backHeight = bg.getSize().y;
		
		//~ if(null!=DBUG)
			//~ DBUG.setText('bW: '+backWidth+' bgImg: '+_BGIMG_.x)
		
		// on resize par rapport à la largeur
	if(_BGIMG_.element && _BGIMG_.x < document.body.getSize().x ) {
	//~ if(_BGIMG_.element  ) {
			var newImgWidth  = document.body.getSize().x;
			//~ var newImgWidth  = backWidth+150;
			var newImgHeight = _BGIMG_.y * (newImgWidth/_BGIMG_.x);
			
			if(newImgHeight < document.body.getSize().y) {
				newImgWidth *= document.body.getSize().y/newImgHeight;
				newImgHeight = document.body.getSize().y;
			}
			
			_BGIMG_.element.set('width',  newImgWidth);
			_BGIMG_.element.set('height', Math.round(newImgHeight));
			
			if(TEST) DBUG.addText('bW/bH= '+(_BGIMG_.x/_BGIMG_.y)+' ::: nW/Nh= '+(newImgWidth/newImgHeight));
		}
		
		$('main').setStyle('width', backWidth+'px');
		$('main').setStyle('left', 0); //Math.max(0, (bg.getSize().x - backWidth)/2)+'px' );
		
		// definir le height du background à cause bug SAFARI MAC
		bg.setStyles({ left: 0, top: 0, height: _BGIMG_.y+'px' });
		
		
	}
	
	function initScroll() {
		var bg = $('backgrounder');
		_BGIMG_.element.setStyle('position', 'absolute');
		document.body.addEvent('mousemove', function(ev) {
		
			//~ var center		=	{ x: document.body.getSize().x/2,		y: document.body.getSize().y/2 };
			//~ var deltaMouse	=	{ x: (center.x-ev.client.x),			y: (center.y-ev.client.y)};
			var image		=	{ w: _BGIMG_.element.getSize().x,		h: _BGIMG_.element.getSize().y };
			//~ var deltaSize 	=	{ x: image.w-document.body.getSize().x,	y: image.h-document.body.getSize().y };
		
			//~ var newPos		=	{ x: deltaMouse.x*deltaSize.x/(2*center.x) -deltaSize.x/2,				y:  deltaMouse.y*deltaSize.y/(2*center.y) - deltaSize.y/2 }
			var newPos		=	{ 
				x: ev.client.x*(1-image.w/document.body.getSize().x),
				y: ev.client.y*(1-image.h/document.body.getSize().y)
			}
		
			_BGIMG_.element.setPosition( { x: newPos.x, y: newPos.y	} );
				
		 /*if(null!=DBUG)
				DBUG.setText(
					'center: '+center.x+'/'+center.y+'; <br /> \
					SIZE : doc '+document.body.getSize().x+' // main '+(bg.getSize().x)+' // img '+(image.w)+';<br /> \
					deltaMouse: '+deltaMouse.x+'/'+deltaMouse.y+';<br /> \
					deltaSize: '+deltaSize.x+'/'+deltaSize.y+'; <br /> \
					bg: '+newPos.x+'/'+newPos.y
				);*/
		});
	}
