/*
	Flashbox by Pascal-berkhahn is a part of pb-embedFlash for Wordpress and based on Slimbox and Videobox. It uses the mootools framework and the SWFObject 2.0  class.
	Released under MIT License.
*/

var Flashbox = {
	init: function(options) {
		var links = $$('a');
		this.anchors = [];
		links.each(function(el, i) {
			if (el.rel && el.href && el.rel.test(/^flashbox/i)) {
				this.create = true;
				el.addEvent('click', function(e) {
					e = new Event(e); e.stop(); this.open (el.href, el.title, el.rel);
				}.bind(this));
				this.anchors.push(el);
			}
		}, this);
		if (this.create) {
			this.overlay = new Element('div', {'id': 'fbOverlay', 'styles': {'opacity': 0, 'display': 'none'}}).injectInside(document.body);
			this.center  = new Element('div', {'id': 'fbCenter'}).injectInside(this.overlay);
			this.bottomContainer = new Element('div', {'id': 'fbBottomContainer', 'styles': {'display': 'none'}}).injectInside(this.overlay);
			this.bottom  = new Element('div', {'id': 'fbBottom'}).injectInside(this.bottomContainer);
			this.caption = new Element('div', {'id': 'fbCaption'}).injectInside(this.bottom);
			new Element('a', {'id': 'fbCloseLink', 'href': '#'}).injectInside(this.bottom).onclick = this.overlay.onclick = this.close.bind(this);
			new Element('div', {'styles': {'clear': 'both'}}).injectInside(this.bottom);
			this.fx = {
				overlay: this.overlay.effect('opacity', {duration: 300}).hide()
//				center: this.center.effects({duration: 300}),
//				bottom: this.bottom.effects({duration: 300})
			};
		}
		return false;
	}, // init
	open: function(linkHref, linkTitle, linkRel) {
		this.vars = linkRel.match(/[0-9]+/g);
		this.left = (window.getWidth()-this.vars[0])/2;
		this.top = (window.getHeight()-this.vars[1])/2;
		this.overlay.setStyles({'display': ''});
		this.center.setStyles({'left': this.left+'px', 'top': this.top+'px', 'width': parseInt(this.vars[0])+'px', 'height': parseInt(this.vars[1])+'px'});
		this.fx.overlay.start(0, 0.8);
//		this.fx.center.start({'opacity': [0, 1]});
		if (linkTitle || this.vars[2] == 1) {
			this.caption.innerHTML = linkTitle;
			this.bottomContainer.setStyles({'left': this.left, 'top': (this.top + this.center.clientHeight)+'px', 'height': '', 'width': this.vars[0]+'px', 'display': ''});
//			this.fx.bottom.start({'margin-top': 0, 'opacity': [0, 1]});
		}
		new Element('div', {'id': 'fbFlashbox'}).injectInside(this.center);
		var flashvars = {}; var params = {}; var attributes = {};
		attributes.id = 'flashboxObject';
//		params.wmode = 'transparent'; 
		swfobject.embedSWF(linkHref, 'fbFlashbox', this.vars[0], this.vars[1], '9.0.0', false, flashvars, params, attributes);
		return false;
	}, // open
	close: function() {
		this.overlay.setStyles({'opacity': 0, 'display': 'none'});
		this.bottomContainer.setStyle('display', 'none');
		this.center.innerHTML = this.caption.innerHTML = '';
		return false;
	} // close
};
window.addEvent('domready', Flashbox.init.bind(Flashbox));