registerThumb = function(element, vehicleimageid, thumb_url){
	if(element.readAttribute('onMouseOver') != null){
		try{
			element.domRA('onMouseOver');
			element.onmouseover = function(){ };
		}catch(e){ };
		new Thumb(element, vehicleimageid, thumb_url);
	};
};

Thumb = Class.create();
Object.extend(Thumb.prototype, {
	initialize: function(element, vehicleimageid, thumb_url){

		this.element = element;
		this.vehicleimageid = vehicleimageid;
		this.thumb_url = thumb_url;
		this.focus = true;

		//new VehicleImage(this.element, this.vehicleimageid);

		this.eventMouseOver  = this.over.bindAsEventListener(this);
		Event.observe(this.element, "mouseover", this.eventMouseOver);
		this.eventMouseOut   = this.out.bindAsEventListener(this);
		Event.observe(this.element, "mouseout", this.eventMouseOut);

		this.tooltip = new Tooltip();
		this.tooltip.initTooltip();
		this.tooltip.registerTooltipElement(this.element);
		this.element.setStyle('cursor:help;');

		this.tooltip.registerTooltipTitle(
			domCE('div').domAC(
				domCE('h3').setStyle({width: '235px' }).domSA({
					className: 'tooltiptitle'
				}).domCTN(lang('Vehicle Photo', 'Photo de véhicules'))
			)
		);

		this.tooltip.registerTooltipBody(
			domCE('div').domAC(
				domCE('p').setStyle({width: '235px'}).domSA({
					className: 'tooltipbody'
				}).domAC(
					domCE('div').domSA({
						align: 'center'
					}).domAC(
						domCE('img').domSA({
							src: this.thumb_url
						})
					)
				).domAC(
					domCE('div').domSA({
						align: 'center'
					}).domAC(
						domCE('p').setStyle({
							color: '#ff0000',
							fontStyle: 'italic'
						}).domCTN(lang('Click to zoom', 'Cliquez pour agrandir'))
					)
				)
			)
		);

		if(this.focus) this.tooltip.showTooltip();

		Event.stopObserving(this.element, "mouseover", this.eventMouseOver);
		Event.stopObserving(this.element, "mouseout", this.eventMouseOut);
	},

	over: function(event){
		this.focus = true;
	},

	out: function(event){
		this.focus = false;
	}

});

var onImageEvent = new YAHOO.util.CustomEvent("Image");
VehicleImage = Class.create();
Object.extend(VehicleImage.prototype, {
	initialize: function(vehicleid, vehicleimageid, imageid){
		this.vehicleid = vehicleid;
		this.vehicleimageid = vehicleimageid;
		this.imageid = imageid;
		this.rendered = false;

		this.elementBody = domCE('div');
		this.loaded = false;

		onImageEvent.subscribe(this.eventDispatch, this, true);
		this.eventOverlay  = this.showOverlay.bindAsEventListener(this);
	},

	eventDispatch: function(type, args){
		switch(args[0]){
			case 'registerButton':
				if(args[2] == this.vehicleimageid) this.registerButton(args[1]);
		};
	},

	registerButton: function(element){
		try{
			element.domRA('onMouseOver');
			element.onmouseover = function(){ };
		}catch(e){ };
		Event.observe(element, "mousedown", this.eventOverlay);
	},

	renderOverlay: function(event){
		if(this.rendered) return;

		this.width = 360;
		this.height = 120;

		this.elementThumb = new Image(this.width, this.height);
		this.elementThumb.src = '/images/spacer.gif';

		this.elementImage = new Image(this.width, this.height);

		this.elementOverlay = domCE('div').domSA({
			className: 'vehicleimage'
		}).domAC(
			this.elementHeader = domCE('div').domSA({
				className: 'header'
			})
		).domAC(
			this.elementBody.setStyle({
				position:'relative'
			}).domSA({
				className: 'body'
			}).domAC(
				this.elementLoaderContainer = domCE('div').domSA({
					align: 'center'
				}).setStyle({
					position: 'absolute',
					top: ((this.height - 48) / 2)+'px',
					left: ((this.width - 208) / 2)+'px',
					display: ((this.loaded) ? 'none' : '')
				}).domAC(
					domCE('span').domCTN(lang('Loading vehicle photo...', 'Chargement des photos du véhicule...'))
				).domAC(
					domCE('br')
				).domAC(
					domCE('br')
				).domAC(
					this.elementLoader = domCE('img').domSA({
						src: '/images/overlayloading.gif'
					})
				)
			).domAC(
				this.elementBackdrop = domCE('div').setStyle({
					backgroundColor: '#000000',
					position: 'absolute',
					top: '0px',
					left: '0px'
				}).domSA({
					height: this.height,
					width: this.width
				})
			).domAC(
				this.elementThumbContainer = domCE('div').setStyle({
					display: ((this.loaded) ? 'none' : '')
				}).domAC(
					this.elementThumb
				)
			)
		).domAC(
			this.elementFooter = domCE('div').domSA({
				className: 'footer'
			})
		);
		this.overlay = new Overlay();
		this.overlay.registerOverlay(this.elementOverlay);
		this.overlay.showOverlay();
		this.loadXML();
		this.rendered = true;
	},

	loadXML: function(){
		this.ajax = new Ajax();
		this.ajax.url = XMLVehicleImage+'?vehicleid='+this.vehicleid+'&vehicleimageid='+this.vehicleimageid;
		this.ajax.caching = true;
		this.ajax.timeout = 10000;
		this.ajax.handleXMLFailure = function(){
			this.loadXML();
		}.bind(this);
		this.ajax.requestXML(function(response){
			this.XML = response.responseJSON.vehicleimages.vehicleimage;

			if((this.XML['-ratio'] * 100) > 100){
				//landscape
				this.elementImageAnim = new YAHOO.util.Anim(this.elementImage, {
					width: { to: 800 }
				}, .10, YAHOO.util.Easing.easeIn);
				this.elementImageAnim2 = new YAHOO.util.Anim(this.elementImage, {
					height: { to: Math.round(800 / this.XML['-ratio']) }
				}, .10, YAHOO.util.Easing.easeIn);
				this.elementImageAnim.onComplete.subscribe(function(){
					this.elementImageAnim2.animate();
				}.bind(this));
			}else{
				//portrait
				this.elementImageAnim = new YAHOO.util.Anim(this.elementImage, {
					width: { to: Math.round(800 * this.XML['-ratio']) }
				}, .10, YAHOO.util.Easing.easeIn);
				this.elementImageAnim2 = new YAHOO.util.Anim(this.elementImage, {
					height: { to: 800 }
				}, .10, YAHOO.util.Easing.easeIn);
				this.elementImageAnim.onComplete.subscribe(function(){
					this.elementImageAnim2.animate();
				}.bind(this));
			};
			this.elementImageAnim3 = new YAHOO.util.Anim(this.elementImage, {
				opacity: { to: 1 }
			}, .10, YAHOO.util.Easing.easeNone);
			this.elementImageAnim2.onComplete.subscribe(function(){
				this.elementImageAnim3.animate();
			}.bind(this));

			this.elementImageAnim.onTween.subscribe(function(){ this.overlay.positionOverlay(); }.bind(this));
			this.elementImageAnim2.onTween.subscribe(function(){ this.overlay.positionOverlay(); }.bind(this));

			this.eventOnloadImage  = this.onloadImage.bindAsEventListener(this);
			Event.observe(this.elementImage, "load", this.eventOnloadImage);

			this.elementImage.src = this.XML['-image_url'];

		}.bind(this));
	},

	onloadImage: function(event){
		this.loaded = true;
		this.elementBody.domRCN();
		this.elementBody.domAC(
			this.elementImage.setStyle({
				opacity: 0
			})
		).domAC(
			this.elementClose = domCE('img').domSA({
				src: '/images/overlayclose.gif'
			}).setStyle({
				position: 'absolute',
				top: '-5px',
				right: ((navigator.appVersion.indexOf('MSIE 6') > 0) ? '0px' : '-5px')
			})
		);

		this.elementImageAnim.animate();
		if((this.XML['-ratio'] * 100) > 100){
			//landscape
			this.width = 800;
			this.height =Math.round(this.width / this.XML['-ratio']);
		}else{
			//portrait
			this.height = 800;
			this.width =Math.round(this.height * this.XML['-ratio']);
		};

		this.eventClose  = this.hideOverlay.bindAsEventListener(this);
		Event.observe(this.elementClose, "mousedown", this.eventClose);

		if(typeof this.XML.vehiclewires != 'undefined'){
			this.XML.vehiclewires.vehiclewire = (typeof this.XML.vehiclewires.vehiclewire.length == 'undefined')
				? [this.XML.vehiclewires.vehiclewire]
				: this.XML.vehiclewires.vehiclewire;
			this.elementPins = new Array();
			this.XML.vehiclewires.vehiclewire.each(function(vehiclewire, index){
				this.elementBody.domAC(
					this.elementPins[this.elementPins.length] = domCE('div').setStyle({
						backgroundImage: 'url(/images/spacer.gif)',
						position: 'absolute',
						top: Math.round(this.height * vehiclewire['-y'])-37+'px',
						left: Math.round(this.width * vehiclewire['-x'])+'px',
						height: '26px',
						width: '26px'
					})
				);

				this.tooltip = new Tooltip();
				this.tooltip.initTooltip();
				this.tooltip.registerTooltipElement(this.elementPins[this.elementPins.length-1]);
				this.tooltip.registerTooltipTitle(
					domCE('div').domAC(
						domCE('h4').setStyle({width: '235px' }).domSA({
							className: 'tooltiptitle'
						}).domAC(
							domCE('p').domCHTN(
								vehiclewire.polarity
							).domAC(
								domCTN(lang(vehiclewire.name_en, vehiclewire.name_fr))
							)
						)
					)
				);
				this.tooltip.registerTooltipBody(
					domCE('div').domAC(
						elementTooltipBody = domCE('p').setStyle({width: '235px'}).domSA({
							className: 'tooltipbody'
						}).domAC(
							domCE('p').domAC(
								domCE('strong').domCTN(lang('Color: ', 'Couleur: '))
							).domAC(
								domCTN(lang(vehiclewire.color_en, vehiclewire.color_fr))
							)
						)
					)
				);

				if(
					typeof vehiclewire.location_en != 'undefined'
					|| typeof vehiclewire.location_fr != 'undefined'
				){
					elementTooltipBody.domAC(
						domCE('p').domAC(
							domCE('strong').domCTN(lang('Location: ', 'Lieu: '))
						).domAC(
							eleLocation = domCE('span')
						)
					);
					if(Language == 'en'){
						if(typeof vehiclewire.location_en != 'undefined'){
							eleLocation.domCTN(vehiclewire.location_en);
						}else if(typeof vehiclewire.location_fr != 'undefined'){
							eleLocation.domCTN(vehiclewire.location_fr);
							onTranslateEvent.fire(eleLocation, 'fr', 'en');
						};
					};
					if(Language == 'fr'){
						if(typeof vehiclewire.location_fr != 'undefined'){
							eleLocation.domCTN(vehiclewire.location_fr);
						}else if(typeof vehiclewire.location_en != 'undefined'){
							eleLocation.domCTN(vehiclewire.location_en);
							onTranslateEvent.fire(eleLocation, 'en', 'fr');
						};
					};
				};

				if(
					typeof vehiclewire.notes_en != 'undefined'
					|| typeof vehiclewire.notes_fr != 'undefined'
				){
					elementTooltipBody.domAC(
						domCE('p').domAC(
							domCE('strong').domCTN(lang('Location: ', 'Lieu: '))
						).domAC(
							eleNotes = domCE('span')
						)
					);
					if(Language == 'en'){
						if(typeof vehiclewire.notes_en != 'undefined'){
							eleNotes.domCTN(vehiclewire.notes_en);
						}else if(typeof vehiclewire.notes_fr != 'undefined'){
							eleNotes.domCTN(vehiclewire.notes_fr);
							onTranslateEvent.fire(eleNotes, 'fr', 'en');
						};
					};
					if(Language == 'fr'){
						if(typeof vehiclewire.notes_fr != 'undefined'){
							eleNotes.domCTN(vehiclewire.notes_fr);
						}else if(typeof vehiclewire.notes_en != 'undefined'){
							eleNotes.domCTN(vehiclewire.notes_en);
							onTranslateEvent.fire(eleNotes, 'en', 'fr');
						};
					};
				};
			}.bind(this));
		};

	},

	showOverlay: function(event){
		//if(!swfobject.hasFlashPlayerVersion("10.1.0")){
			if(!this.rendered){
				this.renderOverlay();
			}else{
				this.overlay.showOverlay();
				//this.overlay.positionOverlay();
			};
		//};
		onImageEvent.fire('selectImage', this.imageid, this.vehicleimageid);
	},

	animExpand: function(){

	},

	hideOverlay: function(event){
		if(!this.rendered) return;
		this.overlay.hideOverlay();
	},

	animCollapse: function(){

	}
});

var onPrintEvent = new YAHOO.util.CustomEvent("Print");
PrintWiring = Class.create();
Object.extend(PrintWiring.prototype, {
	initialize: function(elementPalette, elementWiring, imageData){
		this.elementPalette = elementPalette;
		this.elementWiring = elementWiring;
		this.imageData = imageData;
		this.rendered = false;
		this.miniimage = new Array();
		this.checkboximage = new Array();
		this.images = new Array();
		this.elementBody = domCE('div');

		this.progressbar = new ProgressBar({
			title: lang('Loading Images', 'Chargement des images'),
			autohide:false,
			autodestroy:false,
			oncancel:function(){
				clearTimeout(this.timerCheckCache);
				this.progressbar.hide();
			}.bind(this),
			oncomplete:function(){ }.bind(this)
		});

		this.eventOverlay  = this.showOverlay.bindAsEventListener(this);
		onPrintEvent.subscribe(this.eventDispatch, this, true);

		$('htmlbody').domAC(
			domCE('div').domSA({
				id: 'qrcode'
			}).domAC(
				domCE('img').domSA({
					src: 'http://chart.apis.google.com/chart?chs=100x100&cht=qr&chld=M|1&chl='+window.location.toString()
				})
			)
		);
	},

	eventDispatch: function(type, args){
		switch(args[0]){
			case 'registerButton':
				this.registerButton(args[1]);
		};
	},

	registerButton: function(element){
		try{
			element.domRA('onMouseOver');
			element.onmouseover = function(){ };
		}catch(e){ };
		Event.observe(element, "mousedown", this.eventOverlay);
	},

	renderOverlay: function(event){
		this.elementOverlay = domCE('div').setStyle({
			position: 'relative'
		}).domSA({
			className: 'printoptions'
		}).domAC(
			this.elementClose = domCE('img').setStyle({
				position: 'absolute',
				left: '502px',
				top: '-8px',
				cursor: 'pointer',
				zIndex: 5
			}).domSA({
				src: ((pngBug) ? '/images/overlay_close.gif' : '/images/overlay_close.png'),
				height: '46px',
				width: '40px'
			})
		).domAC(
			this.elementHeader = domCE('div').domSA({
				className: 'head'
			}).domAC(
				domCE('h1').domCTN(lang('Print Options', 'Options d\'impression'))
			)
		).domAC(
			this.elementBody.domSA({
				className: 'body'
			}).domAC(
				domCE('table').domSA({
					border: '0',
					cellSpacing: '0',
					cellPadding: '0'
				}).domAC(
					domCE('tbody').domAC(

						domCE('tr').domAC(
							domCE('td').domSA({
								className: 'colA'
							}).domAC(
								domCE('h2').domCTN(lang('Wiring', 'Câblage'))
							)
						).domAC(
							domCE('td').domSA({
								className: 'colB'
							}).domAC(
								domCE('h2').domCTN(lang('Select Photographs', 'Sélectionnez Photographies'))
							)
						)
					).domAC(
						domCE('tr').domAC(
							this.elementColA = domCE('td').domSA({
								className: 'colA',
								vAlign: 'top'
							}).domAC(
								domCE('img').domSA({
									src: '/images/icons/tabledata.png'
								})
							).domAC(
								domCE('br')
							).domAC(
								this.checkboxdata = domCE('input', 'checkbox').domSA({
									defaultChecked: true,
									checked: true,
									value: '1'
								})
							)
						).domAC(
							this.elementColB = domCE('td').domSA({
								className: 'colB',
								vAlign: 'top'
							}).domAC(
								this.elementImages = domCE('div').domSA({
									className: 'miniimages'
								})
							)
						)
					)
				)
			).domAC(
				domCE('div').domSA({
					className: 'buttons'
				}).domAC(
					this.buttonCancel = domCE('button').domCTN(lang('Cancel', 'Annuler'))
				).domAC(
					this.buttonPrint = domCE('button').domCTN(lang('Print Selected Items', 'Imprimer les éléments sélectionnés'))
				)
			)
		).domAC(
			this.elementFooter = domCE('div').domSA({
				className: 'foot'
			}).domAC(
				domCE('img').domSA({
					src: '/images/spacer.gif',
					width: '10px',
					height: '10px'
				})
			).domCTN(String.nbsp)
		);

		this.eventClose  = this.hideOverlay.bindAsEventListener(this);
		Event.observe(this.elementClose, "mousedown", this.eventClose);

		this.eventCancel  = this.hideOverlay.bindAsEventListener(this);
		Event.observe(this.buttonCancel, "mousedown", this.eventCancel);

		this.eventPrint  = this.print.bindAsEventListener(this);
		Event.observe(this.buttonPrint, "mousedown", this.eventPrint);

		if(this.imageData.length <= 1){
			//no images
			this.elementImages.domRCN();
			this.elementImages.domAC(
				domCE('p').domAC(
					domCE('em').domCTN(lang('There are currently no photos available.', 'Il n\'y a aucune photo disponible.'))
				)
			)
		}else{
			//has images
			this.elementImages.domRCN();
			this.elementImages.domAC(
				this.imageButtons = domCE('p').domAC(
					this.buttonSelectPinned = domCE('a').domSA({
						href: 'javascript:void(0);'
					}).domCTN(lang('Pinned Photos', 'Les photos épinglées'))
				).domAC(
					domCTN(String.nbsp+String.nbsp+'|'+String.nbsp+String.nbsp)
				).domAC(
					this.buttonSelectAll = domCE('a').domSA({
						href: 'javascript:void(0);'
					}).domCTN(lang('All Photos', 'Toutes les photos'))
				).domAC(
					domCTN(String.nbsp+String.nbsp+'|'+String.nbsp+String.nbsp)
				).domAC(
					this.buttonSelectNone = domCE('a').domSA({
						href: 'javascript:void(0);'
					}).domCTN(lang('None', 'Aucun'))
				)
			);

			this.eventSelectPinned  = this.selectPinned.bindAsEventListener(this);
			Event.observe(this.buttonSelectPinned, "mousedown", this.eventSelectPinned);

			this.eventSelectAll  = this.selectAll.bindAsEventListener(this);
			Event.observe(this.buttonSelectAll, "mousedown", this.eventSelectAll);

			this.eventSelectNone  = this.selectNone.bindAsEventListener(this);
			Event.observe(this.buttonSelectNone, "mousedown", this.eventSelectNone);

			this.imageData.each(function(image, index){

				//image = this.imageData[i];
				if(index == 0) return;
				this.images[this.images.length] = new PrintImage(image, index);
				if(image.wires > 0){
					this.images[this.images.length-1].enableImage();
				}else{
					this.images[this.images.length-1].disableImage();
				};
				this.elementImages.domAC(this.images[this.images.length-1].elementInput);

			}.bind(this));
		}

		this.overlay = new Overlay({ width:550 });
		this.overlay.registerOverlay(this.elementOverlay);
		this.overlay.showOverlay();
		this.rendered = true;
	},

	showOverlay: function(event){
		try{ if(event && typeof(Event.stop) == 'function') Event.stop(event); }catch(e){};
		if(!this.rendered){
			this.renderOverlay();
		}else{
			this.overlay.showOverlay();
		};
	},

	hideOverlay: function(event){
		if(!this.rendered) return;
		this.buttonPrint.domRCN();
		this.buttonPrint.domAC( domCTN(lang('Print Selected Items', 'Imprimer les éléments sélectionnés')) ).enable();
		clearTimeout(this.timerCheckCache);
		this.overlay.hideOverlay();
	},

	selectPinned: function(event){
		if(this.imageData.length > 1){
			this.images.each(function(image, index){
				if(image.data.wires > 0){
					image.enableImage(event);
				}else{
					image.disableImage(event);
				};
			});
		};
	},

	selectAll: function(event){
		if(this.imageData.length > 1){
			this.images.each(function(image){
				image.enableImage();
			});
		};
	},

	selectNone: function(event){
		if(this.imageData.length > 1){
			this.images.each(function(image){
				image.disableImage();
			});
		};
	},

	print: function(event){
		this.elementPalette.domRCN();
		this.hideOverlay();

		if(typeof permissions.staff == 'undefined' || permissions.staff == false){
			this.elementPalette.domAC(
				this.elementUser = domCE('div').domSA({
					className: 'print_user'
				}).domAC(
					domCE('p').domCTN(lang('The following information is protected by international copyright laws.', 'Les informations suivantes sont protégées par les lois internationales sur le copyright.'))
				).domAC(
					domCE('p').domCTN(lang('Personal use is authorized for:', 'L\'utilisation personnelle est autorisée pour:'))
				).domAC(
					domCE('p').domSA({ className: 'indent' }).domAC(
						domCE('strong').domCTN(session.user.firstname+' '+session.user.lastname+' <'+session.user.email+'>')
					)
				)
			);
			if(session.user.businessname != ''){
				this.elementUser.domAC(
					domCE('p').domSA({ className: 'indent' }).domAC(
						domCE('strong').domCTN(session.user.businessname)
					)
				)
			};

			this.elementUser.domAC(
				domCE('p').domCTN(lang('If you are not authorized to view this document please forward a copy to', 'Si vous n\'êtes pas autorisé à consulter ce document s\'il vous plaît faire parvenir une copie à')+' <abuse@wirecolor.com>')
			);
		};

		if(this.checkboxdata.checked){
			this.elementPalette.domAC(this.elementWiring.cloneNode(true).removeClassName('noprint').show());
		};
		if(this.imageData.length > 1){
			this.elementPalette.domAC(
				domCE('br')
			);
			this.printableImage = new Array();
			var total = 0;
			this.images.each(function(image, index){
				if(image.selected){
					total++;
					image.loadImage(this.elementPalette);
				};
			}.bind(this));
			if(total > 0){
				this.progressbar.show();
				this.progressbar.set(lang('Loading Images', 'Chargement des images'), 0);
			};
			this.timerCheckCache = setTimeout(function(){ this.checkCache(); }.bind(this), 25);
		}else{
			setTimeout(function(){
				window.print()
			}, 500);
		};
	},

	checkCache: function(){
		var total = 0;
		var waiting = 0;
		this.images.each(function(image, index){
			if(image.selected){
				total++;
				if(image.loaded == false) waiting++;
			};
		}.bind(this));
		if(waiting > 0){
			if(waiting == total){
				this.progressbar.set(lang('Loading Images', 'Chargement des images'), 0);
			}else{
				this.progressbar.set(lang('Loading Images', 'Chargement des images')+' '+(total - waiting)+lang(' of ', ' de ')+total, ((total - waiting) * 100 / total));
			};
			this.timerCheckCache = setTimeout(function(){ this.checkCache(); }.bind(this), 25);
			return false;
		};
		if(total > 0){
			this.progressbar.set(lang('Loaded Images ', 'Les images chargées ')+total+lang(' of ', ' sur ')+total, 100);
		};
		setTimeout(function(){
			this.progressbar.hide();
			window.print()
		}.bind(this), 500);

	}

});

PrintImage = Class.create();
Object.extend(PrintImage.prototype, {
	initialize: function(data, index){
		this.data = data;
		this.index = index;
		this.selected = false;
		this.loaded = false;
		this.renderElements();
	},

	renderElements: function(){
		this.thumb = domCE('img').domSA({
			className: 'thumb',
			src: this.data.thumb,
			width: '75',
			alt: ''
		});
		this.checkbox = domCE('input', 'checkbox').domSA({
			className: 'checkbox',
			value: this.index
		});

		this.eventClickCheckbox  = this.clickCheckbox.bindAsEventListener(this);
		Event.observe(this.checkbox, "mouseup", this.eventClickCheckbox);

		onImageEvent.fire('registerButton', this.thumb, this.data.id);

		//this.image = new VehicleImage(this.thumb, this.data.id);
		this.elementInput = domCE('div').domSA({
			className: 'miniimage layout'
		}).domAC(
			this.thumb
		).domAC(
			this.checkbox
		)
	},

	clickCheckbox: function(event){
		try{ if(event && typeof(Event.stop) == 'function') Event.stop(event); }catch(e){};
		if(this.checkbox.checked){
			this.disableImage(event, false);
		}else{
			this.enableImage(event, false);
		};
	},

	enableImage: function(event, checkbox){
		checkbox = (typeof checkbox == 'undefined') ? true : checkbox;
		this.thumb.removeClassName('subtle');
		if(checkbox){
			this.checkbox.domSA({
				defaultChecked: true,
				checked: 'checked'
			});
		};
		this.selected = true;
	},

	disableImage: function(event, checkbox){
		checkbox = (typeof checkbox == 'undefined') ? true : checkbox;
		this.thumb.addClassName('subtle');
		if(checkbox){
			this.checkbox.domSA({
				defaultChecked: false,
				checked: ''
			});
			this.checkbox.domRA('checked');
			this.checkbox.domRA('defaultChecked');
		};
		this.selected = false;
	},

	loadImage: function(element){
		this.image = new Image();

		this.eventOnloadImage  = this.onloadImage.bindAsEventListener(this);
		Event.observe(this.image, "load", this.eventOnloadImage);

		element.domAC(
			domCE('div').setStyle({
				margin: '10px 0px 0px 0px'
			}).domSA({
				className: ((this.data.width > this.data.height) ? 'landscape' : 'portrait'),
				align: 'center',
				width: '100%'
			}).domAC(
				this.image
			)
		);
		this.image.src = this.data.imagedesc;
	},

	onloadImage: function(event){
		this.loaded = true;
	}

});

LoginForm = Class.create();
Object.extend(LoginForm.prototype, {
	initialize: function(elementForm, elementButton){
		this.elementForm = elementForm;
		this.elementButton = elementButton;
		this.elementButton.disable();
		this.emailRegExp = /^([a-z0-9]+)([a-z0-9_\-\.\+]*)([a-z0-9]+)@([a-z0-9]+)([a-z0-9_\-\.]*)(\.[a-z]{2,4}(\.[a-z]{2}){0,2})$/i;
		this.errors = 0;

		this.eventCheckForm  = this.checkForm.bindAsEventListener(this);
		Event.observe(this.elementForm.email, "keyup", this.eventCheckForm);
		Event.observe(this.elementForm.password, "keyup", this.eventCheckForm);

		this.eventSubmitForm  = this.submitForm.bindAsEventListener(this);
		Event.observe(this.elementButton, "mousedown", this.eventSubmitForm);

		this.checkForm();
	},

	checkEmail: function(event){
		return (this.emailRegExp.test(this.elementForm.email.value));
	},

	checkPassword: function(event){
		return (this.elementForm.password.value.length >= 6);
	},

	checkForm: function(event){
		this.elementButton.disable();
		if(!this.checkEmail()) return false;
		if(!this.checkPassword()) return false;
		this.elementButton.enable();
		if(event.keyCode == Event.KEY_RETURN) this.submitForm(event);
		return true;
	},

	submitForm: function(){
		this.elementButton.disable();
		this.elementButton.domRCN();
		this.elementButton.domAC(
			domCTN(lang('Please wait...', 'Patientez s.v.p...'))
		);

		this.errors = 0;

		this.ajax = new HttpPost();
		this.ajax.requestXML(function(response){
			var XML = response.responseJSON.httppost;
			Object.keys(XML).each(function(key){
				if(XML[key].error){
					this.errors++;
					$('error.'+key).show();
					$('error.'+key).innerHTML = XML[key].error;
				}
			}.bind(this));
			this.elementButton.enable();
			this.elementButton.domRCN();
			this.elementButton.domAC(
				domCTN('Login')
			);

			if(this.errors > 0){
				return false;
			}else{
				createCookie(COOKIEEmail, XML['email'].value, 365);
				location.replace('./');
			};
		}.bind(this), [], this.elementForm);

		return false;
	}
});

SubscriptionForm = Class.create();
Object.extend(SubscriptionForm.prototype, {
	initialize: function(elementList, vehicleid){
		this.elementList = elementList;
		this.vehicleid = vehicleid;
		this.subscriptionChoices = new Array();

		this.ajaxSubscriptions = new Ajax();
		this.ajaxSubscriptions.url = XMLSubscriptions;
		this.ajaxSubscriptions.requestXML(function(response){
			if(
				response.responseJSON.subscriptions == undefined
				|| response.responseJSON.subscriptions.subscription == undefined
			){
				this.elementList.show();
				return;
			};
			this.elementList.domRCN();
			this.elementList.domAC(
				domCE('table').domSA({
					className: 'choosesubscription',
					cellSpacing: 0,
					cellPadding: 0,
					border: 0
				}).setStyle({
					width: '100%',
					border: '1px solid #f00'
				}).domAC(
					this.elementTable = domCE('tbody')
				)
			);
			var subscriptions = (response.responseJSON.subscriptions.subscription.length == undefined)
				? [response.responseJSON.subscriptions.subscription]
				: response.responseJSON.subscriptions.subscription ;
			if(subscriptions.length == 1){
				this.subscriptionChoices[this.subscriptionChoices.length] = new SubscriptionChoice(this.elementTable, subscriptions[0], this.vehicleid);
			}else{
				subscriptions.sort(function(a,b){
					return (parseInt(a['-tokens_left']) < parseInt(b['-tokens_left'])) ? 1 : -1 ;
				});
				subscriptions.each(function(subscription, index){
					this.subscriptionChoices[this.subscriptionChoices.length] = new SubscriptionChoice(this.elementTable, subscription, this.vehicleid);
				}.bind(this));
			};
			this.elementList.show();
		}.bind(this));
	}
});

SubscriptionChoice = Class.create();
Object.extend(SubscriptionChoice.prototype, {
	initialize: function(elementTable, subscription, vehicleid){
		this.elementTable = elementTable;
		this.subscription = subscription;
		this.vehicleid = vehicleid;

		this.elementTable.domAC(
			this.elementRow = domCE('tr').domSA({
				className: ((this.subscription['-tokens_left'] > 0) ? '' : 'subtle' )
			}).domAC(
				domCE('td').setStyle({
					height: '32px',
					width: '32px'
				}).domAC(
					domCE('img').domSA({
						src: '/images/icons/32x32_subscription_'+subscription['-type']+'.jpg',
						height: '32px',
						width: '32px',
						alt: ''
					})
				)
			).domAC(
				domCE('td').domAC(
					domCE('strong').domCTN(lang(subscription['-name_en'], subscription['-name_fr']))
				).domCHTN( ( (
						typeof lang(subscription['-description_en'], subscription['-description_fr']) != 'undefined'
						&& lang(subscription['-description_en'], subscription['-description_fr']) != ''
					)
					? '<br/>'+lang(subscription['-description_en'], subscription['-description_fr'])
					: ''
					) )
			).domAC(
				domCE('td').domCHTN(subscription['-tokens_left']+' <span class="subtle">/ '+subscription['-tokens']+'</span>')
			).domAC(
				domCE('td').domSA({
					align: 'right'
				}).domAC(
					this.elementButton = domCE('a').domSA({
						className: 'button subtle',
						href: 'javascript:void(0);'
					}).domAC(
						domCE('span').domSA({
							className: 'usetoken'
						}).domCTN(lang('Use Token', 'Utilisez'))
					)
				)
			)
		);

		if(subscription['-tokens_left'] <= 0){
			this.elementButton.hide();
		};

		this.eventExpand  = this.expand.bindAsEventListener(this);
		Event.observe(this.elementRow, "mouseover", this.eventExpand);
		//prevent IE blinking
		Event.observe(this.elementRow, "mousemove", this.eventExpand);

		this.eventCollapse  = this.collapse.bindAsEventListener(this);
		Event.observe(this.elementRow, "mouseout", this.eventCollapse);

		this.eventChoose  = this.choose.bindAsEventListener(this);
		Event.observe(this.elementButton, "mousedown", this.eventChoose);

	},

	expand: function(event){
		this.elementButton.removeClassName('subtle');
	},

	collapse: function(event){
		this.elementButton.addClassName('subtle');
	},

	choose: function(event){
		$(this.elementButton.firstChild).addClassName('wait');
		this.httppost = new HttpPost();
		this.httppost.requestXML(function(response){
			var XML = response.responseJSON.httppost;
			if(response.responseJSON.httppost['-errors'] == 0){
				//success
				location.reload(true);
			}else{
				//failed
				Object.keys(XML).each(function(key){
					if(XML[key].error){
						location.reload(true);
					}
				}.bind(this));
				$(this.elementButton.firstChild).removeClassName('wait');
			};
		}.bind(this), [], {
			action: 'subscription_unlock_subscriptionid',
			vehicleid: this.vehicleid,
			subscriptionid: this.subscription['-subscriptionid']
		});
	}
});

KeyForm = Class.create();
Object.extend(KeyForm.prototype, {
	initialize: function(elementForm, elementButton, vehicleid){
		this.elementForm = elementForm;
		this.elementButton = elementButton;
		this.vehicleid = vehicleid;
		this.elementForm.disableSelector(['button']);
		this.objRegExp = /^([ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789])$/i;

		this.elementForm.domSA({
			onsubmit: function(){ return false; }
		});

		this.eventKeyPress  = this.keyPress.bindAsEventListener(this);
		Event.observe(this.elementForm.key, "keyup", this.eventKeyPress);

		this.eventSubmitForm  = this.submitForm.bindAsEventListener(this);
		Event.observe(this.elementButton, "mousedown", this.eventSubmitForm);
		Event.observe(this.elementForm, "submit", this.eventSubmitForm);

	},

	keyPress: function(event){
		this.hideError();
		var temp = '';
		var value = '';
		for(var i=0; i<=this.elementForm.key.value.length; i++){
			if(value.length < 19 && this.objRegExp.test(this.elementForm.key.value.charAt(i))){
				temp+=this.elementForm.key.value.charAt(i);
				value+=this.elementForm.key.value.charAt(i).toUpperCase();
				if(value.length < 19 && (temp.length % 4) == 0) value+='-';
			};
		};
		if(value[value.length-1] == '-') value = value.substring(0, value.length-1);
		this.elementForm.key.value = value;
		if(this.elementForm.key.value.length==19){
			this.elementForm.enableSelector(['button']);
			if(event.keyCode == Event.KEY_RETURN) this.submitForm(event);
		}else{
			this.elementForm.disableSelector(['button']);
		};
	},

	submitForm: function(event){
		this.hideError();
		$(this.elementButton.firstChild).addClassName('wait');
		this.httppost = new HttpPost();
		this.httppost.requestXML(function(response){
			if(
				typeof response.responseJSON != 'undefined'
				&& response.responseJSON.httppost['-errors'] == 0
			){
				//success
				location.reload(true);
			}else{
				//failed
				var XML = response.responseJSON.httppost;
				Object.keys(XML).each(function(key){
					if(XML[key].error){
						this.showError(XML[key].error);
					}
				}.bind(this));
				$(this.elementButton.firstChild).removeClassName('wait');
			};
		}.bind(this), [], {
			action: 'subscription_unlock_key',
			vehicleid: this.vehicleid,
			key: this.elementForm.key.value
		});
		return false;
	},

	showError: function(error){
		if(typeof this.elementError == 'undefined'){
			$(this.elementForm.key.parentNode).domIA(
				this.elementError = domCE('p').domSA({
					className: 'error'
				}),
				this.elementForm.key
			);
		};
		this.elementError.domRCN().domAC(
			domCE('strong').domCTN(lang('Error: ','Erreur: '))
		).domAC(
			domCE('span').domCHTN(error)
		).show();
		this.elementForm.key.addClassName('error');
	},

	hideError: function(){
		if(typeof this.elementError != 'undefined'){
			this.elementForm.key.removeClassName('error');
			this.elementError.hide();
		};
	}

});

var onWireEvent = new YAHOO.util.CustomEvent("Wire");
AddVehicleWire = Class.create();
Object.extend(AddVehicleWire.prototype, {
	initialize: function(parent, arguments){
		this.parent = parent;
		this.options = Object.extend({
			vehicleid: 0,
			wireid: 0,
			colorid_base: 0,
			colorid_stripe: 0,
			colorid_tracer: 0,
			on_load: function(){},
			on_edit: function(){},
			on_submit: function(){},
			on_error: function(){},
			on_cancel: function(){},
			on_destroy: function(){}
		}, (arguments || {}));

		this.hrefWires = new Array();
		this.wires = {};
		this.wire = '';
		this.hrefPolarities = new Array();
		this.polarities = {};
		this.polarity = '';

		this.SelectWire = new Select({ label: domCTN(lang('Choose Wire', 'Choisissez le câble')), text: lang('Choose Wire', 'Choisissez le câble') }, this.selectWire.bind(this));
		this.SelectPolarity = new Select({ label: domCTN(lang('Choose Polarity', 'Choisissez la polarité')), text: lang('Choose Polarity', 'Choisissez la polarité'), width: 150 }, this.selectPolarity.bind(this));
		this.SelectBaseColor = new Select({ label: domCTN(lang('--- none ---', '--- rien ---')), text: lang('--- none ---', '--- rien ---'), width: 150 }, this.selectBaseColor.bind(this));
		this.SelectStripeColor = new Select({ label: domCTN(lang('--- none ---', '--- rien ---')), text: lang('--- none ---', '--- rien ---'), width: 150 }, this.selectStripeColor.bind(this));
		this.SelectTracerColor = new Select({ label: domCTN(lang('--- none ---', '--- rien ---')), text: lang('--- none ---', '--- rien ---'), width: 150 }, this.selectTracerColor.bind(this));

		this.element = domCE('tr').domAC(
			domCE('td').domSA({
				vAlign: 'top'
			}).domAC(
				domCE('div').domSA({
					className: 'author'
				}).domAC(
					domCE('img').domSA({
						className: 'avatar'+((this.options.avatar == 'blank')?' subtle':''),
						src: ((this.options.avatar == 'blank')?'/images/icons/100x100_doppelme.gif':'http://www.doppelme.com/'+this.options.avatar+'/crop.gif'),
						height: 100,
						width: 100
					})
				).domAC(
					domCE('img').domSA({
						className: 'quote',
						src: '/images/comment.png',
						height: 22,
						width: 21
					})
				)
			)
		).domAC(
			domCE('td').domSA({
				className: 'post',
				width: '100%',
				vAlign: 'top'
			}).domAC(
				domCE('div').domSA({
					className: 'post_container bigform'
				}).domAC(
					this.elementHead = domCE('div').setStyle({
						zIndex: 2
					}).domSA({
						className: 'head'
					}).domAC(
						domCE('p').domSA({ className: 'label' }).domCTN(lang('Wire:', 'Fil:'))
					).domAC(
						domCE('div').domAC(
							this.SelectWire.element
						).domAC(
							this.SelectPolarity.element.hide()
						)
					).domAC(
						this.elementButtons = domCE('div').domSA({
							className: 'post_buttons'
						}).domAC(
							this.elementButtonCancel = domCE('a').domSA({
								href: '#',
								className: 'button',
								onclick: function(){ return false; }
							}).domAC(
								domCE('span').domSA({
									className: 'cancel'
								}).domCTN(lang('Cancel', 'Annuler'))
							)
						).domAC(
							this.elementButtonSubmit = domCE('a').domSA({
								href: '#',
								className: 'button',
								onclick: function(){ return false; }
							}).domAC(
								domCE('span').domSA({
									className: 'submit'
								}).domCTN(lang('Submit', 'Soumettre'))
							)
						)
					)
				).domAC(
					this.elementBody = domCE('div').setStyle({
						zIndex: 1
					}).domSA({
						className: 'body'
					}).domAC(
						domCE('div').domAC(
							domCE('p').domSA({ className: 'label' }).domCTN(lang('Location:', 'Lieu:'))
						).domAC(
							this.inputLocation = domCE('input', 'text').domSA({
								tabIndex: 5,
								maxLength: 64
							}).setStyle({
								width: '400px'
							})
						)
					).domAC(
						domCE('div').domAC(
							domCE('p').domSA({ className: 'label' }).domCTN('Notes:')
						).domAC(
							this.inputNotes = domCE('textarea').domSA({
								rows: 3
							}).setStyle({
								width: '99%'
							}).autoRows(3)
						)
					).domAC(
						domCE('div').domAC(
							domCE('span').setStyle({
								display:'inline-block'
							}).domAC(
								domCE('p').domSA({ className: 'label' }).domCTN(lang('Base Color:', 'Couleur de base:'))
							).domAC(
								this.SelectBaseColor.element
							)
						).domAC(
							domCE('span').setStyle({
								display:'inline-block'
							}).domAC(
								domCE('p').domSA({ className: 'label' }).domCTN(lang('Stripe Color:', 'Couleur des ponits:'))
							).domAC(
								this.SelectStripeColor.element
							)
						).domAC(
							domCE('span').setStyle({
								display:'inline-block'
							}).domAC(
								domCE('p').domSA({ className: 'label' }).domCTN(lang('Tracer Color:', 'Couleur de la bande:'))
							).domAC(
								this.SelectTracerColor.element
							)
						)
					)
				).domAC(
					this.elementErrors = domCE('div').domSA({
						className: 'post_errors'
					}).hide()
				).domAC(
					this.elementUpdates = domCE('div').domSA({
						className: 'updates'
					}).hide()
				)
			)
		);

		this.eventCancel  = this.cancel.bindAsEventListener(this);
		Event.observe(this.elementButtonCancel, "mousedown", this.eventCancel);
		this.eventSubmit  = this.submit.bindAsEventListener(this);
		Event.observe(this.elementButtonSubmit, "mousedown", this.eventSubmit);

		this.loadWires();
		this.loadColors();

		this.options.on_load();
	},

	selectWire: function(wire){
		this.wire = wire[0];
		this.options.wireid = 0;
		this.SelectPolarity.reset();
		this.SelectPolarity.show();
		this.SelectPolarity.focus();

		var keys = Object.keys(this.polarities);
		var values = Object.values(this.polarities);
		var polarities = keys.zip(values);
		polarities.each(function(polarity, index){
			if(typeof this.wires[this.wire][polarity[0]] == 'undefined'){
				//not listed
				this.SelectPolarity.options[index].disable();
			}else{
				//listed
				this.SelectPolarity.options[index].enable();
			};
		}.bind(this));
		var enabled = this.SelectPolarity.options.findAll(function(option){
			return option.arguments.enabled;
		});
		if(enabled.length == 1) enabled[0].select();
	},

	selectPolarity: function(polarity){
		this.polarity = polarity[0];
		this.options.wireid = this.wires[this.wire][this.polarity];
  	},

	selectBaseColor: function(colorid){
		this.options.colorid_base = colorid;
	},

	selectStripeColor: function(colorid){
		this.options.colorid_stripe = colorid;
	},

	selectTracerColor: function(colorid){
		this.options.colorid_tracer = colorid;
	},

	loadWires: function(){
		this.ajaxWires = new Ajax();
		this.ajaxWires.url = XMLWires;
		this.ajaxWires.caching = true;
		this.ajaxWires.requestXML(function(response){
			if(typeof response.responseJSON.wires != 'undefined'){
				var wires = (typeof response.responseJSON.wires.wire.length == 'undefined')
					? [response.responseJSON.wires.wire]
					: response.responseJSON.wires.wire ;
				wires.each(function(wire,index){
					if(typeof this.polarities[wire.polarity['#cdata-section']] == 'undefined'){
						this.polarities[wire.polarity['#cdata-section']] = {
							src: wire.polarity['-src'],
							height: wire.polarity['-height'],
							width: wire.polarity['-width'],
							alt: wire.polarity['-alt']
						}
					};
					var p = {};
					p[wire.polarity['#cdata-section']] = parseInt(wire['-wireid']);
					if(Language == 'en' && typeof this.wires[wire.name_en] != 'undefined'){
						Object.extend(this.wires[wire.name_en], p);
					}else if(Language == 'fr' && typeof this.wires[wire.name_fr] != 'undefined'){
						Object.extend(this.wires[wire.name_fr], p);
					}else{
						this.wires[lang(wire.name_en, wire.name_fr)] = p;
					}
				}.bind(this));

				var keys = Object.keys(this.wires);
				var values = Object.values(this.wires);
				var wires = keys.zip(values);
				wires.sort(function(a, b){
					return (a[0] > b[0]) ? 1 : -1;
				});
				wires.each(function(wire, index){
					this.SelectWire.addOption({
						option: domCTN(wire[0]),
						text: wire[0],
						value: wire,
						accessKey: wire[0].charAt(0).toLowerCase()
					});
				}.bind(this));

				var keys = Object.keys(this.polarities);
				var values = Object.values(this.polarities);
				var polarities = keys.zip(values);
				polarities.each(function(polarity, index){
					this.SelectPolarity.addOption({
						option: domCE('span').domAC(
							domCE('img').domSA({
								src: '/images/icons/'+polarity[1].src,
								height: 16,
								width: 16
							})
						).domCTN(polarity[0]),
						text: polarity[0],
						label: domCE('span').domAC(
							domCE('img').domSA({
								src: '/images/icons/'+polarity[1].src,
								height: 16,
								width: 16
							}).setStyle({
								marginRight: '5px'
							})
						).domCTN(polarity[0]),
						value: polarity,
						accessKey: polarity[0].charAt(0).toLowerCase()
					});
				}.bind(this));
			};
		}.bind(this));
	},

	loadColors: function(){
		this.ajaxColors = new Ajax();
		this.ajaxColors.url = XMLColors;
		this.ajaxColors.caching = true;
		this.ajaxColors.requestXML(function(response){
			if(typeof response.responseJSON.colors != 'undefined'){

				this.SelectBaseColor.addOption({
					option: domCTN(lang('--- none ---', '--- rien ---')),
					text: lang('--- none ---', '--- rien ---'),
					value: 0
				});
				this.SelectStripeColor.addOption({
					option: domCTN(lang('--- none ---', '--- rien ---')),
					text: lang('--- none ---', '--- rien ---'),
					value: 0
				});
				this.SelectTracerColor.addOption({
					option: domCTN(lang('--- none ---', '--- rien ---')),
					text: lang('--- none ---', '--- rien ---'),
					value: 0
				});
				var colors = (typeof response.responseJSON.colors.color.length == 'undefined')
					? [response.responseJSON.colors.color]
					: response.responseJSON.colors.color ;
				colors.each(function(color,index){
					var rgb = 'rgb('+color['-r']+','+color['-g']+','+color['-b']+')';
					//var avg = Math.round((parseInt(color['-r'])+parseInt(color['-g'])+parseInt(color['-b']))/3);
					//var rgb2 = 'rgb('+((avg > 128) ? 0 : 255)+','+((avg > 128) ? 0 : 255)+','+((avg > 128) ? 0 : 255)+')';
					this.SelectBaseColor.addOption({
						option: domCE('span').domAC(
							domCE('img').domSA({
								src: '/images/spacer.gif', height: 14, width: 14
							}).setStyle({
								border:'1px solid #000000', backgroundColor: rgb
							})
						).domCTN(lang(color.name_en, color.name_fr)),
						text: lang(color.name_en, color.name_fr),
						label: domCE('span').domAC(
							domCE('img').domSA({
								src: '/images/spacer.gif', height: 15, width: 15
							}).setStyle({
								display: 'inline-block', marginRight: '5px', border:'1px solid #000000', backgroundColor: rgb
							})
						).domCTN(lang(color.name_en, color.name_fr)),
						value: color['-colorid'],
						accessKey: lang(color.name_en, color.name_fr).charAt(0).toLowerCase()
					});
					this.SelectStripeColor.addOption({
						option: domCE('span').domAC(
							domCE('img').domSA({
								src: '/images/spacer.gif', height: 14, width: 14
							}).setStyle({
								border:'1px solid #000000', backgroundColor: rgb
							})
						).domCTN(lang(color.name_en, color.name_fr)),
						text: lang(color.name_en, color.name_fr),
						label: domCE('span').domAC(
							domCE('img').domSA({
								src: '/images/spacer.gif', height: 15, width: 15
							}).setStyle({
								display: 'inline-block', marginRight: '5px', border:'1px solid #000000', backgroundColor: rgb
							})
						).domCTN(lang(color.name_en, color.name_fr)),
						value: color['-colorid'],
						accessKey: lang(color.name_en, color.name_fr).charAt(0).toLowerCase()
					});
					this.SelectTracerColor.addOption({
						option: domCE('span').domAC(
							domCE('img').domSA({
								src: '/images/spacer.gif', height: 14, width: 14
							}).setStyle({
								border:'1px solid #000000', backgroundColor: rgb
							})
						).domCTN(lang(color.name_en, color.name_fr)),
						text: lang(color.name_en, color.name_fr),
						label: domCE('span').domAC(
							domCE('img').domSA({
								src: '/images/spacer.gif', height: 15, width: 15
							}).setStyle({
								display: 'inline-block', marginRight: '5px', border:'1px solid #000000', backgroundColor: rgb
							})
						).domCTN(lang(color.name_en, color.name_fr)),
						value: color['-colorid'],
						accessKey: lang(color.name_en, color.name_fr).charAt(0).toLowerCase()
					});
				}.bind(this));
			};
		}.bind(this));
	},

	submit: function(event){
		if(this.options.wireid == 0){
			if(this.wire == ''){
				this.SelectWire.focus();
			}else{
				this.SelectPolarity.focus();
			};
			this.stopBubble(event);
			return;
		};

		this.elementButtons.hide();
		this.elementErrors.domRCN();

		this.SelectWire.disable();
		this.SelectPolarity.disable();
		this.SelectBaseColor.disable();
		this.SelectStripeColor.disable();
		this.SelectTracerColor.disable();
		this.inputLocation.disable();
		this.inputNotes.disable();

		this.httppost = new HttpPost();
		this.httppost.requestXML(function(response){
			var XML = response.responseJSON.httppost;
			if(response.responseJSON.httppost['-errors'] == 0){
				//success
				onWireEvent.fire('addWire', {
					vehiclewireid: XML['vehiclewireid'].value
				});
				this.options.on_submit();
				this.destroy();
			}else{
				//failed
				this.elementErrors.show();
				Object.keys(XML).each(function(key){
					if(XML[key].error){
						this.elementErrors.domAC(
							domCE('p').domSA({ className: 'post_error' }).domCTN(lang('Error: ','Erreur: ')+XML[key].error)
						);
					}
				}.bind(this));
				this.SelectWire.enable();
				this.SelectPolarity.enable();
				this.SelectBaseColor.enable();
				this.SelectStripeColor.enable();
				this.SelectTracerColor.enable();
				this.inputLocation.enable();
				this.inputNotes.enable();
				this.elementButtons.show();
				this.options.on_error();

			};
		}.bind(this), [], {
			action: 'vehicle_wire_add',
			vehicleid: this.options.vehicleid,
			wireid: this.options.wireid,
			colorid_base: this.options.colorid_base,
			colorid_stripe: this.options.colorid_stripe,
			colorid_tracer: this.options.colorid_tracer,
			location_en: this.inputLocation.value,
			notes_en: this.inputNotes.value
		});
	},

	cancel: function(event){
		this.options.on_cancel();
		this.destroy();
	},

	destroy: function(event){
		if(YAHOO.util.Dom.inDocument(this.element)) Element.remove(this.element);
		try{
			Event.stopObserving(this.elementButtonCancel, "mousedown", this.eventCancel);
			Event.stopObserving(this.elementButtonSubmit, "mousedown", this.eventSubmit);
		}catch(e){};
		this.SelectWire.destroy();
		this.SelectPolarity.destroy();
		this.SelectBaseColor.destroy();
		this.SelectStripeColor.destroy();
		this.SelectTracerColor.destroy();
		this.options.on_destroy();
	},

	stopBubble: function(event){
		try{ if(event && typeof(Event.stop) == 'function') Event.stop(event); }catch(e){};
	}
});

Wires = Class.create();
Object.extend(Wires.prototype, {
	initialize: function(elementDiv, makeid, modelid, vehicleid){
		this.elementDiv = elementDiv;
		this.makeid = makeid;
		this.modelid = modelid;
		this.vehicleid = vehicleid;
		this.wires = new Array();

		this.elementDiv.domRCN();
		this.elementDiv.domAC(
			this.elementTable = domCE('table').domSA({
				className: 'wires',
				border: 0,
				cellSpacing: 0,
				cellPadding: 0,
				width: '100%'
			}).domAC(
				this.elementThead = domCE('thead').domAC(
					this.elementNav = domCE('tr').domSA({
						className: 'nav'
					}).domAC(
						domCE('td').domCTN(String.nbsp)
					).domAC(
						domCE('td').domAC(
							domCE('p').domSA({ className: 'polarity' }).domCTN(lang('Polarity', 'Polarité'))
						)
					).domAC(
						domCE('td').domAC(
							domCE('p').domSA({ className: 'name' }).domCTN(lang('Wire/Function', 'Fils/Fonction'))
						)
					).domAC(
						domCE('td').domSA({
							width: '100%'
						}).domAC(
							domCE('p').domSA({ className: 'color' }).domCTN(lang('Color', 'Couleur'))
						).domAC(
							domCE('p').domSA({ className: 'location' }).domCTN(lang('Location/Description', 'Lieu/Description'))
						)
					)
				).domAC(
					this.elementFilter = domCE('tr').domSA({
						className: 'filter noprint'
					}).domAC(
						domCE('td').domSA({
							colSpan: '5'
						}).domAC(
							this.elementFilterDiv = domCE('div').domCTN(String.nbsp)
						)
					).hide()
				).domAC(
					this.elementLoading = domCE('tr').domAC(
						domCE('td').setStyle({
							height: '250px'
						}).domSA({
							colSpan: '4',
							align: 'center',
							vAlign: 'middle',
							className: 'loading'
						}).domAC(
							domCE('span').domCTN(lang('Loading vehicle data...', 'Chargement des données sur le véhicule...'))
						).domAC(
							domCE('br')
						).domAC(
							domCE('br')
						).domAC(
							domCE('img').domSA({
								src: '/images/overlayloading.gif',
								height: 13,
								width: 208,
								alt: ''
							})
						)
					)
				)
			).domAC(
				this.elementTfoot = domCE('tfoot').domAC(
					domCE('tr').domAC(
						domCE('td').domSA({
							className: 'disclaimer noscreen',
							colSpan: '4'
						}).domAC(
							$('disclaimer').cloneNode(true).removeClassName('noprint')
						)
					)
				)
			).domAC(
				this.elementTbody = domCE('tbody')
			)
		);

		setTimeout(function(){
			this.ajax = new Ajax();
			this.ajax.url = XMLVehicleWires+'?makeid='+this.makeid+'&modelid='+this.modelid+'&vehicleid='+this.vehicleid;
			this.ajax.requestXML(function(response){
				Element.remove(this.elementLoading);
				if(
					typeof response.responseJSON != 'undefined'
					&& typeof response.responseJSON.wires != 'undefined'
					&& typeof response.responseJSON.wires.wire != 'undefined'
				){
					var wires = (typeof response.responseJSON.wires.wire.length == 'undefined')
						? [response.responseJSON.wires.wire]
						: response.responseJSON.wires.wire;
					wires.each(function(wire){
						this.pointer = this.wires.length;
						this.wires[this.pointer] = new Wire(this, {
							wireid: wire['-wireid'],
							sort: wire['-sort'],
							polarity: wire.polarity['#cdata-section'],
							polarity_src: wire.polarity['-src'],
							polarity_height: wire.polarity['-height'],
							polarity_width: wire.polarity['-width'],
							name_en: wire.name_en,
							name_fr: wire.name_fr,
							vehiclewires: ((typeof wire.vehiclewires != 'undefined') ? wire.vehiclewires : {} )
						});
						this.elementTbody.domAC(this.wires[this.pointer].element);
					}.bind(this));
					this.wires.sort(function(a, b){
						return ((a.options.sort - b.options.sort) > 0) ? 1 : -1 ;
					});
				};
			}.bind(this));
		}.bind(this), 500);
		onWireEvent.subscribe(this.eventDispatch, this, true);
	},

	eventDispatch: function(type, args){
		switch(args[0]){
			case 'addWire':
				this.newWire(args[1]);
		};
	},

	newWire: function(arguments){
		this.ajax = new Ajax();
		this.ajax.url = XMLVehicleWire+'?makeid='+this.makeid+'&modelid='+this.modelid+'&vehicleid='+this.vehicleid+'&vehiclewireid='+arguments.vehiclewireid;
		this.ajax.requestXML(function(response){
			if(typeof response.responseJSON.wires.wire != 'undefined'){
				var wires = (typeof response.responseJSON.wires.wire.length == 'undefined')
					? [response.responseJSON.wires.wire]
					: response.responseJSON.wires.wire;
				wires.each(function(wire){
					var isLast = true;
					for(var w=0; w<this.wires.length; w++){
						if(this.wires[w].options.sort >= parseInt(wire['-sort'])){
							if(this.wires[w].options.sort > parseInt(wire['-sort'])){
								//wire does not exist yet
								this.pointer = this.wires.length;
								this.wires[this.pointer] = new Wire(this, {
									wireid: wire['-wireid'],
									sort: wire['-sort'],
									polarity: wire.polarity['#cdata-section'],
									polarity_src: wire.polarity['-src'],
									polarity_height: wire.polarity['-height'],
									polarity_width: wire.polarity['-width'],
									name_en: wire.name_en,
									name_fr: wire.name_fr,
									vehiclewires: ((typeof wire.vehiclewires != 'undefined') ? wire.vehiclewires : {} )
								});
								this.elementTbody.domIB(
									this.wires[this.pointer].element,
									this.wires[w].element
								);
							}else{
								//wire exists
								var vehiclewire = wire.vehiclewires.vehiclewire;
								var arguments = {
									vehiclewireid: vehiclewire['-vehiclewireid'],
									productid: ((vehiclewire['-productid'] != undefined) ? vehiclewire['-productid'] : 0 ),
									rating_p: ((vehiclewire['-rating_positive'] != undefined) ? vehiclewire['-rating_positive'] : 0 ),
									rating_n: ((vehiclewire['-rating_negative'] != undefined) ? vehiclewire['-rating_negative'] : 0 ),
									location_en: vehiclewire.location_en,
									location_fr: vehiclewire.location_fr,
									notes_en: vehiclewire.notes_en,
									notes_fr: vehiclewire.notes_fr,
									images: ((typeof vehiclewire.images != 'undefined') ? vehiclewire.images : {} ),
									comments: ((typeof vehiclewire.comments != 'undefined') ? vehiclewire.comments : {} ),
									ratings: ((typeof vehiclewire.ratings != 'undefined') ? vehiclewire.ratings : {} ),
									index: this.wires[w].vehiclewires.length
								};
								if(typeof vehiclewire.author != 'undefined'){
									Object.extend(arguments, {
										userid: vehiclewire.author['-id'],
										avatar: vehiclewire.author['-avatar'],
										username: vehiclewire.author['#cdata-section']
									});
								};
								if(typeof vehiclewire.color != 'undefined'){
									Object.extend(arguments, {
										colorid_base: vehiclewire.color['-colorid_base'],
										colorid_stripe: vehiclewire.color['-colorid_stripe'],
										colorid_tracer: vehiclewire.color['-colorid_tracer'],
										color_en: vehiclewire.color.color_en,
										color_fr: vehiclewire.color.color_fr
									});
								};
								this.wires[w].addVehicleWire(arguments);
							}
							isLast = false;
							break;
						};
					};
					if(isLast){
						this.pointer = this.wires.length;
						this.wires[this.pointer] = new Wire(this, {
							wireid: wire['-wireid'],
							sort: wire['-sort'],
							polarity: wire.polarity['#cdata-section'],
							polarity_src: wire.polarity['-src'],
							polarity_height: wire.polarity['-height'],
							polarity_width: wire.polarity['-width'],
							name_en: wire.name_en,
							name_fr: wire.name_fr,
							vehiclewires: ((typeof wire.vehiclewires != 'undefined') ? wire.vehiclewires : {} )
						});
						this.elementTbody.domAC(this.wires[this.pointer].element);
					};
					this.wires.sort(function(a, b){
						return ((a.options.sort - b.options.sort) > 0) ? 1 : -1 ;
					});
				}.bind(this));
			};
		}.bind(this));
	}
});

Wire = Class.create();
Object.extend(Wire.prototype, {
	initialize: function(parent, arguments){
		this.parent = parent;
		this.options = Object.extend({
			wireid: 0,
			sort: 0,
			polarity: '',
			polarity_src: '',
			polarity_height: 0,
			polarity_width: 0,
			name_en: '',
			name_fr: '',
			vehiclewires: {}
		}, (arguments || {}));

		this.vehiclewires = new Array();

		this.element = domCE('tr').domSA({
			className: 'wire'
		}).domAC(
			domCE('td').domSA({
				className: 'pad'
			}).domAC(
				domCE('p').domSA({ className: 'sort' }).domCTN(this.options.sort+'.')
			)
		).domAC(
			domCE('td').domSA({
				align: 'center',
				className: 'noscreen'
			}).domAC(
				domCE('img').domSA({
					src: '/images/icons/'+this.options.polarity_src,
					height: parseInt(this.options.polarity_height/2),
					width: parseInt(this.options.polarity_width/2),
					alt: this.options.polarity
				})
			)
		).domAC(
			domCE('td').domSA({
				className: 'pad noprint',
				align: 'center'
			}).domAC(
				domCE('img').domSA({
					src: '/images/icons/'+this.options.polarity_src,
					height: this.options.polarity_height,
					width:this.options.polarity_width,
					alt: this.options.polarity
				})
			).domAC(
				domCE('p').domSA({ className: 'polarity' }).domCTN(this.options.polarity)
			)
		).domAC(
			domCE('td').domSA({
				className: 'pad'
			}).domAC(
				domCE('p').domSA({ className: 'name' }).domCTN(lang(this.options.name_en, this.options.name_fr))
			)
		).domAC(
			domCE('td').domSA({
				vAlign: 'top'
			}).domAC(
				domCE('table').domSA({
					className: 'locations',
					width: '100%',
					border: 0,
					cellSpacing: 0,
					cellPadding: 0
				}).domAC(
					this.elementTbodyWires = domCE('tbody')
				)
			)
		);

		if(typeof this.options.vehiclewires.vehiclewire != 'undefined'){
			this.options.vehiclewires = (typeof this.options.vehiclewires.vehiclewire.length == 'undefined')
				? [this.options.vehiclewires.vehiclewire]
				: this.options.vehiclewires.vehiclewire;
			this.options.vehiclewires.sort(function(a, b){
				return ( (typeof a['-productid'] != 'undefined' && typeof b['-productid'] != 'undefined')
					? ((a['-productid'] > b['-productid']) ? -1 : 1 )
					: (((a.ratings['-positive']-a.ratings['-negative']) > (b.ratings['-positive']-b.ratings['-negative'])) ? -1 : 1)
				);
			});
			this.options.vehiclewires.each(function(vehiclewire, index){
				this.arguments = {
					wireid: this.options.wireid,
					vehiclewireid: vehiclewire['-vehiclewireid'],
					productid: ((vehiclewire['-productid'] != undefined) ? vehiclewire['-productid'] : 0 ),
					rating_p: vehiclewire.ratings['-positive'],
					rated_p: false,
					rating_n: vehiclewire.ratings['-negative'],
					rated_n: false,
					location_en: vehiclewire.location_en,
					location_fr: vehiclewire.location_fr,
					notes_en: vehiclewire.notes_en,
					notes_fr: vehiclewire.notes_fr,
					images: ((typeof vehiclewire.images != 'undefined') ? vehiclewire.images : {} ),
					comments: ((typeof vehiclewire.comments != 'undefined') ? vehiclewire.comments : {} ),
					ratings: ((typeof vehiclewire.ratings != 'undefined') ? vehiclewire.ratings : {} ),
					index: index
				};
				if(typeof vehiclewire.author != 'undefined'){
					Object.extend(this.arguments, {
						userid: vehiclewire.author['-id'],
						avatar: vehiclewire.author['-avatar'],
						username: vehiclewire.author['#cdata-section']
					});
				};
				if(typeof vehiclewire.color != 'undefined'){
					Object.extend(this.arguments, {
						colorid_base: vehiclewire.color['-colorid_base'],
						colorid_stripe: vehiclewire.color['-colorid_stripe'],
						colorid_tracer: vehiclewire.color['-colorid_tracer'],
						color_en: vehiclewire.color.color_en,
						color_fr: vehiclewire.color.color_fr
					});
				};
				if(
					session != undefined
					&& session.user != undefined
					&& session.user.userid != undefined
					&& vehiclewire.ratings.rating != undefined
				){
					vehiclewire.ratings.rating = (typeof vehiclewire.ratings.rating.length == 'undefined')
						? [vehiclewire.ratings.rating]
						: vehiclewire.ratings.rating ;
					vehiclewire.ratings.rating.each(function(rating, index){
						if(rating['-userid'] == session.user.userid){
							if(parseInt(rating['-rating']) == 1){
								Object.extend(this.arguments, { rated_p: true });
							}else{
								Object.extend(this.arguments, { rated_n: true });
							};
						};
					}.bind(this));
				}
				this.addVehicleWire(this.arguments);
				//arguments.index++;
				//this.addVehicleWire(this.arguments);
				//this.addVehicleWire(this.arguments);
			}.bind(this));
		};
	},

	addVehicleWire: function(arguments){
		this.pointer = this.vehiclewires.length;
		this.vehiclewires[this.pointer] = new VehicleWire(this, arguments);
		this.elementTbodyWires.domAC(this.vehiclewires[this.pointer].elementRowLocation);
		this.elementTbodyWires.domAC(this.vehiclewires[this.pointer].elementRowExtras);
	}

});

VehicleWire = Class.create();
Object.extend(VehicleWire.prototype, {
	initialize: function(parent, arguments){
		this.parent = parent;
		this.options = Object.extend({
			vehiclewireid: 0,
			wireid: 0,
			productid: 0,
			rating_p: 0,
			rated_p: false,
			rating_n: 0,
			rated_n: false,
			userid: 0,
			username: 'unknown',
			avatar: 'blank',
			colorid_base: 0,
			colorid_stripe: 0,
			colorid_tracer: 0,
			color_en: '',
			color_fr: '',
			location_en: '',
			location_fr: '',
			notes_en: '',
			notes_fr: '',
			images: {},
			comments: {},
			ratings: {},
			index: 0
		}, (arguments || {}));

		onWireEvent.subscribe(this.eventDispatch, this, true);

		this.images = new Array();
		this.extrasPinned = false;
		this.photosHeight = 91;
		this.photosRendered = false;
		this.ratingsRendered = false;

		this.elementRowLocation = domCE('tr').domSA({
			className: 'location'
		}).domAC(
			this.elementCellLeft = domCE('td').domSA({
				width: '100%',
				vAlign: 'middle',
				colSpan: 2
			}).setStyle({
				padding: '0px 5px'
			})
		).domAC(
			this.elementCellRating = domCE('td').setStyle({
				borderTop: ((this.options.index == 0) ? '' : '1px solid #dddddd')
			}).domSA({
				className: 'rating noprint',
				vAlign: 'middle'
			}).domCTN(String.nbsp)
		).domAC(
			this.elementCellRight = domCE('td').domSA({
				className: 'options noprint',
				vAlign: 'middle'
			}).domAC(
				domCE('div').domSA({
					align: 'right'
				}).setStyle({
					whiteSpace: 'nowrap'
				}).domAC(
					this.elementDivPhoto = domCE('div').domSA({
						className: 'inline'
					}).hide()
				).domAC(
					this.elementImgUser = domCE('a').domSA({
						className: 'inline user'
					}).domAC(
						this.elementDivUser = domCE('div')
					).hide()
				).domAC(
					this.elementImgPhoto = domCE('a').domSA({
						className: 'inline photo'
					}).domAC(
						domCE('div').domAC(
							this.elementSpanPhoto = domCE('p').domSA({
								className: 'num'
							}).domCTN(String.nbsp)
						)
					).hide()
				).domAC(
					this.elementImgRating = domCE('a').domSA({
						className: 'inline rating'
					}).domAC(
						domCE('div').domAC(
							this.elementSpanRating = domCE('p').domSA({
								className: 'num'
							}).domCTN(String.nbsp)
						)
					).hide()
				)
			).hide()
		);

		this.elementRowExtras = domCE('tr').domSA({
			className: 'extras noprint'
		}).domAC(
			this.elementCellExtras = domCE('td').domSA({
				colSpan: 3
			}).domAC(
				this.elementDivPhotos = domCE('div').domSA({
					className:'photos'
				}).domAC(
					domCE('div').domSA({
						className: 'options'
					}).domAC(
						this.elementHrefCollapsePhotos = domCE('a').domSA({
							name: 'link',
							className: 'spacify'
						}).domCTN(lang('collapse all', 'réduire toutes'))
					).domAC(
						this.elementHrefExpandPhotos = domCE('a').domSA({
							name: 'link'
						}).domCTN(lang('expand all', 'maximiser toutes'))
					)
				).domAC(
					domCE('h3').domSA({
						className: 'title'
					}).domCTN(lang('Pinned Photos', 'Photos épinglées'))
				)
			).domAC(
				this.elementDivRatings = domCE('div').domSA({
					className:'ratings'
				}).domAC(
					domCE('div').domSA({
						className: 'options'
					}).domAC(
						this.elementHrefCollapseRatings = domCE('a').domSA({
							name: 'link',
							className: 'spacify'
						}).domCTN(lang('collapse all', 'réduire toutes'))
					).domAC(
						this.elementHrefExpandRatings = domCE('a').domSA({
							name: 'link'
						}).domCTN(lang('expand all', 'maximiser toutes'))
					)
				).domAC(
					domCE('h3').domSA({
						className: 'title'
					}).domCTN(lang('Comments & Rating', 'Commentaires et Classement'))
				)
			)
		).hide();

		Event.observe(this.elementHrefCollapsePhotos, "click", function(){
			onWireEvent.fire('collapsePhotos', {});
			//setTimeout(this.scrollTo.bind(this), 500);
		}.bind(this));
		Event.observe(this.elementHrefExpandPhotos, "click", function(){
			onWireEvent.fire('expandPhotos', {});
			//setTimeout(this.scrollTo.bind(this), 500);
		}.bind(this));
		Event.observe(this.elementHrefCollapseRatings, "click", function(){
			onWireEvent.fire('collapseRatings', {});
			//setTimeout(this.scrollTo.bind(this), 500);
		}.bind(this));
		Event.observe(this.elementHrefExpandRatings, "click", function(){
			onWireEvent.fire('expandRatings', {});
			//setTimeout(this.scrollTo.bind(this), 500);
		}.bind(this));


		if(this.options.index > 0){
			this.elementCellLeft.setStyle({
				borderTop: '1px solid #dddddd'
			});
		};

		if(typeof this.options.userid != 'undefined' && this.options.userid != 0){
			var userIcon = new UserIcon({
				userid: this.options.userid,
				username: this.options.username,
				avatar: this.options.avatar
			});
			this.elementCellLeft.domSA({ colSpan: 1 });
			this.elementCellRight.show();
			this.elementDivUser.domAC(
				userIcon.element
			);
			this.elementImgUser.show();
		};

		if(this.options.userid != 0){
			this.elementCellLeft.domAC(
				domCE('p').domSA({ className: 'author noscreen' }).domCTN(lang('Added by ', 'Ajouté par ')+this.options.username)
			);
		};

		if(
			typeof this.options.images != 'undefined'
			&& typeof this.options.images.image != 'undefined'
		){
			this.options.images.image = (typeof this.options.images.image.length == 'undefined')
				? [this.options.images.image]
				: this.options.images.image ;
			this.imagelist = new Array();
			this.options.images.image.each(function(image, i){
				if(image['-sort'] != undefined){
					this.imagelist[this.imagelist.length] = image['-sort'];
				};
			}.bind(this));
			if(this.imagelist.length >= 1){
				this.elementCellLeft.domAC(
					domCE('p').domSA({ className: 'photo noscreen' }).domCTN('[Photo'+((this.imagelist.length > 1) ? 's' : '' )+': '+this.imagelist.join(', ')+']')
				);
			};
		};

		if(typeof lang(this.options.color_en, this.options.color_fr) != 'undefined'){
			this.elementCellLeft.domAC(
				domCE('p').domSA({ className: 'color' }).domCTN(lang(this.options.color_en, this.options.color_fr))
			);
		};

		if(
			(typeof this.options.location_en != 'undefined' && this.options.location_en != '')
			|| (typeof this.options.location_fr != 'undefined' && this.options.location_fr != '')
		){
			this.elementCellLeft.domAC(
				eleLocation = domCE('p').domSA({ className: 'location' })
			);
			if(Language == 'en'){
				if(typeof this.options.location_en != 'undefined' && this.options.location_en != ''){
					eleLocation.domCTN(this.options.location_en);
				}else if(typeof this.options.location_fr != 'undefined' && this.options.location_fr != ''){
					eleLocation.domCTN(this.options.location_fr);
					onTranslateEvent.fire(eleLocation, 'fr', 'en');
				};
			};
			if(Language == 'fr'){
				if(typeof this.options.location_fr != 'undefined' && this.options.location_fr != ''){
					eleLocation.domCTN(this.options.location_fr);
				}else if(typeof this.options.location_en != 'undefined' && this.options.location_en != ''){
					eleLocation.domCTN(this.options.location_en);
					onTranslateEvent.fire(eleLocation, 'en', 'fr');
				};
			};
		};

		if(
			(typeof this.options.notes_en != 'undefined' && this.options.notes_en != '')
			|| (typeof this.options.notes_fr != 'undefined' && this.options.notes_fr != '')
		){
			this.elementCellLeft.domAC(
				eleNotes = domCE('p').domSA({ className: 'notes' })
			);
			if(Language == 'en'){
				if(typeof this.options.notes_en != 'undefined' && this.options.notes_en != ''){
					eleNotes.domCTN(this.options.notes_en);
				}else if(typeof this.options.notes_fr != 'undefined' && this.options.notes_fr != ''){
					eleNotes.domCTN(this.options.notes_fr);
					onTranslateEvent.fire(eleNotes, 'fr', 'en');
				};
			};
			if(Language == 'fr'){
				if(typeof this.options.notes_fr != 'undefined' && this.options.notes_fr != ''){
					eleNotes.domCTN(this.options.notes_fr);
				}else if(typeof this.options.notes_en != 'undefined' && this.options.notes_en != ''){
					eleNotes.domCTN(this.options.notes_en);
					onTranslateEvent.fire(eleNotes, 'en', 'fr');
				};
			};
		};

		if(this.options.images.image != undefined){
			this.photosExist = true;

			this.eventClickPhotos = this.clickPhotos.bindAsEventListener(this);
			Event.observe(this.elementImgPhoto, "click", this.eventClickPhotos);

			this.eventDoubleClickPhotos = this.doubleClickPhotos.bindAsEventListener(this);
			Event.observe(this.elementImgPhoto, "dblclick", this.eventDoubleClickPhotos);

			this.elementCellLeft.domSA({ colSpan: 1 });
			this.elementCellRight.show();
			this.elementImgPhoto.show();

			this.elementSpanPhoto.domRCN();
			this.elementSpanPhoto.domCTN(
				((this.options.images.image.length != undefined)
					? this.options.images.image.length
					: '1'
				)
			);
		};


		if(this.options.productid == 0){
			this.eventClickRatings = this.clickRatings.bindAsEventListener(this);
			Event.observe(this.elementImgRating, "click", this.eventClickRatings);

			this.eventDoubleClickRatings = this.doubleClickRatings.bindAsEventListener(this);
			Event.observe(this.elementImgRating, "dblclick", this.eventDoubleClickRatings);

			this.elementCellLeft.domSA({ colSpan: 1 });
			this.elementCellRight.show();
			this.elementImgRating.show();

			this.elementSpanRating.domRCN();
			this.elementSpanRating.domCTN(
				( this.options.comments.comment == undefined )
					? String.nbsp
					: ( this.options.comments.comment.length == undefined )
						? '1'
						: this.options.comments.comment.length
			);

			var ratingInt = parseInt(this.options.rating_p) - parseInt(this.options.rating_n);
			this.elementCellRating.domRCN();
			this.elementCellRating.domAC(
				domCE('p').domSA({
					className: ((ratingInt == 0) ? 'neu' : ((ratingInt > 0) ? 'pos' : 'neg' ))
				}).domCTN(((ratingInt == 0)
					? String.nbsp
					: ((ratingInt > 0) ?'+' : '' )+ratingInt
				))
			);
		};
	},

	scrollTo: function(event){
		this.elementRowLocation.scrollTo();
	},

	showExtras: function(event){
		this.elementRowLocation.addClassName('locationf');
		this.elementRowExtras.show();
	},

	hideExtras: function(event){
		this.elementRowLocation.removeClassName('locationf');
		this.elementRowExtras.hide();
	},

	clickPhotos: function(event){
		if(this.photosShown != true){
			this.showPhotos(event);
			this.showExtras(event);
			onWireEvent.fire('selectWire', this.options.wireid, this.options.vehiclewireid);
		}else{
			this.hidePhotos(event);
			this.hideExtras(event);
		};
	},

	doubleClickPhotos: function(event){
		if(this.photosShown != true){
			onWireEvent.fire('expandPhotos', {});
		}else{
			onWireEvent.fire('collapsePhotos', {});
		};
	},

	showPhotos: function(event){
		if(!this.photosRendered) this.renderPhotos();
		this.elementDivPhotos.show();
		this.elementImgPhoto.addClassName('inlinef');
		this.photosShown = true;
		this.hideRatings(event);
	},

	hidePhotos: function(event){
		this.elementDivPhotos.hide();
		this.elementImgPhoto.removeClassName('inlinef');
		this.photosShown = false;
	},

	clickRatings: function(event){
		if(this.ratingsShown != true){
			this.showRatings(event);
			this.showExtras(event);
			onWireEvent.fire('selectWire', this.options.wireid, this.options.vehiclewireid);
		}else{
			this.hideRatings(event);
			this.hideExtras(event);
		};
	},

	doubleClickRatings: function(event){
		if(this.ratingsShown != true){
			onWireEvent.fire('expandRatings', {});
		}else{
			onWireEvent.fire('collapseRatings', {});
		};
	},

	showRatings: function(event){
		if(!this.ratingsRendered) this.renderRatings();
		this.elementDivRatings.show();
		this.elementImgRating.addClassName('inlinef');
		this.ratingsShown = true;
		this.hidePhotos(event);
	},

	hideRatings: function(event){
		this.elementImgRating.removeClassName('inlinef');
		this.elementDivRatings.hide();
		this.ratingsShown = false;
	},

	eventDispatch: function(type, args){
		switch(args[0]){
			case 'expandPhotos':
				if(this.photosExist == true){
					this.showExtras();
					this.showPhotos();
				}
				break;
			case 'collapsePhotos':
				if(this.photosExist == true){
					if(this.photosShown){
						this.hidePhotos();
						this.hideExtras();
					};
				}
				break;
			case 'expandRatings':
				if(this.options.productid == 0){
					this.showExtras();
					this.showRatings();
				};
				break;
			case 'collapseRatings':
				if(this.options.productid == 0){
					if(this.ratingsShown){
						this.hideRatings();
						this.hideExtras();
					};
				};
				break;
		};
	},

	renderPhotos: function(){
		if(this.photosRendered) return;
		if(this.options.images.image != undefined){
			this.options.images = (this.options.images.image.length == undefined)
				? [this.options.images.image]
				: this.options.images.image;
			this.options.images.each(function(image){
				this.addVehicleWireImage({
					imageid: image['-imageid'],
					vehicleimageid: image['-vehicleimageid'],
					host: image['-host'],
					md5sum: image['-md5sum'],
					aspectratio: image['-aspectratio'],
					x: image['-x'],
					y: image['-y']
				});
			}.bind(this));
		};
		this.photosRendered = true;
	},

	addVehicleWireImage: function(arguments){
		this.pointer = this.images.length;
		this.images[this.pointer] = new VehicleWireImage(this, arguments);
		this.elementDivPhotos.domAC(this.images[this.pointer].element);
	},


	renderRatings: function(){
		if(this.ratingsRendered) return;

		var ratingInt = parseInt(this.options.rating_p) - parseInt(this.options.rating_n);
		var ratingStr = ((ratingInt == 0)
			? '&#177;'
			: ((ratingInt > 0) ?'+' : '' )
		)+ratingInt;

		this.elementDivRatings.domAC(
			domCE('table').domSA({
				className: 'ratings bigform',
				width: '100%'
			}).domAC(
				domCE('tbody').domAC(
					domCE('tr').domAC(
						domCE('td').domSA({
							className: 'left',
							width: '66%'
						}).domAC(
							this.elementCommentList = domCE('div').domSA({
								className: 'list'
							}).domAC(
								domCE('p').domCTN(lang('No comments', 'Pas de commentaires'))
							)
						).domAC(
							this.elementCommentForm = domCE('div').domSA({
								className: 'form'
							}).hide()
						)
					).domAC(
						domCE('td').domSA({
							className: 'right',
							width: '33%'
						}).domAC(
							this.elementRatingList = domCE('div').domAC(
								domCE('p').domCTN(lang('Rating:', 'Note:'))
							).domAC(
								domCE('table').domSA({
									className: 'rating'
								}).domAC(
									domCE('tbody').domAC(
										domCE('tr').domAC(
											domCE('td').domAC(
												this.buttonThumbDown = domCE('img').domSA({
													src: '/images/spacer.gif',
													className: 'imgdown '+((this.options.rated_n) ? 'rated' : 'unrated' )
												})
											).domAC(
												this.numThumbDown = domCE('p').domSA({ className: 'neg' }).domCTN(((this.options.rating_n > 0) ?'-'+this.options.rating_n:String.nbsp))
											)
										).domAC(
											domCE('td').domSA({
												valign: 'middle'
											}).domAC(
												this.elementRating = domCE('p')
											)
										).domAC(
											domCE('td').domAC(
												this.numThumbUp = domCE('p').domSA({ className: 'pos' }).domCTN(((this.options.rating_p > 0) ?'+'+this.options.rating_p:String.nbsp))
											).domAC(
												this.buttonThumbUp = domCE('img').domSA({
													src: '/images/spacer.gif',
													className: 'imgup '+((this.options.rated_p) ? 'rated' : 'unrated' )
												})
											)
										)
									)
								)
							)
						)
					)
				)
			)
		);

		this.drawRating();

		this.eventRatePositive = this.ratePositive.bindAsEventListener(this);
		Event.observe(this.buttonThumbUp, "click", this.eventRatePositive);

		this.eventRateNegative = this.rateNegative.bindAsEventListener(this);
		Event.observe(this.buttonThumbDown, "click", this.eventRateNegative);

		if(this.options.comments.comment == undefined){
			this.elementCommentList.show();
		}else{
			this.options.comments = (this.options.comments.comment.length == undefined)
				? [this.options.comments.comment]
				: this.options.comments.comment;
			this.elementCommentList.show();
			this.options.comments.each(function(comment, index){
				if(index == 0) this.elementCommentList.domRCN();
				this.addVehicleWireComment({
					userid: comment['-userid'],
					username: comment['-username'],
					avatar: comment['-avatar'],
					comment: comment['#cdata-section'],
					lang: comment['-lang']
				});
			}.bind(this));
		};

		if(permissions.wires_w){
			this.elementCommentForm.show();
			this.elementCommentForm.domAC(
				domCE('p').domSA({ className: 'label' }).domCTN(lang('Add Comment', 'Ajouter un commentaire'))
			).domAC(
				this.elementInputComment = domCE('textarea').domSA({
					rows: 2
				}).autoRows()
			).domAC(
				this.elementErrorComments = domCE('div').domSA({
					className: 'post_errors'
				}).hide()
			).domAC(
				this.elementButtonSubmit = domCE('a').domSA({
					href: '#',
					className: 'button',
					onclick: function(){ return false; }
				}).domAC(
					domCE('span').domSA({
						className: 'submit'
					}).domCTN(lang('Submit', 'Soumettre'))
				)
			);

			this.eventSubmitComment = this.submitComment.bindAsEventListener(this);
			Event.observe(this.elementButtonSubmit, "click", this.eventSubmitComment);
		};

		this.ratingsRendered = true;
	},

	drawRating: function(){
		var ratingInt = parseInt(this.options.rating_p) - parseInt(this.options.rating_n);
		var ratingStr = ((ratingInt == 0)
			? '&#177;'
			: ((ratingInt > 0) ?'+' : '' )
		)+ratingInt;
		this.elementRating.domRCN();
		this.elementRating.domSA({
			className: 'rating '+((ratingInt == 0) ? 'neu' : ((ratingInt > 0) ? 'pos' : 'neg' ))
		}).domCHTN(ratingStr);
		this.elementCellRating.domRCN();
		this.elementCellRating.domAC(
			domCE('p').domSA({
				className: ((ratingInt == 0) ? 'neu' : ((ratingInt > 0) ? 'pos' : 'neg' ))
			}).domCTN(((ratingInt == 0)
				? String.nbsp
				: ((ratingInt > 0) ?'+' : '' )+ratingInt
			))
		);
	},

	addVehicleWireComment: function(arguments, isNew){
		var isNew = (isNew || false);
		/*
		arguments: {
			userid:
			username:
			avatar:
			comment:
		}
		*/
		if(isNew){
			if(
				this.options.comments == undefined
				|| this.options.comments.length == undefined
			){
				this.options.comments = new Array();
				this.elementCommentList.domRCN();
			}
			this.options.comments[this.options.comments.length] = {};

			this.elementSpanRating.domRCN();
			this.elementSpanRating.domCTN(
				( this.options.comments == undefined )
					? '1'
					: this.options.comments.length
			);
		};

		if(arguments.userid == this.options.userid){
			var userIcon = new UserIcon({
				userid: arguments.userid,
				username: arguments.username,
				avatar: arguments.avatar,
				size: 32
			});
			this.elementCommentList.domAC(
				elementComment = domCE('p').domSA({
					className: 'comment'
				}).domAC(
					userIcon.element
				).domAC(
					eleComment = domCE('span').domCHTN('“'+arguments.comment+'”')
				)
			);
		}else{
			var userIcon = new UserIcon({
				userid: arguments.userid,
				username: arguments.username,
				avatar: arguments.avatar,
				size: 32
			});
			this.elementCommentList.domAC(
				elementComment = domCE('p').domSA({
					className: 'comment'
				}).setStyle({
					paddingLeft: '32px'
				}).domAC(
					userIcon.element
				).domAC(
					eleComment = domCE('span').domCHTN('“'+arguments.comment+'”')
				)
			);
		};
		if(arguments.lang != Language) onTranslateEvent.fire(eleComment, arguments.lang, Language);

		this.elementCommentList.show();
		if(isNew) elementComment.isNew();
	},



	submitComment: function(event){
		$(this.elementButtonSubmit.firstChild).addClassName('wait');
		Event.stopObserving(this.elementButtonSubmit, "click", this.eventSubmitComment);
		this.elementErrorComments.domRCN();
		this.httppost = new HttpPost();
		this.httppost.requestXML(function(response){
			var XML = response.responseJSON.httppost;
			if(response.responseJSON.httppost['-errors'] == 0){
				//success
				this.elementInputComment.value = '';
				this.addVehicleWireComment({
					userid: session.user.userid,
					username: session.user.username,
					avatar: session.user.avatar,
					comment: response.responseJSON.httppost.comment.value
				}, true);
			}else{
				//failed
				this.elementErrorComments.show();
				Object.keys(XML).each(function(key){
					if(XML[key].error){
						this.elementErrorComments.domAC(
							domCE('p').domSA({ className: 'post_error' }).domCTN(lang('Error: ','Erreur: ')+XML[key].error)
						);
					}
				}.bind(this));
			};

			$(this.elementButtonSubmit.firstChild).removeClassName('wait');
			Event.observe(this.elementButtonSubmit, "click", this.eventSubmitComment);

		}.bind(this), [], {
			action: 'vehicle_wire_comment',
			vehiclewireid: this.options.vehiclewireid,
			comment: this.elementInputComment.value
		});
	},

	ratePositive: function(event){
		this.rate(1);
	},

	rateNegative: function(event){
		this.rate(-1);
	},

	rate: function(rating){
		this.httppost = new HttpPost();
		this.httppost.requestXML(function(response){
			var XML = response.responseJSON.httppost;
			if(response.responseJSON.httppost['-errors'] == 0){
				//success
				this.options.rated_p = ((XML['rate'].value == 1) ? true : false);
				this.options.rated_n = ((XML['rate'].value == -1) ? true : false);

				this.buttonThumbUp.removeClassName( ((this.options.rated_p) ? 'unrated' : 'rated' ) );
				this.buttonThumbUp.addClassName( ((this.options.rated_p) ? 'rated' : 'unrated' ) );
				this.buttonThumbDown.removeClassName( ((this.options.rated_n) ? 'unrated' : 'rated' ) );
				this.buttonThumbDown.addClassName( ((this.options.rated_n) ? 'rated' : 'unrated' ) );

				if(parseInt(XML['rate'].value) > 0 || this.options.rating_p != XML['rating_p'].value){
					this.options.rating_p = XML['rating_p'].value;
					this.drawRating();
					this.AnimPin = new YAHOO.util.Anim(this.buttonThumbUp, {
						opacity: { to: 1 }
					}, .25, YAHOO.util.Easing.easeNone);
					this.AnimPout = new YAHOO.util.Anim(this.buttonThumbUp, {
						opacity: { to: 0 }
					}, .25, YAHOO.util.Easing.easeNone);
					this.AnimPout.onComplete.subscribe(function(){
						this.numThumbUp.domRCN().domCTN(((this.options.rating_p > 0) ?'+'+this.options.rating_p:String.nbsp))
						this.AnimPin.animate();
					}.bind(this));
					this.AnimPout.animate();
				};

				if(parseInt(XML['rate'].value) < 0 || this.options.rating_n != XML['rating_n'].value){
					this.options.rating_n = XML['rating_n'].value;
					this.drawRating();
					this.AnimNin = new YAHOO.util.Anim(this.buttonThumbDown, {
						opacity: { to: 1 }
					}, .25, YAHOO.util.Easing.easeNone);
					this.AnimNout = new YAHOO.util.Anim(this.buttonThumbDown, {
						opacity: { to: 0 }
					}, .25, YAHOO.util.Easing.easeNone);
					this.AnimNout.onComplete.subscribe(function(){
						this.numThumbDown.domRCN().domCTN(((this.options.rating_n > 0) ?'-'+this.options.rating_n:String.nbsp))
						this.AnimNin.animate();
					}.bind(this));
					this.AnimNout.animate();
				};
			}else{
				//failed
			};
		}.bind(this), [], {
			action: 'vehicle_wire_rate',
			vehiclewireid: this.options.vehiclewireid,
			rate: rating
		});
	}
});

VehicleWireImage = Class.create();
Object.extend(VehicleWireImage.prototype, {
	initialize: function(parent, arguments){
		this.parent = parent;
		this.options = Object.extend({
			imageid: 0,
			vehicleimageid: 0,
			host: 'image-new.wirecolor.com',
			md5sum: '',
			aspectratio: 1,
			x: 0,
			y: 0
		}, (arguments || {}));

		this.scale = 75;

		this.element = domCE('div').domSA({
			className: 'photo'
		}).domAC(
			domCE('img').domSA({
				src: 'http://'+this.options.host+'/thumb/'+this.options.md5sum+'.jpg',
				height: ((this.options.aspectratio >= 1.00) ? this.scale : (this.scale / this.options.aspectratio) ),
				width: ((this.options.aspectratio >= 1.00) ? (this.scale * this.options.aspectratio) : this.scale )
			})
		);
		this.eventMouseOver   = this.mouseOver.bindAsEventListener(this);
		Event.observe(this.element, "mouseover", this.eventMouseOver);
	},

	mouseOver: function(event){
		Event.stopObserving(this.element, "mouseover", this.eventMouseOver);
		new Thumb(this.element, this.options.vehicleimageid, 'http://'+this.options.host+'/thumb/'+this.options.md5sum+'.jpg');
		onImageEvent.fire('registerButton', this.element, this.options.vehicleimageid);
	}
});

UserIcon = Class.create();
Object.extend(UserIcon.prototype, {
	initialize: function(arguments){
		this.options = Object.extend({
			userid: 0,
			username: 'unknown',
			avatar: 'blank',
			size: 32,
			style: {}
		}, (arguments || {}));

		this.element = domCE('img').setStyle(this.options.style).domSA({
			className: 'avatar',
			src: ((this.options.avatar != undefined) ? 'http://www.doppelme.com/TRANSPARENT/'+this.options.size+'/'+this.options.avatar+'/crop.png' : '/images/icons/'+this.options.size+'x'+this.options.size+'_avatar.png'),
			height: this.options.size,
			width: this.options.size
		});

		new UserToolTip(this.element, this.options);
	}
});

UserToolTip = Class.create();
Object.extend(UserToolTip.prototype, {
	initialize: function(element, arguments){
		this.element = element;
		this.options = Object.extend({
			userid: 0
		}, (arguments || {}));
		this.rendered = false;
		this.eventMouseOver   = this.mouseOver.bindAsEventListener(this);
		Event.observe(this.element, "mouseover", this.eventMouseOver);
	},

	mouseOver: function(event){
		Event.stopObserving(this.element, "mouseover", this.eventMouseOver);
		this.render();
	},

	render: function(event){
		if(this.rendered) return;

		this.ajax = new Ajax();
		this.ajax.url = XMLUser+'?userid='+this.options.userid;
		this.ajax.caching = true;
		this.ajax.requestXML(function(response){
			var user = response.responseJSON.user;

			this.tooltip = new Tooltip();
			this.tooltip.initTooltip();
			this.tooltip.registerTooltipElement(this.element);
			this.tooltip.registerTooltipTitle(
				domCE('div').domAC(
					this.elementTooltipTitle = domCE('h4').setStyle({width: '235px' }).domSA({
						className: 'tooltiptitle'
					}).domAC(
						domCE('img').domSA({
							src: ((typeof user.avatar == 'undefined') ? 'http://www.doppelme.com/blank/crop.gif' : 'http://www.doppelme.com/TRANSPARENT/48/'+this.options.avatar+'/crop.png'),
							height: 48,
							width: 48,
							align: 'left'
						})
					).domAC(
						domCE('p').domAC(
							domCTN(user.username)
						)
					)
				)
			);
			this.tooltip.registerTooltipBody(
				domCE('div').domAC(
					this.elementTooltipBody = domCE('p').setStyle({width: '235px'}).domSA({
						className: 'tooltipbody'
					}).domAC(
						this.elementDetails = domCE('div').setStyle({
							textAlign: 'center'
						})
					)
				)
			);
			this.tooltip.showTooltip(event);
			if(typeof user.businessname != 'undefined'){
				this.elementTooltipTitle.domAC(
					domCE('p').domCTN(user.businessname)
				);
			}
			if(typeof user.city != 'undefined' || typeof user.province != 'undefined' || typeof user.country != 'undefined'){
				this.elementTooltipTitle.domAC(
					domCE('p').domCTN(
						((typeof user.city != 'undefined') ? user.city+', ' : '')
						+((typeof user.province != 'undefined') ? user.province+', ' : '')
						+((typeof user.country != 'undefined') ? user.country : '')
					)
				);
			}
			if(
				typeof user.stats != 'undefined'
				&& typeof user.stats.vehiclemakes != 'undefined'
				&& typeof user.stats.vehiclemakes.vehiclemake != 'undefined'
			){
				var vehiclemakes = (user.stats.vehiclemakes.vehiclemake.length == undefined)
					? [user.stats.vehiclemakes.vehiclemake]
					: user.stats.vehiclemakes.vehiclemake;
				var chd = new Array();
				var chdl = new Array();
				var chco = new Array();
				var colors = ['FF0000','0000FF','00FF00','FFFF00','FF8800','BDBDBD'];
				vehiclemakes.each(function(vehiclemake, index){
					chd.push(vehiclemake['-per']);
					chdl.push(vehiclemake['#cdata-section']);
					chco.push(colors[index]);
				}.bind(this));
				this.elementDetails.domAC(
					domCE('img').domSA({
						src: 'http://chart.apis.google.com/chart\
							?chs=230x125\
							&cht=p3\
							&chco='+chco.join(',')+'\
							&chd=t:'+chd.join(',')+'\
							&chdl='+chdl.join('|')+'\
							&chdlp=l\
							&chp=0\
							&chtt=Vehicle+Expertise\
							&chts=676767,12\
						'
					})
				);
			};

			this.elementDetails.domAC( domCTN(String.nbsp) );
		}.bind(this));
		this.rendered = true;
	}
});



var onFlashEvent = new YAHOO.util.CustomEvent("Flash");
getURL = function(obj){
	onFlashEvent.fire('getURL');
};

registerFile = function (element, fileid, isPreview){
	try{
		element.onmouseover = function(){ };
		element.domRA('onMouseOver');
	}catch(e){ };
	new File(element, fileid, isPreview);
};

File = Class.create();
Object.extend(File.prototype, {

	initialize: function(element, fileid, isPreview) {
		this.element = element;
		this.fileid = fileid;
		this.isPreview = isPreview || false;
		this.focus = true;

		this.eventMouseOver  = this.over.bindAsEventListener(this);
		Event.observe(this.element, "mouseover", this.eventMouseOver);
		this.eventMouseOut   = this.out.bindAsEventListener(this);
		Event.observe(this.element, "mouseout", this.eventMouseOut);

		this.ajax = new Ajax();
		this.ajax.url = XMLFile+'?fileid='+this.fileid;
		this.ajax.caching = true;
		this.ajax.requestXML(function(response){
			if(typeof response.responseJSON == 'undefined') return;
			if(typeof response.responseJSON.files == 'undefined') return;
			if(typeof response.responseJSON.files.category == 'undefined') return;

			var category = response.responseJSON.files.category;
			var file = category.file;

			this.tooltip = new Tooltip();
			this.tooltip.initTooltip();
			this.tooltip.registerTooltipElement(this.element);

			this.element.setStyle('cursor:help;');

			this.tooltip.registerTooltipTitle(
				domCE('div').domAC(
					domCE('img').domSA({
						src: ((this.isPreview)
							? '/images/extensions/preview.png'
							: '/images/extensions/'+file.extension+'.png'
						),
						align: 'left'
					})
				).domAC(
					domCE('h4').setStyle({width: '235px' }).domSA({
						className: 'tooltiptitle'
					}).domAC(
						domCE('p').domAC(
							domCTN((this.isPreview)
								? lang('Preview File','Fichier d\'aperçu')
								: lang('Download File','Téléchargement de Fichier')
							)
						)
					)
				)
			);

			this.tooltip.registerTooltipBody(
				domCE('div').domAC(
					domCE('p').setStyle({width: '235px'}).domSA({
						className: 'tooltipbody'
					}).domAC(
						this.tooltipBody = domCE('p')
					)
				)
			);

			this.tooltipBody.domAC(
				domCE('h2').domCHTN((this.isPreview && typeof file.pages['-num'] != 'undefined')
					? file.pages['-num']+' pages'
					: file.size.humanbytes()
				)
			);

			if(file.extension == 'pdf'){

				this.image = new Image();
				Event.observe(this.image, "load", function(){
					this.tooltip.moveTooltip();
				}.bind(this));
				this.image.src = 'http://ifar.ca/images/gen/pdf/'+this.fileid+'.jpg';

				this.tooltipBody.domAC(
					domCE('div').setStyle({
						width: '235px',
						clear: 'both'
					}).domSA({
						align: 'center'
					}).domAC(
						this.image
					)
				);

			}else{
				if(lang(category.description_en, category.description_fr)){
					this.tooltipBody.domAC(
						domCE('br')
					).domAC(
						domCE('p').domCHTN(lang(category.description_en, category.description_fr).nl2br())
					);
				};

				if(lang(file.description_en, file.description_fr)){
					this.tooltipBody.domAC(
						domCE('br')
					).domAC(
						domCE('p').domCHTN(lang(file.description_en, file.description_fr).nl2br())
					);
				};
			};

			this.tooltipBody.domAC(
				domCE('br')
			).domAC(
				domCE('p').setStyle({
					color: '#ff0000',
					fontStyle: 'italic'
				}).domSA({
					align: 'center'
				}).domCTN((this.isPreview)
					? lang('Click to preview','Cliquez pour un aperçu')
					: lang('Click to download','Cliquez pour télécharger')
				)
			);

			if(this.focus) this.tooltip.showTooltip();

			Event.stopObserving(this.element, "mouseover", this.eventMouseOver);
			Event.stopObserving(this.element, "mouseout", this.eventMouseOut);

		}.bind(this));
	},

	over: function(event){
		this.focus = true;
	},

	out: function(event){
		this.focus = false;
	}
});
