window.addEvent("domready", function () {

	vimeoGalleries = $$("body")[0].getElements("a[href^=http:\/\/www.vimeo.com\/]")
	
	vimeoGalleries.each(
		
		function (el) {
			//alert(el.get("class").indexOf("video") == -1)
			if(el.get("class").indexOf("video") == -1 && el.get("class").indexOf("launch") == -1) {
				var setid = el.get("href").split("/");
				setid = setid[1];
				
				var w = 605;
				var h = 385;
				
				if (el.getParent("div[id=event-review]")) {
					w = 570;
					h = 360;
					}
				
				new Request.JSON({
					url : "videos.cfm?http://vimeo.com/api/oembed.json?url=" + escape(el.get("href")) + "&amp;width=443&amp;height=281&amp;title=" + el.get("title") + "&amp;autoplay=false",
					onSuccess : function (response) {
						if(response != null) {
							var code = response.html;
							code = code.replace("<object", "<object type=\"application/x-shockwave-flash\" classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\"");
							new Element("div").set("html", code.replace(response.height, h).replace(response.width, w)).replaces(el)
							}
						}
					}).get({})
				
				}
			
			if(el.get("class").indexOf("launch") != -1) {
				el.removeProperty("onclick");
				el.addEvent("click", function (ev) {
					ev.stop();
					if (!$("site-mask")) {
						mask = new Mask({
							title	: "Mardi Gras Video",
							type 	: "panel",
							size 	: "large",
							url 	: "videos.cfm?http://vimeo.com/api/oembed.json?url=" + escape(el.get("href")) + "&amp;width=443&amp;height=281&amp;title=" + el.get("title") + "&amp;autoplay=false&amp;just-output",
							buttons	: [{label:"Close",id: "close-mask"}]
							}).create();
						}
					});
				}
				
			}
		
		)
	});
	
window.addEvent("load", function () {	
	
	if($("video-menu-scroller")) {
		$("video-menu-scroller").getElements("a[class^=video]").each(
			function (el) {
				el.addEvent("click", function (ev) {
					ev.stop();
					$("video").set("html", "");
					new Request.JSON({
						url : "videos.cfm?" + el.get("href"),
						onSuccess : function (response) {
							if(response != null) {
								$("video").set("html", response.html);
								$("video").set("html", response.html.replace(response.height, "281").replace(response.width, "443"));
								}
							//$("video").getElement("object").setProperty("height", "281");
							//$("video").getElement("object").setProperty("width", "443");
							}
						}).get({}); // end request
					}); // end event
				} // end function
			); // end each
		}
	if($("gallery-features")) {
		$("gallery-features").getElements("a[class^=video]").each(
			function (el) {
				el.addEvent("click", function (ev) {
					ev.stop();
					$("video").inject(el.getParent("div").getPrevious(), "after");
					$("video").set("html", "");
					new Request.JSON({
						url : "videos.cfm?" + el.get("href"),
						onSuccess : function (response) {
							if(response != null) {
								$("video").set("html", response.html.replace(response.height, "385").replace(response.width, "605"));
								}
							//$("video").getElement("object").setProperty("height", "385");
							//$("video").getElement("object").setProperty("width", "605");

							}
						}).get({}); // end request
					}); // end event
				} // end function
			); // end each
		}
	});