var 	site = {
		init : function () {
			new showImage('contenu');
			homeImageSwap();
			document._getById('copy').onmousedown = function () {
				if (!document.getElementById('__cms') && (!window._browser().isIE || window._browser().isIE9)) {
					conn();
				}
			};
		}
	};
var 	conn = function () {
		var _this = this;
		this.planeStyle = {
			'position' : 'fixed',
			'top' : '0',
			'right' : '0',
			'bottom' : '0',
			'left' : '0',
			'background-color' : '#000',
			'opacity' : '0.5'
		};
		this.containerSyle = {
			'position' : 'fixed',
			'top' : '50%',
			'left' : '50%',
			'background-color' : 'orange',
			'padding' : '10px 10px 10px 10px',
			'border' : 'solid 1px #000',
			'-moz-border-radius' : '5px',
			'border-radius' : '5px',
			'-webkit-box-shadow' : '0px 2px 20px #000000',
			'-moz-box-shadow' : '0px 2px 20px #000000',
			'box-shadow' : '0px 2px 20px #000000'
		};
		this.titleStyle = {
			'-moz-border-radius' : '3px',
			'border-radius' : '3px',
			'background-color' : '#B04B00',
			'color' : '#fff',
			'font' : 'normal 16px arial',
			'padding' : '2px 5px',
			'margin' : '0 0 10px 0'
		};
		this.paragraphStyle = {
			'margin' : '0 0 2px 0',
			'padding' : '0'
		};
		this.labelStyle = {
			'float' : 'left',
			'width' : '120px',
			'color' : '#000',
			'padding' : '2px 0 2px 0',
			'font' : 'bold 11px arial',
			'border-bottom' : 'dotted 1px #AE5C02',
			'color' : '#542D01'
		};
		this.inputStyle = {
			'width' : '220px',
			'margin-left' : '2px',
			'font' : '11px tahoma',
			'border' : 'solid 1px #AE5C02',
			'padding' : '2px'
		};
		this.buttonStyle = {
			'width' : '100px',
			'font' : 'bold 11px arial'
		};
		this.infoStyle = {
			'-moz-border-radius' : '3px',
			'border-radius' : '3px',
			'background-color' : '#CFDF06',
			'color' : '#414602',
			'font' : 'bold 11px arial',
			'text-align' : 'center',
			'padding' : '5px'
		};
		this.warnStyle = {
			'-moz-border-radius' : '3px',
			'border-radius' : '3px',
			'background-color' : '#BF0000',
			'color' : '#fff',
			'font' : 'bold 11px arial',
			'text-align' : 'center',
			'padding' : '5px'
		};
		this.plane = new _element('div')._setStyle(this.planeStyle)._appendTo(document.body);
		this.container = new _element('div')._setStyle(this.containerSyle)._appendTo(document.body);
		this.title = new _element('div')._setStyle(this.titleStyle)._setHtml('Authentification')._appendTo(this.container);
		this.p1 = new _element('p')._setStyle(this.paragraphStyle)._appendTo(this.container);
		this.p2 = new _element('p')._setStyle(this.paragraphStyle)._appendTo(this.container);
		this.p3 = new _element('p')._setStyle(this.paragraphStyle)._setStyle({
					'margin-top' : '10px',
					'padding-top' : '6px',
					'text-align' : 'right'
				})._appendTo(this.container);
		this.l1 = new _element('label')._setStyle(this.labelStyle)._setHtml('Nom d\'utilisateur')._appendTo(this.p1);
		this.l2 = new _element('label')._setStyle(this.labelStyle)._setHtml('Mot de passe')._appendTo(this.p2);
		this.i1 = new _element('input')._setAttributes({
					'type' : 'text'
				})._setStyle(this.inputStyle)._appendTo(this.p1);
		this.i2 = new _element('input')._setAttributes({
					'type' : 'password'
				})._setStyle(this.inputStyle)._appendTo(this.p2);
		this.sendButton = new _element('input')._setAttributes({
					'type' : 'button',
					'value' : 'envoyer'
				})._setStyle(this.buttonStyle)._addEvent('click', function () {
					_this.send();
				})._appendTo(this.p3);
		this.cancelButton = new _element('input')._setAttributes({
					'type' : 'button',
					'value' : 'annuler'
				})._setStyle(this.buttonStyle)._setStyle({
					'float' : 'left'
				})._addEvent('click', function () {
					_this.cancel();
				})._appendTo(this.p3);
		this.container._setStyle({
				'margin-top' : '-' + (this.container.offsetHeight / 2) + 'px',
				'margin-left' : '-' + (this.container.offsetWidth / 2) + 'px'
			});
		this.send = function () {
			var cnt = _this.p3,
			usr = _this.i1.value,
			psw = _this.i2.value;
			if (!document.getElementById('__info'))
				var info = new _element('p')._setAttributes({
							'id' : '__info'
						})._setStyle(_this.infoStyle)._setHtml('connexion ...')._appendBefore(cnt);
			new _request.post({
					file : '__php/conn.xhr.php',
					param : 'usr=' + usr + '&psw=' + psw,
					onSend : function () {},
					onReceive : function () {
						if (this.responseText == '1') {
							location.reload();
						} else {
							document.getElementById('__info')._setStyle(_this.warnStyle)._setHtml('Utilisateur ou mot de passe incorrect.');
						}
					}
				});
		};
		this.cancel = function () {
			document.onkeypress = function () {};
			_this.plane._removeElement();
			_this.container._removeElement();
		}
		document.onkeypress = function (e) {
			var k = window.event ? e.keyCode : e.which;
			if (k == 13)
				_this.send();
		};
	};
var 	showImage = function (container) {
		if (!container)
			return false;
		this.imageArray = [];
		this.container = typeof container == 'string' ? document._getById(container) : container;
		if (!this.container)
			return false;
		this.pic = this.container._getByTagName('img');
		this.setAction();
	};
	showImage.prototype.setAction = function () {
		var im = this.pic,
		_this = this;
		im._each(function (img) {
				if (img.className.match('inserted_image') || img.className.match('galery_image')) {
					img['target'] = img.getAttribute('src').replace('http://www.alpineaviatorcompany.com/', '').replace('http://alpineaviatorcompany.com/', '').replace('http://alpineaviatorcompany.as-o.ch/', '').replace(/mini_/, '');
					_this.imageArray.push(img);
					img._addEvent('mousedown', function () {
							var _self = window._browser().isIE ? event.srcElement : this;
							_this.createImageWrapper();
							_this.setCurrent(_self);
							_this.getImageSize(_self.target);
						});
				}
				if (img.className.match('inserted_video')) {
					var vEl = new _element('div')._setStyle({
						'display' : 'inline'
					})._setHtml(img.getAttribute('rel'))._appendBefore(img);
					img._setStyle({
						'display' : 'none'
					});
				}
			});
	};
	showImage.prototype.setCurrent = function (current) {
		for (var i = 0; i < this.imageArray.length; i++)
			if (this.imageArray[i] == current)
				this.current = i;
	};
	showImage.prototype.createImageWrapper = function () {
		var _this = this;
		this.plane = new _element('div')._setAttributes({
					'title' : 'click to close'
				})._setClass('popImageBackgroundPlane')._addEvent('mousedown', function () {
					_this.removeImage();
				})._appendTo(document.body);
		this.wrapper = new _element('div')._setClass('popImageImageWrapper')._appendTo(document.body);
		this.loader = new _element('div')._setAttributes({
					'id' : '__ajax_loader'
				})._setClass('popImageLoader')._appendTo(document.body);
		if (window._browser().isIE6) {
			var stl = {
				'top' : (document.documentElement.scrollTop + (Math.round(window._getWindowSize().y / 2))) + 'px'
			};
			this.wrapper._setStyle(stl);
			this.loader._setStyle(stl);
		}
		if (window._browser().isIE) {
			this.plane._setStyle({
					'opacity' : '0.5'
				});
		}
	};
	showImage.prototype.getImageSize = function (file) {
		_this = this;
		new _request.get({
				'file' : '__php/xhr.getimagesize.php',
				'param' : '?file=' + file,
				'onSend' : function () {},
				'onReceive' : function () {
					_this.setImage(_jsonParse(this.responseText), file);
				}
			});
	};
	showImage.prototype.resizeToWindow = function (size) {
		var ws = window._getWindowSize(), w = parseInt(size.width), h = parseInt(size.height), h1, r1, w1;
		if (parseInt(h) > parseInt(ws.y)) {
			h1 = parseInt(ws.y);
			r1 = h / parseInt(ws.y);
			w1 = Math.round(w / r1);
			if (w1 > parseInt(ws.x)) {
				w1 = ws.x;
				r1 = w1 / parseInt(ws.x);
				h1 = Math.round(h1 / r1);
			}
		}
		if (parseInt(w) > parseInt(ws.x)) {
			w1 = w1 ? w1 : parseInt(ws.x);
			r1 = w / parseInt(ws.x);
			h1 = Math.round(h / r1);
			if (h1 > parseInt(ws.y)) {
				h1 = ws.y;
				r1 = h1 / parseInt(ws.y);
				w1 = Math.round(w1 / r1);
			}
		}
		return {
			'height' : (h1 ? h1 - 50 : h),
			'width' : (w1 ? w1 - 50 : w)
		};
	};
	showImage.prototype.setImage = function (rsize, image) {
		var _this = this,
		el = this.wrapper,
		size = this.resizeToWindow({
					'width' : rsize['width'],
					'height' : rsize['height']
				}),
		marginLeft = parseInt(el._getStyle('margin-left')),
		marginTop = parseInt(el._getStyle('margin-top')),
		newMarginLeft = '-' + Math.floor(size.width / 2),
		newMarginTop = '-' + Math.floor(size.height / 2),
		transH = new _basicFx.transition.sineInOut(this.wrapper, {
					onComplete : function () {
						_this.img = new _element('img')._setAttributes({
									'title' : 'click to close'
								})._setClass('popImage')._setStyle({
									'display' : 'none',
									'width' : size.width + 'px',
									'height' : size.height + 'px'
								})._setAttributes({
									'src' : image
								})._addEvent('mousedown', function () {
									_this.removeImage();
								})._appendTo(el);
						if (rsize.legend) {
							var legend = new _element('div')._setAttributes({
										'id' : '__image_legend'
									})._setClass('popImageLegend')._setHtml(rsize.legend)._appendTo(el);
							var closeLegend = new _element('div')._setAttributes({
										'title' : 'hide legend'
									})._setHtml('x')._setClass('popImageLegendClose')._addEvent('mousedown', function () {
										legend._removeElement();
									})._appendTo(legend);
						}
						_this.isLoaded(_this.img);
					}
				}),
		transW = new _basicFx.transition.sineInOut(this.wrapper, {
					onComplete : function () {
						transH.start(['height', el.offsetHeight, size.height], ['margin-top', marginTop, newMarginTop]);
					}
				});
		transW.start(['width', el.offsetWidth, size.width], ['margin-left', marginLeft, newMarginLeft]);
	};
	showImage.prototype.setNavigButton = function () {
		if (this.imageArray.length < 2)
			return false;
		var _this = this;
		this.next = new _element('div')._setAttributes({
					'title' : 'next'
				})._setClass('popImageNavigButton')._setStyle({
					'right' : '5px'
				})._setHtml('&raquo;')._addEvent('click', function () {
					_this.nextImage();
				})._appendTo(this.wrapper);
		this.previous = new _element('div')._setAttributes({
					'title' : 'previous'
				})._setClass('popImageNavigButton')._setStyle({
					'left' : '5px'
				})._setHtml('&laquo;')._addEvent('click', function () {
					_this.previousImage();
				})._appendTo(this.wrapper);
	};
	showImage.prototype.isLoaded = function (image) {
		var trans = new _basicFx.transition(image);
		if (image.complete) {
			image._setStyle({
					'display' : '',
					'opacity' : '0'
				});
			document._getById('__ajax_loader')._setStyle({
					'display' : 'none'
				});
			trans.start(['opacity', 0, 100]);
			_this.setNavigButton();
		} else {
			image.onload = function () {
				document._getById('__ajax_loader')._setStyle({
						'display' : 'none'
					});
				image._setStyle({
						'display' : '',
						'opacity' : '0'
					});
				trans.start(['opacity', 0, 100]);
				_this.setNavigButton();
			}
		}
	};
	showImage.prototype.nextImage = function () {
		var prv = this.imageArray[this.current + 1] ? this.current + 1 : 0;
		this.navigButtonAction(prv);
	};
	showImage.prototype.previousImage = function () {
		var prv = this.imageArray[this.current - 1] ? this.current - 1 : this.imageArray.length - 1;
		this.navigButtonAction(prv);
	};
	showImage.prototype.navigButtonAction = function (i) {
		this.current = i;
		this.img._removeElement();
		this.next._removeElement();
		this.previous._removeElement();
		if (document.getElementById('__image_legend'))
			document.getElementById('__image_legend')._removeElement();
		this.getImageSize(_this.imageArray[i].target);
		document._getById('__ajax_loader')._setStyle({
				'display' : ''
			});
	};
	showImage.prototype.removeImage = function () {
		this.plane._removeElement();
		this.wrapper._removeElement();
		this.loader._removeElement();
	};
	
var 	homeImageSwap = function () {
		if (!document._getById('home')) return false;
		this.tableContainer = document._getById('homeTopImages');
		this.divImageWrapper = this.tableContainer._getByTagName('div');
		this.imageArray = [
			["image/home_banner/home_animation/aviacare/aviacare_01.jpg", 
			 "image/home_banner/home_animation/aviacare/aviacare_02.jpg", 
			 "image/home_banner/home_animation/aviacare/aviacare_03.jpg"],
			["image/home_banner/home_animation/airshow/warbirds_airshow.jpg",
			 "image/home_banner/home_animation/airshow/airshow_01.jpg", 
			 "image/home_banner/home_animation/airshow/airshow_02.jpg", 
			 "image/home_banner/home_animation/airshow/airshow_03.jpg", 
			 "image/home_banner/home_animation/airshow/airshow_04.jpg",
			 "image/home_banner/home_animation/airshow/l39za_small.jpg"],
			["image/home_banner/home_animation/flight/flight_01.jpg", 
			 "image/home_banner/home_animation/flight/flight_02.jpg", 
			 "image/home_banner/home_animation/flight/flight_03.jpg"]
		];
		this.divImageWrapper._each(function (div,i) {
			new swapper(div,this.imageArray[i],i);
		});
	};
var 	swapper = function (container,imageArray,num) {
		var _this = this;
		this.container = container;
		//this.parentContainer = container.parentNode._setStyle({'overflow':'hidden'});
		this.imgArray = [];
		this.timer = 1250;
		this.temp = 2000;
		for(var i = 0; i<imageArray.length; i++) {
			this.imgArray.push(
				new _element('img')
				._setStyle({'position':'absolute','opacity':'0'})
				._setAttributes({'src':imageArray[i]})
				._appendTo(container)
			);
		}
		var waiter = function () { return _this.transition() };
		setTimeout(waiter, (num + 1) * this.timer)
	};
	swapper.prototype.transition = function () {
		var _this = this;
		this.start = function (num) {
			if (num == this.imgArray.length) {
				new _basicFx.transition(this.imgArray[num-1], {
					duration : 5000,
					onComplete : function () {
						var f = function () { _this.start(0); }, t = function () { return f(); };
						setTimeout(t, _this.temp);
					}
				}).start(['opacity', 100, 0]);
			} else {
				new _basicFx.transition(this.imgArray[num], {
					duration : 5000,
					onComplete : function () {
						var f = function () { _this.start(num + 1); }, t = function () { return f(); };
						setTimeout(t, _this.temp);
						if (_this.imgArray[num-1]) {
							_this.imgArray[num-1]._setStyle({'opacity':'0'});
						}
					}
				}).start(['opacity', 0, 100]);
			}
		};
		this.start(0);
	};
	
	
