
window.addEvent('domready', function() {

	var GalleryContainer = $("GalleryContainer");
	GalleryContainer.Content = $("GalleryContent");
	GalleryContainer.setStyles({
		'display': 'none'
	});
	$("CloseGalleryLink").addEvent('click', function() {
		GalleryContainer.setStyle('display', 'none');
	});

	var ThumbnailPreview = new Element("div", {
		id: "ThumbnailPreview"
	});

	window.ShowGallery = function(index, xmlPath) {
		var ws = window.getSize();
		var w = ws.x - 20;
		var h = ws.y - 20;
		var wp = window.getScroll();

		GalleryContainer.setStyles({
			'width': w,
			'height': h,
			'top': wp.y + 10,
			'left': wp.x + 10
		});

		GalleryContainer.Content.empty();
		GalleryContainer.Content.adopt(new Swiff('Swf/Viewer.swf', {
			width: w,
			height: h,
			id: 'viewer',
			vars: {
				'xmlDataPath': xmlPath,
				'preloaderColor': '0xffffff',
				'firstImageIndex': index
			}
		}));

		GalleryContainer.setStyle('display', 'block');	
	
	}

	ThumbnailPreview.inject(document.body, "bottom");

	var LinkMouseOver = function() {

		var pos = this.getPosition();
		ThumbnailPreview.setStyles({
			"left": (pos.x + 30) + "px",
			"top": (pos.y - 50) + "px",
			"background-image": "url(" + this.ImageLink + ")",
			"display": "block"
		});
	};

	var LinkMouseOut = function() {
		ThumbnailPreview.setStyles({
			"background-image": "none",
			"display": "none"
		});
	};

	var LinkMouseClick = function() {

		ShowGallery(this.index);

	};

	$$("a.VehicleImage").each(function(link, index) {
		link.ImageLink = link.getElement("input").get("value");//href;
		//link.href = "javascript:void(0);";
		link.index = index;
		link.addEvent("mouseenter", LinkMouseOver);
		link.addEvent("mouseleave", LinkMouseOut);
		//link.addEvent("click", LinkMouseClick);

		if (Browser.Engine.trident4) {
			link.getElement("img").setStyle("visibility", "hidden");
			var img = link.getElement("img");
			var src = img.get("src");
			img.set({
				"src": "Images/Blank.gif",
				"width": "16",
				"height": "16"
			});
			window.status = src;
			link.setStyles({
				"height": "16px",
				"width": "16px",
				"background": "url(" + link.ImageLink + ") 50% 50% no-repeat"
			});
		}

	});

});

        