/*
mediaboxAdvanced v1.5.4 - The ultimate extension of Slimbox and Mediabox; an all-media script
updated 2011.2.19
	(c) 2007-2011 John Einselen - http://iaian7.com
based on Slimbox v1.64 - The ultimate lightweight Lightbox clone
	(c) 2007-2008 Christophe Beyls - http://www.digitalia.be

description: The ultimate extension of Slimbox and Mediabox; an all-media script

license: MIT-style

authors:
- John Einselen
- Christophe Beyls
- Contributions from many others

requires:
- core/1.3.2: [Core, Array, String, Number, Function, Object, Event, Browser, Class, Class.Extras, Slick.*, Element.*, FX.*, DOMReady, Swiff]
- Quickie/2.1: '*'

provides: [Mediabox.open, Mediabox.close, Mediabox.recenter, Mediabox.scanPage]
*/


var Mediabox = new Class({
	Implements : [Events, Options],
	options    : {
//	Text options (translate as needed)
		buttonText: ['<big>&laquo;</big>','<big>&raquo;</big>','<big>Schlie&szlig;en</big>'],		// Array defines "previous", "next", and "close" button content (HTML code should be written as entity codes or properly escaped)
//		buttonText: ['<big>«</big>','<big>»</big>','<big>×</big>'],
//		buttonText: ['<b>P</b>rev','<b>N</b>ext','<b>C</b>lose'],
		counterText: '({x} of {y})',	// Counter text, {x} = current item number, {y} = total gallery length
		linkText: '<a href="{x}" target="_new">{x}</a><br/>open in a new tab</div>',	// Text shown on iOS devices for non-image links
		flashText: '<b>Error</b><br/>Adobe Flash is either not installed or not up to date, please visit <a href="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" title="Get Flash" target="_new">Adobe.com</a> to download the free player.',	// Text shown if Flash is not installed.
//	General overlay options
		center: true,					// Set to false for use with custom CSS layouts
		loop: false,					// Navigate from last to first elements in a gallery
		keyboard: true,					// Enables keyboard control; escape key, left arrow, and right arrow
		keyboardAlpha: false,			// Adds 'x', 'c', 'p', and 'n' when keyboard control is also set to true
		keyboardStop: false,			// Stops all default keyboard actions while overlay is open (such as up/down arrows)
										// Does not apply to iFrame content, does not affect mouse scrolling
		overlayOpacity: 0.8,			// 1 is opaque, 0 is completely transparent (change the color in the CSS file)
		resizeOpening: true,			// Determines if box opens small and grows (true) or starts at larger size (false)
		resizeDuration: 240,			// Duration of each of the box resize animations (in milliseconds)
		initialWidth: 320,				// Initial width of the box (in pixels)
		initialHeight: 180,				// Initial height of the box (in pixels)
		defaultWidth: 640,				// Default width of the box (in pixels) for undefined media (MP4, FLV, etc.)
		defaultHeight: 360,				// Default height of the box (in pixels) for undefined media (MP4, FLV, etc.)
		showCaption: true,				// Display the title and caption, true / false
		showCounter: true,				// If true, a counter will only be shown if there is more than 1 image to display
		countBack: false,				// Inverts the displayed number (so instead of the first element being labeled 1/10, it's 10/10)
		clickBlock: true,				// Adds an event on right-click to block saving of images from the context menu in most browsers (this can't prevent other ways of downloading, but works as a casual deterent)
//	iOS device options
//		iOSenable: false,				// When set to false, disables overlay entirely (links open in new tab)
										// IMAGES and INLINE content will display normally,
										// while ALL OTHER content will display a direct link (this is required so as to not break mixed-media galleries)
		iOShtml: true,					// If set to true, HTML content is displayed normally as well (useful if your HTML content is minimal and UI oriented instead of external sites)
//	Image options
		imgBackground: false,		// Embed images as CSS background (true) or <img> tag (false)
									// CSS background is naturally non-clickable, preventing downloads
									// IMG tag allows automatic scaling for smaller screens
									// (all images have no-click code applied, albeit not Opera compatible. To remove, comment lines 212 and 822)
		imgPadding: 100,			// Clearance necessary for images larger than the window size (only used when imgBackground is false)
									// Change this number only if the CSS style is significantly divergent from the original, and requires different sizes
//	Inline options
		overflow: 'auto',			// If set, overides CSS settings for inline content only, set to "false" to leave CSS settings intact.
		inlineClone: false,			// Clones the inline element instead of moving it from the page to the overlay
//	Global media options
		html5: 'true',				// HTML5 settings for YouTube and Vimeo, false = off, true = on
		scriptaccess: 'true',		// Allow script access to flash files
		fullscreen: 'true',			// Use fullscreen
		fullscreenNum: '1',			// 1 = true
		autoplay: 'true',			// Plays the video as soon as it's opened
		autoplayNum: '1',			// 1 = true
		autoplayYes: 'yes',			// yes = true
		volume: '100',				// 0-100, used for NonverBlaster and Quicktime players
		medialoop: 'true',			// Loop video playback, true / false, used for NonverBlaster and Quicktime players
		bgcolor: '#000000',			// Background color, used for flash and QT media
		wmode: 'transparent',			// Background setting for Adobe Flash ('opaque' and 'transparent' are most common)
//	NonverBlaster
		playerpath: '/js/NonverBlaster.swf',	// Path to NonverBlaster.swf
		showTimecode: 'false',		// turn timecode display off or on (true, false)
		controlColor: '0xFFFFFF',	// set the control color
		controlBackColor: '0x0000000',	// set the bakcground color (video only)
//		playerBackColor: '0x0000FF',	// set the player background color (leave blank to allow CSS styles to show through for audio)
		playerBackColor: '',	// set the player background color (leave blank to allow CSS styles to show through)
		wmodeNB: 'transparent',			// Background setting for Adobe Flash (set to 'transparent' for a blank background, 'opaque' in other situations)
//		autoAdvance: 'false',		// placeholder setting only - not currently implemented (intending to add auto gallery list navigation on play-end)
//	Quicktime options
		controller: 'true',			// Show controller, true / false
//	Flickr options
		flInfo: 'true',				// Show title and info at video start
//	Revver options
		revverID: '187866',			// Revver affiliate ID, required for ad revinue sharing
		revverFullscreen: 'true',	// Fullscreen option
		revverBack: '000000',		// Background color
		revverFront: 'ffffff',		// Foreground color
		revverGrad: '000000',		// Gradation color
//	Ustream options
		usViewers: 'true',			// Show online viewer count (true, false)
//	Youtube options
		ytBorder: '0',				// Outline				(1=true, 0=false)
		ytColor1: '000000',			// Outline color
		ytColor2: '333333',			// Base interface color (highlight colors stay consistent)
		ytRel: '0',					// Show related videos	(1=true, 0=false)
		ytInfo: '1',				// Show video info		(1=true, 0=false)
		ytSearch: '0',				// Show search field	(1=true, 0=false)
//	Viddyou options
		vuPlayer: 'basic',			// Use 'full' or 'basic' players
//	Vimeo options
		vmTitle: '1',				// Show video title
		vmByline: '1',				// Show byline
		vmPortrait: '1',			// Show author portrait
		vmColor: 'ffffff'			// Custom controller colors, hex value minus the # sign, defult is 5ca0b5
	},
	mediaArray: null,
	activeMedia: null,
	prevMedia: null,
	nextMedia: null,
	top: null,
	mTop: null,
	left: null,
	mLeft: null,
	winWidth: null,
	winHeight: null,
	fx: null,
	preload: null,
	preloadPrev: new Image(),
	preloadNext: new Image(),
	overlay: null,
	center: null,
	media: null,
	bottom: null,
	captionSplit: null,
	title: null,
	caption: null,
	number: null,
	prevLink: null,
	nextLink: null,
	URL: null,
	WH: null,
	WHL: null,
	elrel: null,
	mediaWidth: null,
	mediaHeight: null,
	mediaType: "none",
	mediaSplit: null,
	mediaId: "mediaBox",
	margin: null,
	marginBottom: null,
	initialize: function(options) {
		this.setOptions(options);
		/*document.id(document.body).adopt(
			$$([
				this.overlay = new Element("div", {id: "mbOverlay"}).addEvent("click", this.close.bind(this)),
				this.center = new Element("div", {id: "mbCenter"})
			]).setStyle("display", "none")
		);
		*/
		this.overlay = new Element("div", {'id': 'mbOverlay','style':'display:none'}).addEvent("click", this.close.bind(this));
		this.center = new Element("div", {'id': 'mbCenter','style':'display:none'});
		$$('body')[0].adopt(this.overlay);
		$$('body')[0].adopt(this.center);
		
		this.container = new Element('div', {'id': 'mbContainer'}).inject(this.center, 'inside');
		this.media = new Element("div", {id: "mbMedia"}).inject(this.container, "inside");
		this.bottom = new Element("div", {id: "mbBottom"}).inject(this.center, "inside").adopt(
			this.closeLink = new Element("a", {id: "mbCloseLink", href: "#"}).addEvent("click", this.close.bind(this)),
			this.nextLink = new Element("a", {id: "mbNextLink", href: "#"}).addEvent("click", this.next.bind(this)),
			this.prevLink = new Element("a", {id: "mbPrevLink", href: "#"}).addEvent("click", this.previous.bind(this)),
			this.title = new Element("div", {id: "mbTitle"}),
			this.number = new Element("div", {id: "mbNumber"}),
			this.caption = new Element("div", {id: "mbCaption"})
		);
	
		this.fx = {
			overlay: new Fx.Tween(this.overlay, {property: "opacity", duration: 360}).set(0),
			media: new Fx.Tween(this.media, {property: "opacity", duration: 360, onComplete:  this.captionAnimate.bind(this)}),
			bottom: new Fx.Tween(this.bottom, {property: "opacity", duration: 240}).set(0)
		};
	},

	recenter: function(){	// Thanks to Garo Hussenjian (Xapnet Productions http://www.xapnet.com) for suggesting this addition
		if (this.center && !Browser.Platform.ios) {
			this.left = window.getScrollLeft() + (window.getWidth()/2);
			this.center.setStyles({left: this.left, marginLeft: -(this.mediaWidth/2)-this.margin});
		}
	},

	open: function(_mediaArray, startMedia, _options) {
		this.prevLink.set('html', this.options.buttonText[0]);
		this.nextLink.set('html', this.options.buttonText[1]);
		this.closeLink.set('html', this.options.buttonText[2]);

		if (Browser.firefox2) {	// Fixes Firefox 2 and Camino 1.6 incompatibility with opacity + flash
			this.options.overlayOpacity = 1;
			this.overlay.className = 'mbOverlayOpaque';
		}

		if (Browser.Platform.ios) {
			this.options.keyboard = false;
			this.options.resizeOpening = false;	// Speeds up interaction on small devices (mobile) or older computers (IE6)
			this.overlay.className = 'mbMobile';
			this.bottom.className = 'mbMobile';
			this.position();
		}

		if (Browser.ie6) {
			this.options.resizeOpening = false;	// Speeds up interaction on small devices (mobile) or older computers (IE6)
			this.overlay.className = 'mbOverlayAbsolute';
			this.position();
		}

		if (typeof _mediaArray == "string") {	// Used for single mediaArray only, with URL and Title as first two arguments
			_mediaArray = [[_mediaArray,startMedia,_options]];
			startMedia = 0;
		}

		this.mediaArray = _mediaArray;
		this.options.loop = this.options.loop && (this.mediaArray.length > 1);

		this.size();
		this.setup(true);
		this.top = window.getScrollTop() + (window.getHeight()/2);
		this.left = window.getScrollLeft() + (window.getWidth()/2);
		this.margin = this.center.getStyle('padding-left').toInt()+this.media.getStyle('margin-left').toInt()+this.media.getStyle('padding-left').toInt();
		this.marginBottom = this.bottom.getStyle('margin-left').toInt()+this.bottom.getStyle('padding-left').toInt()+this.bottom.getStyle('margin-right').toInt()+this.bottom.getStyle('padding-right').toInt();

		this.center.setStyles({top: this.top, left: this.left, width: this.options.initialWidth, height: this.options.initialHeight, marginTop: -(this.options.initialHeight/2)-this.margin, marginLeft: -(this.options.initialWidth/2)-this.margin, display: ""});
		this.fx.resize = new Fx.Morph(this.center, {duration: this.options.resizeDuration, onComplete: this.mediaAnimate.bind(this)});
		this.fx.overlay.start(this.options.overlayOpacity);
		return this.changeMedia(startMedia);
	},
	position:function() {
		this.overlay.setStyles({top: window.getScrollTop(), left: window.getScrollLeft()});
	},
	size:function() {
		this.winWidth = window.getWidth();
		this.winHeight = window.getHeight();
		this.overlay.setStyles({width: this.winWidth, height: this.winHeight});
	},
	setup:function(open) {
		// Hides on-page objects and embeds while the overlay is open, nessesary to counteract Firefox stupidity
		if (Browser.firefox) {
			["object", window.ie ? "select" : "embed"].forEach(function(tag) {
				Array.forEach($$(tag), function(el) {
					if (open) el._mediabox = el.style.visibility;
					el.style.visibility = open ? "hidden" : el._mediabox;
				});
			});
		}

		this.overlay.style.display = open ? "" : "none";

		var fn = open ? "addEvent" : "removeEvent";
		if (Browser.Platform.ios || Browser.ie6) window[fn]("scroll", this.position);	// scroll position is updated only after movement has stopped
		window[fn]("resize", this.size.bind(this));
		if (this.options.keyboard) document[fn]("keydown", this.keyDown.bind(this));
	},
	keyDown:function(event) {
		if (this.options.keyboardAlpha) {
			switch(event.code) {
				case 27:	// Esc
				case 88:	// 'x'
				case 67:	// 'c'
					this.close().bind(this);
					break;
				case 37:	// Left arrow
				case 80:	// 'p'
					this.previous().bind(this);
					break;
				case 39:	// Right arrow
				case 78:	// 'n'
					this.next().bind(this);
			}
		} else {
			switch(event.code) {
				case 27:	// Esc
					this.close().bind(this);
					break;
				case 37:	// Left arrow
					this.previous().bind(this);
					break;
				case 39:	// Right arrow
					this.next().bind(this);
			}
		}
		if (this.options.keyboardStop) { return false; };
	},
	previous:function() {
		return this.changeMedia(this.prevMedia);
	},
	next:function() {
		return this.changeMedia(this.nextMedia);
	},
	changeMedia:function(mediaIndex) {
		if (mediaIndex >= 0) {
			this.media.set('html', '');
			this.activeMedia = mediaIndex;
			this.prevMedia = ((this.activeMedia || !this.options.loop) ? this.activeMedia : this.mediaArray.length) - 1;
			this.nextMedia = this.activeMedia + 1;
			if (this.nextMedia == this.mediaArray.length) this.nextMedia = this.options.loop ? 0 : -1;
			this.stop();
			this.center.className = "mbLoading";
			if (this.preload && this.mediaType == "inline" && !this.options.inlineClone) 
				this.preload.adopt(this.media.getChildren());	// prevents loss of adopted data

	/*	mediaboxAdvanced link formatting and media support	*/

			if (!this.mediaArray[mediaIndex][2]) this.mediaArray[mediaIndex][2] = '';	// Thanks to Leo Feyer for offering this fix
			this.WH = this.mediaArray[mediaIndex][2].split(' ');
			this.WHL = this.WH.length;
			if (this.WHL>1) {
//				mediaWidth = (WH[WHL-2].match("%")) ? (window.getWidth()*((WH[WHL-2].replace("%", ""))*0.01))+"px" : WH[WHL-2]+"px";
				this.mediaWidth = (this.WH[this.WHL-2].match("%")) ? (window.getWidth()*((this.WH[this.WHL-2].replace("%", ""))*0.01)) : this.WH[this.WHL-2];
//				mediaHeight = (WH[WHL-1].match("%")) ? (window.getHeight()*((WH[WHL-1].replace("%", ""))*0.01))+"px" : WH[WHL-1]+"px";
				this.mediaHeight = (this.WH[this.WHL-1].match("%")) ? (window.getHeight()*((this.WH[this.WHL-1].replace("%", ""))*0.01)) : this.WH[this.WHL-1];
			} else {
				this.mediaWidth = "";
				this.mediaHeight = "";
			}
			this.URL = this.mediaArray[mediaIndex][0];
//			URL = encodeURI(URL).replace("(","%28").replace(")","%29");
//			URL = encodeURI(URL).replace("(","%28").replace(")","%29").replace("%20"," ");
			this.captionSplit = this.mediaArray[this.activeMedia][1].split('::');

// Quietube and yFrog support
			if (this.URL.match(/quietube\.com/i)) {
				this.mediaSplit = this.URL.split('v.php/');
				this.URL = this.mediaSplit[1];
			} else if (this.URL.match(/\/\/yfrog/i)) {
				this.mediaType = (this.URL.substring(this.URL.length-1));
				if (this.mediaType.match(/b|g|j|p|t/i)) this.mediaType = 'image';
				if (this.mediaType == 's') this.mediaType = 'flash';
				if (this.mediaType.match(/f|z/i)) this.mediaType = 'video';
				this.URL = this.URL+":iphone";
			}

	/*	Specific Media Types	*/

// GIF, JPG, PNG
			if (this.URL.match(/\.gif|\.jpg|\.jpeg|\.png|twitpic\.com/i) || this.mediaType == 'image') {
				this.mediaType = 'img';
				this.URL = this.URL.replace(/twitpic\.com/i, "twitpic.com/show/full");
				this.preload = new Image();
				this.preload.onload = this.startEffect;
				this.preload.src = URL;
// FLV, MP4
			} else if (this.URL.match(/\.flv|\.mp4/i) || this.mediaType == 'video') {
				this.mediaType = 'obj';
				this.mediaWidth = this.mediaWidth || this.options.defaultWidth;
				this.mediaHeight = this.mediaHeight || this.options.defaultHeight;
				this.preload = new Swiff(''+this.options.playerpath+'?mediaURL='+this.URL+'&allowSmoothing=true&autoPlay='+this.options.autoplay+'&buffer=6&showTimecode='+this.options.showTimecode+'&loop='+this.options.medialoop+'&controlColor='+this.options.controlColor+'&controlBackColor='+this.options.controlBackColor+'&playerBackColor='+this.options.playerBackColor+'&defaultVolume='+this.options.volume+'&scaleIfFullScreen=true&showScalingButton=true&crop=false', {
					id: 'mbVideo',
					width: this.mediaWidth,
					height: this.mediaHeight,
					params: {wmode: this.options.wmodeNB, bgcolor: this.options.bgcolor, allowscriptaccess: this.options.scriptaccess, allowfullscreen: this.options.fullscreen}
					});
				this.startEffect();
// MP3, AAC
			} else if (this.URL.match(/\.mp3|\.aac|tweetmic\.com|tmic\.fm/i) || this.mediaType == 'audio') {
				this.mediaType = 'obj';
				this.mediaWidth = this.mediaWidth || this.options.defaultWidth;
				this.mediaHeight = this.mediaHeight || "17";
				if (this.URL.match(/tweetmic\.com|tmic\.fm/i)) {
					this.URL = this.URL.split('/');
					this.URL[4] = this.URL[4] || this.URL[3];
					this.URL = "http://media4.fjarnet.net/tweet/tweetmicapp-"+this.URL[4]+'.mp3';
				}
				this.preload = new Swiff(''+this.options.playerpath+'?mediathis.URL='+this.URL+'&allowSmoothing=true&autoPlay='+this.options.autoplay+'&buffer=6&showTimecode='+this.options.showTimecode+'&loop='+this.options.medialoop+'&controlColor='+this.options.controlColor+'&controlBackColor='+this.options.controlBackColor+'&defaultVolume='+this.options.volume+'&scaleIfFullScreen=true&showScalingButton=true&crop=false', {
					id: 'mbAudio',
					width: this.mediaWidth,
					height: this.mediaHeight,
					params: {wmode: this.options.wmode, bgcolor: this.options.bgcolor, allowscriptaccess: this.options.scriptaccess, allowfullscreen: this.options.fullscreen}
					});
				this.startEffect();
// SWF
			} else if (this.URL.match(/\.swf/i) || this.mediaType == 'flash') {
				this.mediaType = 'obj';
				this.mediaWidth = this.mediaWidth || this.options.defaultWidth;
				this.mediaHeight = this.mediaHeight || this.options.defaultHeight;
				this.preload = new Swiff(this.URL, {
					id: 'mbFlash',
					width: this.mediaWidth,
					height: this.mediaHeight,
					params: {wmode: this.options.wmode, bgcolor: this.options.bgcolor, allowscriptaccess: this.options.scriptaccess, allowfullscreen: this.options.fullscreen}
					});
				this.startEffect();
// MOV, M4V, M4A, MP4, AIFF, etc.
			} else if (this.URL.match(/\.mov|\.m4v|\.m4a|\.aiff|\.avi|\.caf|\.dv|\.mid|\.m3u|\.mp3|\.mp2|\.mp4|\.qtz/i) || this.mediaType == 'qt') {
				this.mediaType = 'qt';
				this.mediaWidth = this.mediaWidth || this.options.defaultWidth;
//				this.mediaHeight = (parseInt(this.mediaHeight)+16)+"px" || this.options.defaultHeight;
				this.mediaHeight = (parseInt(this.mediaHeight)+16) || this.options.defaultHeight;
				this.preload = new Quickie(this.URL, {
					id: 'MediaboxQT',
					width: this.mediaWidth,
					height: this.mediaHeight,
					attributes: {controller: this.options.controller, autoplay: this.options.autoplay, volume: this.options.volume, loop: this.options.medialoop, bgcolor: this.options.bgcolor}
					});
				this.startEffect();

	/*	Social Media Sites	*/

// Blip.tv
			} else if (this.URL.match(/blip\.tv/i)) {
				this.mediaType = 'obj';
				this.mediaWidth = this.mediaWidth || "640";
				this.mediaHeight = this.mediaHeight || "390";
				this.preload = new Swiff(this.URL, {
					src: this.URL,
					width: this.mediaWidth,
					height: this.mediaHeight,
					params: {wmode: this.options.wmode, bgcolor: this.options.bgcolor, allowscriptaccess: this.options.scriptaccess, allowfullscreen: this.options.fullscreen}
					});
				this.startEffect();
// Break.com
			} else if (this.URL.match(/break\.com/i)) {
				this.mediaType = 'obj';
				this.mediaWidth = this.mediaWidth || "464";
				this.mediaHeight = this.mediaHeight || "376";
				this.mediaId = this.URL.match(/\d{6}/g);
				this.preload = new Swiff('http://embed.break.com/'+this.mediaId, {
					width: this.mediaWidth,
					height: this.mediaHeight,
					params: {wmode: this.options.wmode, bgcolor: this.options.bgcolor, allowscriptaccess: this.options.scriptaccess, allowfullscreen: this.options.fullscreen}
					});
				this.startEffect();
// DailyMotion
			} else if (this.URL.match(/dailymotion\.com/i)) {
				this.mediaType = 'obj';
				this.mediaWidth = this.mediaWidth || "480";
				this.mediaHeight = this.mediaHeight || "381";
				this.preload = new Swiff(this.URL, {
					id: this.mediaId,
					width: this.mediaWidth,
					height: this.mediaHeight,
					params: {wmode: this.options.wmode, bgcolor: this.options.bgcolor, allowscriptaccess: this.options.scriptaccess, allowfullscreen: this.options.fullscreen}
					});
				this.startEffect();
// Facebook
			} else if (this.URL.match(/facebook\.com/i)) {
				this.mediaType = 'obj';
				this.mediaWidth = this.mediaWidth || "320";
				this.mediaHeight = this.mediaHeight || "240";
				this.mediaSplit = this.URL.split('v=');
				this.mediaSplit = this.mediaSplit[1].split('&');
				this.mediaId = this.mediaSplit[0];
				this.preload = new Swiff('http://www.facebook.com/v/'+this.mediaId, {
					movie: 'http://www.facebook.com/v/'+this.mediaId,
					classid: 'clsid:D27CDB6E-AE6D-11cf-96B8-444553540000',
					width: this.mediaWidth,
					height: this.mediaHeight,
					params: {wmode: this.options.wmode, bgcolor: this.options.bgcolor, allowscriptaccess: this.options.scriptaccess, allowfullscreen: this.options.fullscreen}
					});
				this.startEffect();
// Flickr
			} else if (this.URL.match(/flickr\.com(?!.+\/show\/)/i)) {
				this.mediaType = 'obj';
				this.mediaWidth = this.mediaWidth || "500";
				this.mediaHeight = this.mediaHeight || "375";
				this.mediaSplit = this.URL.split('/');
				this.mediaId = this.mediaSplit[5];
				this.preload = new Swiff('http://www.flickr.com/apps/video/stewart.swf', {
					id: this.mediaId,
					classid: 'clsid:D27CDB6E-AE6D-11cf-96B8-444553540000',
					width: this.mediaWidth,
					height: this.mediaHeight,
					params: {flashvars: 'photo_id='+this.mediaId+'&amp;show_info_box='+this.options.flInfo, wmode: this.options.wmode, bgcolor: this.options.bgcolor, allowscriptaccess: this.options.scriptaccess, allowfullscreen: this.options.fullscreen}
					});
				this.startEffect();
// GameTrailers Video
			} else if (this.URL.match(/gametrailers\.com/i)) {
				this.mediaType = 'obj';
				this.mediaWidth = this.mediaWidth || "480";
				this.mediaHeight = this.mediaHeight || "392";
				this.mediaId = this.URL.match(/\d{5}/g);
				this.preload = new Swiff('http://www.gametrailers.com/remote_wrap.php?mid='+this.mediaId, {
					id: this.mediaId,
					width: this.mediaWidth,
					height: this.mediaHeight,
					params: {wmode: this.options.wmode, bgcolor: this.options.bgcolor, allowscriptaccess: this.options.scriptaccess, allowfullscreen: this.options.fullscreen}
					});
				this.startEffect();
// Google Video
			} else if (this.URL.match(/google\.com\/videoplay/i)) {
				this.mediaType = 'obj';
				this.mediaWidth = this.mediaWidth || "400";
				this.mediaHeight = this.mediaHeight || "326";
				this.mediaSplit = this.URL.split('=');
				this.mediaId = this.mediaSplit[1];
				this.preload = new Swiff('http://video.google.com/googleplayer.swf?docId='+this.mediaId+'&autoplay='+this.options.autoplayNum, {
					id: this.mediaId,
					width: this.mediaWidth,
					height: this.mediaHeight,
					params: {wmode: this.options.wmode, bgcolor: this.options.bgcolor, allowscriptaccess: this.options.scriptaccess, allowfullscreen: this.options.fullscreen}
					});
				this.startEffect();
// Megavideo - Thanks to Robert Jandreu for suggesting this code!
			} else if (this.URL.match(/megavideo\.com/i)) {
				this.mediaType = 'obj';
				this.mediaWidth = this.mediaWidth || "640";
				this.mediaHeight = this.mediaHeight || "360";
				this.mediaSplit = this.URL.split('=');
				this.mediaId = this.mediaSplit[1];
				this.preload = new Swiff('http://wwwstatic.megavideo.com/mv_player.swf?v='+this.mediaId, {
					id: this.mediaId,
					width: this.mediaWidth,
					height: this.mediaHeight,
					params: {wmode: this.options.wmode, bgcolor: this.options.bgcolor, allowscriptaccess: this.options.scriptaccess, allowfullscreen: this.options.fullscreen}
					});
				this.startEffect();
// Metacafe
			} else if (this.URL.match(/metacafe\.com\/watch/i)) {
				this.mediaType = 'obj';
				this.mediaWidth = this.mediaWidth || "400";
				this.mediaHeight = this.mediaHeight || "345";
				this.mediaSplit = this.URL.split('/');
				this.mediaId = this.mediaSplit[4];
				this.preload = new Swiff('http://www.metacafe.com/fplayer/'+this.mediaId+'/.swf?playerVars=autoPlay='+this.options.autoplayYes, {
					id: this.mediaId,
					width: this.mediaWidth,
					height: this.mediaHeight,
					params: {wmode: this.options.wmode, bgcolor: this.options.bgcolor, allowscriptaccess: this.options.scriptaccess, allowfullscreen: this.options.fullscreen}
					});
				this.startEffect();
// Myspace
			} else if (this.URL.match(/vids\.myspace\.com/i)) {
				this.mediaType = 'obj';
				this.mediaWidth = this.mediaWidth || "425";
				this.mediaHeight = this.mediaHeight || "360";
				this.preload = new Swiff(this.URL, {
					id: this.mediaId,
					width: this.mediaWidth,
					height: this.mediaHeight,
					params: {wmode: this.options.wmode, bgcolor: this.options.bgcolor, allowscriptaccess: this.options.scriptaccess, allowfullscreen: this.options.fullscreen}
					});
				this.startEffect();
// Revver
			} else if (this.URL.match(/revver\.com/i)) {
				this.mediaType = 'obj';
				this.mediaWidth = this.mediaWidth || "480";
				this.mediaHeight = this.mediaHeight || "392";
				this.mediaSplit = this.URL.split('/');
				this.mediaId = this.mediaSplit[4];
				this.preload = new Swiff('http://flash.revver.com/player/1.0/player.swf?this.mediaId='+this.mediaId+'&affiliateId='+this.options.revverID+'&allowFullScreen='+this.options.revverFullscreen+'&autoStart='+this.options.autoplay+'&backColor=#'+this.options.revverBack+'&frontColor=#'+this.options.revverFront+'&gradColor=#'+this.options.revverGrad+'&shareUrl=revver', {
					id: this.mediaId,
					width: this.mediaWidth,
					height: this.mediaHeight,
					params: {wmode: this.options.wmode, bgcolor: this.options.bgcolor, allowscriptaccess: this.options.scriptaccess, allowfullscreen: this.options.fullscreen}
					});
				this.startEffect();
// Rutube
			} else if (this.URL.match(/rutube\.ru/i)) {
				this.mediaType = 'obj';
				this.mediaWidth = this.mediaWidth || "470";
				this.mediaHeight = this.mediaHeight || "353";
				this.mediaSplit = this.URL.split('=');
				this.mediaId = this.mediaSplit[1];
				this.preload = new Swiff('http://video.rutube.ru/'+this.mediaId, {
					movie: 'http://video.rutube.ru/'+this.mediaId,
					width: this.mediaWidth,
					height: this.mediaHeight,
					params: {wmode: this.options.wmode, bgcolor: this.options.bgcolor, allowscriptaccess: this.options.scriptaccess, allowfullscreen: this.options.fullscreen}
					});
				this.startEffect();
// Tudou
			} else if (this.URL.match(/tudou\.com/i)) {
				this.mediaType = 'obj';
				this.mediaWidth = this.mediaWidth || "400";
				this.mediaHeight = this.mediaHeight || "340";
				this.mediaSplit = this.URL.split('/');
				this.mediaId = this.mediaSplit[5];
				this.preload = new Swiff('http://www.tudou.com/v/'+this.mediaId, {
					width: this.mediaWidth,
					height: this.mediaHeight,
					params: {wmode: this.options.wmode, bgcolor: this.options.bgcolor, allowscriptaccess: this.options.scriptaccess, allowfullscreen: this.options.fullscreen}
					});
				this.startEffect();
// Twitcam
			} else if (this.URL.match(/twitcam\.com/i)) {
				this.mediaType = 'obj';
				this.mediaWidth = this.mediaWidth || "320";
				this.mediaHeight = this.mediaHeight || "265";
				this.mediaSplit = this.URL.split('/');
				this.mediaId = this.mediaSplit[3];
				this.preload = new Swiff('http://static.livestream.com/chromelessPlayer/wrappers/TwitcamPlayer.swf?hash='+this.mediaId, {
					width: this.mediaWidth,
					height: this.mediaHeight,
					params: {wmode: this.options.wmode, bgcolor: this.options.bgcolor, allowscriptaccess: this.options.scriptaccess, allowfullscreen: this.options.fullscreen}
					});
				this.startEffect();
// Twitvid
			} else if (this.URL.match(/twitvid\.com/i)) {
				this.mediaType = 'obj';
				this.mediaWidth = this.mediaWidth || "600";
				this.mediaHeight = this.mediaHeight || "338";
				this.mediaSplit = this.URL.split('/');
				this.mediaId = this.mediaSplit[3];
				this.preload = new Swiff('http://www.twitvid.com/player/'+this.mediaId, {
					width: this.mediaWidth,
					height: this.mediaHeight,
					params: {wmode: this.options.wmode, bgcolor: this.options.bgcolor, allowscriptaccess: this.options.scriptaccess, allowfullscreen: this.options.fullscreen}
					});
				this.startEffect();
// Ustream.tv
			} else if (this.URL.match(/ustream\.tv/i)) {
				this.mediaType = 'obj';
				this.mediaWidth = this.mediaWidth || "400";
				this.mediaHeight = this.mediaHeight || "326";
				this.preload = new Swiff(this.URL+'&amp;viewcount='+this.options.usViewers+'&amp;autoplay='+this.options.autoplay, {
					width: this.mediaWidth,
					height: this.mediaHeight,
					params: {wmode: this.options.wmode, bgcolor: this.options.bgcolor, allowscriptaccess: this.options.scriptaccess, allowfullscreen: this.options.fullscreen}
					});
				this.startEffect();
// YouKu
			} else if (this.URL.match(/youku\.com/i)) {
				this.mediaType = 'obj';
				this.mediaWidth = this.mediaWidth || "480";
				this.mediaHeight = this.mediaHeight || "400";
				this.mediaSplit = this.URL.split('id_');
				this.mediaId = this.mediaSplit[1];
				this.preload = new Swiff('http://player.youku.com/player.php/sid/'+this.mediaId+'=/v.swf', {
					width: this.mediaWidth,
					height: this.mediaHeight,
					params: {wmode: this.options.wmode, bgcolor: this.options.bgcolor, allowscriptaccess: this.options.scriptaccess, allowfullscreen: this.options.fullscreen}
					});
				this.startEffect();
// YouTube Video (now includes HTML5 option)
			} else if (this.URL.match(/youtube\.com\/watch/i)) {
				this.mediaSplit = this.URL.split('v=');
				if (this.options.html5) {
					this.mediaType = 'url';
					this.mediaWidth = this.mediaWidth || "640";
					this.mediaHeight = this.mediaHeight || "385";
					this.mediaId = "this.mediaId_"+new Date().getTime();	// Safari may not update iframe content with a static id.
					this.preload = new Element('iframe', {
						'src': 'http://www.youtube.com/embed/'+this.mediaSplit[1],
						'id': this.mediaId,
						'width': this.mediaWidth,
						'height': this.mediaHeight,
						'frameborder': 0
						});
					this.startEffect();
				} else {
					this.mediaType = 'obj';
					this.mediaId = this.mediaSplit[1];
					this.mediaWidth = this.mediaWidth || "480";
					this.mediaHeight = this.mediaHeight || "385";
					this.preload = new Swiff('http://www.youtube.com/v/'+this.mediaId+'&autoplay='+this.options.autoplayNum+'&fs='+this.options.fullscreenNum+'&border='+this.options.ytBorder+'&color1=0x'+this.options.ytColor1+'&color2=0x'+this.options.ytColor2+'&rel='+this.options.ytRel+'&showinfo='+this.options.ytInfo+'&showsearch='+this.options.ytSearch, {
						id: this.mediaId,
						width: this.mediaWidth,
						height: this.mediaHeight,
						params: {wmode: this.options.wmode, bgcolor: this.options.bgcolor, allowscriptaccess: this.options.scriptaccess, allowfullscreen: this.options.fullscreen}
						});
					this.startEffect();
				}
// YouTube Playlist
			} else if (this.URL.match(/youtube\.com\/view/i)) {
				this.mediaType = 'obj';
				this.mediaSplit = this.URL.split('p=');
				this.mediaId = this.mediaSplit[1];
				this.mediaWidth = this.mediaWidth || "480";
				this.mediaHeight = this.mediaHeight || "385";
				this.preload = new Swiff('http://www.youtube.com/p/'+this.mediaId+'&autoplay='+this.options.autoplayNum+'&fs='+this.options.fullscreenNum+'&border='+this.options.ytBorder+'&color1=0x'+this.options.ytColor1+'&color2=0x'+this.options.ytColor2+'&rel='+this.options.ytRel+'&showinfo='+this.options.ytInfo+'&showsearch='+this.options.ytSearch, {
					id: this.mediaId,
					width: this.mediaWidth,
					height: this.mediaHeight,
					params: {wmode: this.options.wmode, bgcolor: this.options.bgcolor, allowscriptaccess: this.options.scriptaccess, allowfullscreen: this.options.fullscreen}
					});
				this.startEffect();
// Veoh
			} else if (this.URL.match(/veoh\.com/i)) {
				this.mediaType = 'obj';
				this.mediaWidth = this.mediaWidth || "410";
				this.mediaHeight = this.mediaHeight || "341";
				this.URL = this.URL.replace('%3D','/');
				this.mediaSplit = this.URL.split('watch/');
				this.mediaId = this.mediaSplit[1];
				this.preload = new Swiff('http://www.veoh.com/static/swf/webplayer/WebPlayer.swf?version=AFrontend.5.5.2.1001&permalinkId='+this.mediaId+'&player=videodetailsembedded&videoAutoPlay='+this.options.AutoplayNum+'&id=anonymous', {
					id: this.mediaId,
					width: this.mediaWidth,
					height: this.mediaHeight,
					params: {wmode: this.options.wmode, bgcolor: this.options.bgcolor, allowscriptaccess: this.options.scriptaccess, allowfullscreen: this.options.fullscreen}
					});
				this.startEffect();
// Viddler
			} else if (this.URL.match(/viddler\.com/i)) {
				this.mediaType = 'obj';
				this.mediaWidth = this.mediaWidth || "437";
				this.mediaHeight = this.mediaHeight || "370";
				this.mediaSplit = this.URL.split('/');
				this.mediaId = this.mediaSplit[4];
				this.preload = new Swiff(this.URL, {
					id: 'viddler_'+this.mediaId,
					movie: this.URL,
					classid: 'clsid:D27CDB6E-AE6D-11cf-96B8-444553540000',
					width: this.mediaWidth,
					height: this.mediaHeight,
					params: {wmode: this.options.wmode, bgcolor: this.options.bgcolor, allowscriptaccess: this.options.scriptaccess, allowfullscreen: this.options.fullscreen, id: 'viddler_'+this.mediaId, movie: this.URL}
					});
				this.startEffect();
// Vimeo (now includes HTML5 option)
			} else if (this.URL.match(/vimeo\.com/i)) {
				this.mediaWidth = this.mediaWidth || "640";		// site defualt: 400px
				this.mediaHeight = this.mediaHeight || "360";		// site defualt: 225px
				this.mediaSplit = this.URL.split('/');
				this.mediaId = this.mediaSplit[3];

				if (this.options.html5) {
					this.mediaType = 'url';
					this.mediaId = "this.mediaId_"+new Date().getTime();	// Safari may not update iframe content with a static id.
					this.preload = new Element('iframe', {
						'src': 'http://player.vimeo.com/video/'+this.mediaSplit[3]+'?portrait='+this.options.vmPortrait,
						'id': this.mediaId,
						'width': this.mediaWidth,
						'height': this.mediaHeight,
						'frameborder': 0
						});
					this.startEffect();
				} else {
					this.mediaType = 'obj';
					this.preload = new Swiff('http://www.vimeo.com/moogaloop.swf?clip_id='+this.mediaId+'&amp;server=www.vimeo.com&amp;fullscreen='+this.options.fullscreenNum+'&amp;autoplay='+this.options.autoplayNum+'&amp;show_title='+this.options.vmTitle+'&amp;show_byline='+this.options.vmByline+'&amp;show_portrait='+this.options.vmPortrait+'&amp;color='+this.options.vmColor, {
						id: this.mediaId,
						width: this.mediaWidth,
						height: this.mediaHeight,
						params: {wmode: this.options.wmode, bgcolor: this.options.bgcolor, allowscriptaccess: this.options.scriptaccess, allowfullscreen: this.options.fullscreen}
						});
					this.startEffect();
				}
// INLINE
			} else if (this.URL.match(/\#mb_/i)) {
				this.mediaType = 'inline';
				this.mediaWidth = this.mediaWidth || this.options.defaultWidth;
				this.mediaHeight = this.mediaHeight || this.options.defaultHeight;
				this.URLsplit = this.URL.split('#');
//				this.preload = new Element("div", {id: "mbMediaInline"}).adopt(document.id(this.URLsplit[1]).getChildren().clone([true,true]));
				this.preload = document.id(this.URLsplit[1]);
				this.startEffect();
// HTML (applies to ALL links not recognised as a specific media type)
			} else {
				this.mediaType = 'url';
				this.mediaWidth = this.mediaWidth || this.options.defaultWidth;
				this.mediaHeight = this.mediaHeight || this.options.defaultHeight;
				this.mediaId = "this.mediaId_"+new Date().getTime();	// Safari may not update iframe content with a static id.
				this.preload = new Element('iframe', {
					'src': this.URL,
					'id': this.mediaId,
					'width': this.mediaWidth,
					'height': this.mediaHeight,
					'frameborder': 0
					});
				this.startEffect();
			}
		}
		return false;
	},
	startEffect:function() {
//		if (Browser.Platform.ios && (this.mediaType == "obj" || this.mediaType == "qt" || this.mediaType == "html")) alert("this isn't gonna work");
//		if (Browser.Platform.ios && (this.mediaType == "obj" || this.mediaType == "qt" || this.mediaType == "html")) this.mediaType = "ios";
		(this.mediaType == "img")?this.media.addEvent("click", next):this.media.removeEvent("click", this.next);
		if (this.mediaType == "img"){
			this.mediaWidth = this.preload.width;
			this.mediaHeight = this.preload.height;
			if (this.options.imgBackground) {
				this.media.setStyles({backgroundImage: "url("+this.URL+")", display: ""});
			} else {	// Thanks to Dusan Medlin for fixing large 16x9 image errors in a 4x3 browser
				if (this.mediaHeight >= this.winHeight-this.options.imgPadding && (this.mediaHeight / this.winHeight) >= (this.mediaWidth / this.winWidth)) {
					this.mediaHeight = this.winHeight-this.options.imgPadding;
					this.mediaWidth = this.preload.width = parseInt((this.mediaHeight/this.preload.height)*this.mediaWidth);
					this.preload.height = this.mediaHeight;
				} else if (this.mediaWidth >= this.winWidth-this.options.imgPadding && (this.mediaHeight / this.winHeight) < (this.mediaWidth / this.winWidth)) {
					this.mediaWidth = this.winWidth-this.options.imgPadding;
					this.mediaHeight = this.preload.height = parseInt((this.mediaWidth/this.preload.width)*this.mediaHeight);
					this.preload.width = this.mediaWidth;
				}
				if (Browser.ie) this.preload = document.id(this.preload);
				if (this.options.clickBlock) this.preload.addEvent('mousedown', function(e){ e.stop(); }).addEvent('contextmenu', function(e){ e.stop(); });
				this.media.setStyles({backgroundImage: "none", display: ""});
				this.preload.inject(this.media);
			}
//			this.mediaWidth += "px";
//			this.mediaHeight += "px";
		} else if (this.mediaType == "inline") {
//			if (this.options.overflow) this.media.setStyles({overflow: this.options.overflow});
			this.media.setStyles({backgroundImage: "none", display: ""});
//			this.preload.inject(media);
//			this.media.grab(this.preload.get('html'));
			(this.options.inlineClone)?this.media.grab(this.preload.get('html')):this.media.adopt(this.preload.getChildren());
		} else if (this.mediaType == "qt") {
			this.media.setStyles({backgroundImage: "none", display: ""});
			this.preload.inject(this.media);
//			this.preload;
		} else if (this.mediaType == "ios" || Browser.Platform.ios) {
			this.media.setStyles({backgroundImage: "none", display: ""});
			this.media.set('html', this.options.linkText.replace(/{x}/gi, this.URL));
			this.mediaWidth = this.options.DefaultWidth;
			this.mediaHeight = this.options.DefaultHeight;
		} else if (this.mediaType == "url") {
			this.media.setStyles({backgroundImage: "none", display: ""});
			this.preload.inject(this.media);
		} else if (this.mediaType == "obj") {
			if (Browser.Plugins.Flash.version < "8") {
				this.media.setStyles({backgroundImage: "none", display: ""});
				this.media.set('html', '<div id="mbError"><b>Error</b><br/>Adobe Flash is either not installed or not up to date, please visit <a href="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" title="Get Flash" target="_new">Adobe.com</a> to download the free player.</div>');
				this.mediaWidth = this.options.DefaultWidth;
				this.mediaHeight = this.options.DefaultHeight;
			} else {
				this.media.setStyles({backgroundImage: "none", display: ""});
				this.preload.inject(this.media);
			}
		} else {
			this.media.setStyles({backgroundImage: "none", display: ""});
			this.media.set('html', this.options.flashText);
			this.mediaWidth = this.options.defaultWidth;
			this.mediaHeight = this.options.defaultHeight;
		}

		this.title.set('html', (this.options.showCaption) ? this.captionSplit[0] : "");
		this.caption.set('html', (this.options.showCaption && (this.captionSplit.length > 1)) ? this.captionSplit[1] : "");
		this.number.set('html', (this.options.showCounter && (this.mediaArray.length > 1)) ? this.options.counterText.replace(/{x}/, (this.options.countBack)?this.mediaArray.length-this.activeMedia:this.activeMedia+1).replace(/{y}/, this.mediaArray.length) : "");

//		if (this.options.countBack) {
//			this.number.set('html', (this.options.showCounter && (this.mediaArray.length > 1)) ? this.options.counterText.replace(/{x}/, this.activeMedia + 1).replace(/{y}/, this.mediaArray.length) : "");
//		} else {
//			this.number.set('html', (this.options.showCounter && (this.mediaArray.length > 1)) ? this.options.counterText.replace(/{x}/, this.mediaArray.length - this.activeMedia).replace(/{y}/, this.mediaArray.length) : "");
//		}

		if ((this.prevMedia >= 0) && (this.mediaArray[this.prevMedia][0].match(/\.gif|\.jpg|\.jpeg|\.png|twitpic\.com/i))) this.preloadPrev.src = this.mediaArray[this.prevMedia][0].replace(/twitpic\.com/i, "twitpic.com/show/full");
		if ((this.nextMedia >= 0) && (this.mediaArray[this.nextMedia][0].match(/\.gif|\.jpg|\.jpeg|\.png|twitpic\.com/i))) this.preloadNext.src = this.mediaArray[this.nextMedia][0].replace(/twitpic\.com/i, "twitpic.com/show/full");
		if (this.prevMedia >= 0) this.prevLink.style.display = "";
		if (this.nextMedia >= 0) this.nextLink.style.display = "";
		this.media.setStyles({width: this.mediaWidth+"px", height: this.mediaHeight+"px"});
		this.bottom.setStyles({width: this.mediaWidth-this.marginBottom+"px"});
		this.caption.setStyles({width: this.mediaWidth-this.marginBottom+"px"});

		this.mediaWidth = this.media.offsetWidth;
		this.mediaHeight = this.media.offsetHeight+this.bottom.offsetHeight;
		if (this.mediaHeight >= this.top+this.top) { this.mTop = -this.top } else { this.mTop = -(this.mediaHeight/2) };
		if (this.mediaWidth >= this.left+this.left) { this.mLeft = -this.left } else { this.mLeft = -(this.mediaWidth/2) };
/****/	if (this.options.resizeOpening) { this.fx.resize.start({width: this.mediaWidth, height: this.mediaHeight, marginTop: this.mTop-this.margin, marginLeft: this.mLeft-this.margin});
/****/	} else { this.center.setStyles({width: this.mediaWidth, height: this.mediaHeight, marginTop: this.mTop-this.margin, marginLeft: this.mLeft-this.margin}); this.mediaAnimate(); }
	},
	mediaAnimate:function() {
		this.fx.media.start(1);
	},
	captionAnimate:function() {
		this.center.className = "";
//		if (this.prevMedia >= 0) this.prevLink.style.display = "";
//		if (this.nextMedia >= 0) this.nextLink.style.display = "";
		this.fx.bottom.start(1);
	},
	stop:function() {
		if (this.preload) {
			if (this.mediaType == "inline" && !this.options.inlineClone) this.preload.adopt(this.media.getChildren());	// prevents loss of adopted data
			this.preload.onload = function(){}; // $empty replacement
		}
		this.fx.resize.cancel();
		this.fx.media.cancel().set(0);
		this.fx.bottom.cancel().set(0);
		$$(this.prevLink, this.nextLink).setStyle("display", "none");
	},
	close:function() {
		if (this.activeMedia >= 0) {
			if (this.mediaType == "inline" && !this.options.inlineClone) this.preload.adopt(this.media.getChildren());	// prevents loss of adopted data
			this.preload.onload = function(){}; // $empty replacement
			this.media.empty();
			for (var f in this.fx) this.fx[f].cancel();
			this.center.setStyle("display", "none");
			this.fx.overlay.chain(this.setup()).start(0);
		}
		return false;
	},
	scanPage: function(_options, linkMapper, linksFilter) {
		var links = $$("a").filter(function(el) {
			return el.rel && el.rel.test(/^lightbox/i);
		});
		linkMapper = linkMapper || function(el) {
			elrel = el.rel.split(/[\[\]]/);
			elrel = elrel[1];
			return [el.get('href'), el.title, elrel];	// thanks to Dušan Medlín for figuring out the URL bug!
		};
		linksFilter = linksFilter || function() {
			return true;
		};
		$each($$('a'),function(el){
			if(el.rel && el.rel.test(/^lightbox/i)){
				el.addEvent('contextmenu', function(e){
					if (options.clickBlock && this.toString().match(/\.gif|\.jpg|\.jpeg|\.png/i)) e.stop();
				});
				el.removeEvents("click").addEvent("click", function(e2) {
					// Build the list of media that will be displayed
					var filteredArray = links.filter(linksFilter, this);
					var filteredLinks = [];
					var filteredHrefs = [];
	
					filteredArray.each(function(item, index){
						if(filteredHrefs.indexOf(item.toString()) < 0) {
							filteredLinks.include(filteredArray[index]);
							filteredHrefs.include(filteredArray[index].toString());
						};
					});
					return this.open(filteredLinks.map(linkMapper), filteredHrefs.indexOf(el.href), _options);
				}.bind(this));
			}
		}.bind(this))
	}
});
function initMediabox(){
	var mb=new Mediabox();
	window.addEvent('domready', function() {
		mb.scanPage();
	});
	window.addEvent('resize', function() {
		mb.recenter();
	});
}
/*	Quicktime detection from Quickie.js	

Browser.Plugins.QuickTime = (function(){
	if (navigator.plugins) {
		for (var i = 0, l = navigator.plugins.length; i < l; i++) {
			if (navigator.plugins[i].name.indexOf('QuickTime') >= 0) {
				return true;
			}
		}
	} else {
		try { var test = new ActiveXObject('QuickTime.QuickTime'); }
		catch(e) {}
		
		if (test) { return true; }
	}
	return false;
})();
*/
