/* 
	moo.rd - A lightweight Mootools extension  

	Author: Riccardo Degni, <http://www.riccardodegni.it/> and the moo.rd Team 

	License: GNU GPL License 

	Copyright: copyright 2007 Riccardo Degni 

	[Credits] 
		[li] moo.rd is based on the MooTools framework <http://mootools.net/>, and uses the MooTools syntax 
		[li] moo.rd constructors extends some of the MooTools Classes 
		[li] moo.rd Documentation is written by Riccardo Degni 
	[/Credits] 

*/ 

var Moo = {};

Moo.Rd = {
	version: '1.3.2',
	author: 'Riccardo Degni',
	members: [
		'Cristiano Fino',
		'Moocha'
	]
};

var Table = new Class({	
	initialize: function(element) {
		this.element = $(element);
		this.rows = this.element.getElements('tr');
		this.cells = this.element.getElements('tr').getElements('td');
	}
});

var Make = new Class({
	Implements: [Options],
	options: {
		content: 'text'
	}
});

function $dump(obj, result) {
	var r = '(' + '<br />';
	var tinyspaces = '&nbsp;&nbsp;';
	r += tinyspaces + 'Value: ' + obj.toString() + '<br />';
	r += tinyspaces + 'Type: ' + $type(obj) + '<br />';
	r += ')';
	return (result) ? $(result).set('html', r) : r;
}

function $string(obj) {
	return $type(obj) == 'string';
}

function $int(obj) {
	return $type(obj) == 'number';
}

function $array(obj) {
	return $type(obj) == 'array';
}

function $object(obj) {
	return $type(obj) == 'object';
}

function $function(obj) {
	return $type(obj) == 'function';
}

function $date(obj) {
	return $type(obj) == 'date';
}

function $class(obj) {
	return $type(obj) == 'class';
}

function $element(obj) {
	return $type(obj) == 'element';
}

function $collection(obj) {
	return $type(obj) == 'collection';
}

function $arguments(obj) {
	return $type(obj) == 'arguments';
}

function $textnode(obj) {
	return $type(obj) == 'textnode';
}

function $whitespace(obj) {
	return $type(obj) == 'whitespace';
}

function $window(obj) {
	return $type(obj) == 'window';
}

function $document(obj) {
	return $type(obj) == 'document';
}

Browser.ie = Browser.Engine.trident;
Browser.ie6 = Browser.Engine.trident4;
Browser.ie7 = Browser.Engine.trident5;
Browser.firefox = Browser.Engine.gecko;
Browser.safari = Browser.Engine.webkit;
Browser.safari2 = Browser.Engine.webkit419;
Browser.safari3 = Browser.Engine.webkit420;
Browser.opera = Browser.Engine.presto;
Browser.opera925 = Browser.Engine.presto925;
Browser.opera950 = Browser.Engine.presto950;

var Overlay = new Class({
						
	createOverlay: function(id, light) {
		this.overlay = new Element('div', {
			'id': id || 'overlay',
			'styles': {
				'position': (Browser.ie6) ? 'absolute' : 'fixed',
				'top': '0px',
				'left': '0px',
				'width': (Browser.ie6) ? window.getWidth() : '100%',
				'height': '100%',
				'background-image':'url(g.gif)',
				'z-index': 3100
			}
		});
		
		if(Browser.Engine.presto) this.overlay.setStyle('overflow', 'hidden');  
	
		this.setLight(light);
		
		return this;
	},
	
	createFullPage: function(id) {
		this.fullpage = new Element('div', {
			'id': id || 'fullpage',
			'styles': {
				'position': (Browser.ie6) ? 'absolute' : 'fixed',
				'top': '0px',
				'left': '0px',
				'width': (Browser.ie6) ? window.getWidth() : '100%',
				'height': '100%',
				'background-image':'url(g.gif)',
				'z-index': 8200
			}
		});
		
		if(Browser.Engine.presto) this.fullpage.setStyle('overflow', 'hidden');  
		
		return this;
	},
	
	setLight: function(light, opacity) {
		switch(light) {
			case 'darken': 
				var color = '#333333';
				break;
			case 'lighten':
				var color = '#FFFFFF';
				break;
			case false:
				var color = 'transparent';
				break;
			default: 
				var color = light;
				break;
		};
		this.overlay.setStyles({
			'background-color': color,
			'opacity': opacity || '0.8'			   
		});
		
		return this;
	},
	
	injectOverlay: function(fullpage) {
		this.overlay.inject(document.body);
		if(fullpage) this.fullpage.inject(document.body);
		this.overlayActive = true;
		this.fixOverlay();
		return this;
	},
	
	removeOverlay: function() {
		this.overlay.dispose();
		this.fullpage.dispose();
		if(Browser.ie6) {
			document.body.setStyles({'height': this.bodyHeightTrident4, 'overflow': this.bodyOverflowTrident4});
		}
		this.overlayActive = false;
		return this;
	},
	
	fixOverlay: function() {
		if(Browser.ie6) {
			if(!this.bodyHeightTrident4) this.bodyHeightTrident4 = $(document.body).getStyle('height');
			this.bodyOverflowTrident4 = $(document.body).getStyle('overflow');
			
			$$(this.overlay, this.fullpage).setStyle('overflow', 'hidden');
			
			$$(window, document.body).setStyles({
				'height': '100%',
				'overflow': 'auto',
				'margin': 0,
				'padding': 0
			});
		}
		return this;
	}
});

var Virtual = new Class({
		
	Implements: [Overlay, Options, Events],
	
	options: {
		enable: {
			arrows: true,
			closeButton: true,
			arrowsKeyboard: true,
			closeKeyboard: true,
			caption: true
		},
		effect: 'open',
		effectOptions: {
			duration: 1000	
		},
		style: true,
		adjustStyles: true,
		zones: {
			main: '',
			wrapper: '',
			caption: '',
			captionText: '',
			captionTextTitle: '',
			captionTextContent: '',
			arrowsBox: '',
			arrowsBoxText: '',
			leftArrow: '',
			rightArrow: ''
		},
		arrowsBoxText: false,
		leftArrowText: 'prev',
		rightArrowText: 'next',
		closeButtonText: 'close',
		captionOpacity: 0.4,
		imageText: false,
		onShow: $empty,
		onClose: $empty,
		onNext: $empty,
		onPrev: $empty,
		overlayLight: 'darken'
	},	
	
	initialize: function(options) {
		this.setOptions(options);
		this.effects = {
			main: new Fx.Elements(null, $merge(this.options.effectOptions, {link: 'ignore'})),
			caption: new Fx.Elements(null, {duration: 1000, link: 'ignore'})	
		};
		this.fullWidth = [];
		this.fullHeight = [];
		this.captionHeight = [];
	},
	
	mechanize: function() {
        this.createOverlay('virtualBoxOverlay', this.options.overlayLight);
		this.createFullPage('virtualBoxFullPage');
		
		this.main = new Element('div', {
			'id': 'virtualMain',
			'class': this.options.zones.main
		});
		
		if(this.options.style)
			this.main.setStyles({
				'background-color': '#FFFFFF',
				'padding': '8px'
			});
		
		this.wrapper = new Element('div', {
			'id': 'virtualBox',
			'class': this.options.zones.wrapper,
			'styles': {
				'position': 'relative',
				'overflow': 'hidden'
			}
		}).inject(this.main);
		
		if(this.options.enable.caption) {
			this.caption = new Element('div', {
				'id': 'virtualCaption',	
				'class': this.options.zones.caption,
				'styles': {
					'position': 'absolute',
					'bottom': '0px',
					'opacity': this.options.captionOpacity,
					'z-index': 1,
					'overflow': 'hidden',
					'visibility': 'hidden'
				}
			}).inject(this.wrapper);
			
			if(this.options.style) this.caption.setStyles({'background-color': '#CCCCCC'});
			
			this.captionText = new Element('div', {
				'id': 'virtualCaptionText',	
				'class': this.options.zones.captionText,
				'styles': {
					'position': 'absolute',
					'bottom': '0px',
					'opacity': 1,
					'z-index': 2,
					'overflow': 'hidden',
					'visibility': 'hidden'
				}
			}).inject(this.wrapper);
			
			this.captionTextTitle = new Element('p', {
				'id': 'virtualCaptionTitle',
				'class': this.options.zones.captionTextTitle
			}).inject(this.captionText);
			
			this.captionTextContent = new Element('p', {
				'id': 'virtualCaptionContent',
				'class': this.options.zones.captionTextContent
			}).inject(this.captionText);
		}
		
		if(this.options.enable.arrows) {
			this.arrowsBox = new Element('div', {
				'id': 'virtualArrowsBox',	
				'class': this.options.zones.arrowsBox,
				 'styles': {
					 'position': 'absolute',
					 'bottom': '0px',
					 'visibility': 'hidden' 
				 }
			});
			
			this.arrowsBoxText = new Element('div', {
				'id': 'virtualArrowsBoxText', 
				'class': this.options.zones.arrowsBoxText,
				'styles': {
					'display': 'block',
					'visibility': 'hidden'
				}
			}).inject(this.arrowsBox);
			
			this.leftArrow = new Element('a', {
				'id': 'virtualLeftArrow',
				'class': this.options.zones.leftArrow,
				'href': '#'
			}).set('html', this.options.leftArrowText);
			
			this.rightArrow = new Element('a', {
				'id': 'virtualRightArrow',
				'class': this.options.zones.rightArrow,
				'href': '#'
			}).set('html', this.options.rightArrowText);
			
			this.leftArrow.addEvent('click', function(event) {
				event.preventDefault();
				this.prev();
			}.bind(this));
			
			this.rightArrow.addEvent('click', function(event) {
				event.preventDefault();
				this.next();
			}.bind(this));
			
			$$(this.leftArrow, this.rightArrow).inject(this.arrowsBox);
			
			if(this.options.enable.closeButton) {
				this.closeButton = new Element('a', {
					'id': 'virtualCloseButton',
					'class': this.options.zones.closeButton,
					'href': '#'
				}).set('html', this.options.closeButtonText).addEvent('click', function(event) {
					event.preventDefault();
					this.closeBox();
				}.bind(this));
				this.closeButton.inject(this.arrowsBox);
			}
			else {
				this.attachCloseEvent();
			}
		}
		
		if(this.options.enable.closeKeyboard) document.addEvent('keydown', this.keyboardClose.bind(this));
		if(!this.options.enable.arrows || !this.options.enable.closeButton) this.attachCloseEvent();
		if(this.options.enable.arrowsKeyboard) document.addEvent('keydown', this.keyboard.bindWithEvent(this));
		
		if(this.options.adjustStyles) {
			this.newsizes = function() {
				$$(this.main).setStyles({
					'top': window.getSize().y.toInt()/2,
					'left': window.getSize().x.toInt()/2
				});
			};
			window.addEvent('resize', this.newsizes.bind(this));
		}
	},
	
	createArrowsBox: function() {
		this.arrowsBox.inject(this.main);
		this.main.inject(this.fullpage);
		this.arrowsBoxHeight = this.arrowsBox.getSize().y + this.arrowsBoxText.getSize().y;
		this.arrowsBoxHalfHeight = this.arrowsBox.getHeight().toInt();
		this.main.setStyles({
			'position': 'absolute',
			'top': window.getSize().y.toInt()/2,
			'left': window.getSize().x.toInt()/2,
			'height': this.sizes.height+this.arrowsBoxHeight,
			'margin-top': -((this.sizes.height+this.arrowsBoxHeight)/2),
			'margin-left': -((this.sizes.width+this.arrowsBoxHeight)/2)
		});
	},
	
	setArrowsBoxText: function(text) {
		if(this.options.enable.arrows) { 
			var arrowsBoxText = this.options.arrowsBoxText || text;
			this.arrowsBoxText.set('html', arrowsBoxText).inject(this.main);
		}
	},
	
	reset: function() {
		$$(this.caption, this.captionText, this.arrowsBox, this.arrowsBoxText).setStyle('visibility', 'hidden');
		if(this.options.enable.caption) {
			this.captionText.dispose().setStyle('height', '0px');
			$$(this.captionTextTitle, this.captionTextContent).empty();
		}
	},
	
	makeCaptionEffect: function(i) {
		if(this.options.enable.caption) {
			this.captionText.inject(this.caption, 'after');
			if(!this.captionPadding) this.captionPadding = (this.captionText.getStyle('padding-top').toInt() + this.captionText.getStyle('padding-bottom').toInt());
			
			this.captionText.setStyle('height', 'auto');
			this.captionTextTitle.set('html', this.sizes.title).inject(this.captionText);
			this.captionTextContent.set('html', this.sizes.text).inject(this.captionText);
			
			if(!this.captionHeight[i]) this.captionHeight[i] = this.captionText.getSize().y - this.captionPadding;
			
			$$(this.caption, this.captionText).setStyles({'height': '0px', 'visibility': 'visible'});
			
			switch(this.options.effect) {
				case 'open':
				case 'slide:vertical':
				case 'slide:horizontal':
				case 'slide': this.captionDelay = this.effects.main.options.duration.toInt();
								break;
				case 'fix': this.captionDelay = 0;
							break;
				case 'fold': this.captionDelay = this.effects.main.options.duration.toInt()*2;
								break;
			}
			
			this.effects.caption.elements = $$(this.caption, this.captionText);
			this.effects.caption.start.delay(this.captionDelay, this.effects.caption, {
				'0': { height: [0, this.captionHeight[i]]},	
				'1': { height: [0, this.captionHeight[i]]}
			});
		}
	},
	
	next: function() {
		if(this.effects.main.timer || this.effects.caption.timer) return;
		(this.count != this.length) ? this.count++ : this.count = 0;
		this.attach(this.count);
		this.fireEvent('onNext', [this.count, this.fullLength]);
	},
	
	prev: function() {
		if(this.effects.main.timer || this.effects.caption.timer) return;
		(this.count == 0) ? this.count = this.length : this.count--;
		this.attach(this.count);
		this.fireEvent('onPrev', [this.count, this.fullLength]);
	},
	
	keyboard: function(event) {
		if(this.overlayActive) {
			if(event.key == 'right') {
				this.next();
			}
			else if(event.key == 'left') {
				this.prev();
			}
		}
	},
	
	keyboardClose: function(event) {
		if(this.overlayActive) {
			if(event.key == 'esc') this.closeBoxWithKeyboard();
		}
	},
	
	setEffect: function(mode) {
		this.options.effect = mode;
	},
	
	remove: function() {
		this.main.dispose();
		this.removeOverlay();
	},
	
	attachCloseEvent: function() {
		if(Browser.firefox) {
			this.overlay.addEvent('click', this.closeBox.bindWithEvent(this, 'overlay'));
			this.fullpage.addEvent('click', this.closeBox.bindWithEvent(this, 'fullpage'));
		}
		else {
			this.fullpage.addEvent('click', this.closeBox.bindWithEvent(this, 'fullpage'));
		}
	},
	
	closeBox: function(event, zone) {
		if(this.effects.main.timer || this.effects.caption.timer) return;
		if((!this.options.enable.arrows || !this.options.enable.closeButton) && event.target != this[zone]) return;
		this.fireEvent('onClose', [this.count, this.length]);
		this.count = 0;
		this.remove();
	},
	
	closeBoxWithKeyboard: function() {
		if(this.effects.main.timer || this.effects.caption.timer) return;
		this.fireEvent('onClose', [this.count, this.length]);
		this.count = 0;
		this.remove();
	},
	
	makeEffect: function(i) {
		if(this.options.effect == 'open') {
			if(Browser.firefox) this.fullpage.setStyle('height', 'auto');
			if(this.options.enable.arrows) this.createArrowsBox();
			else this.main.inject(this.fullpage);
			
			if(!this.fullWidth[i]) this.fullWidth[i] = this.main.getStyle('width').toInt();
			if(!this.fullHeight[i]) this.fullHeight[i] = (!this.arrowsBoxHeight) ? this.sizes.height : this.sizes.height+this.arrowsBoxHeight;
			
			$$(this.main, this.wrapper).setStyles({'visibility': 'visible', 'height': '0px', 'width': '0px'});
			$$(this.arrowsBox).setStyle('width', this.fullWidth[i]);
			
			this.effects.main.elements = $$(this.main, this.wrapper);
			this.effects.main.start({
				'0': {
					'width': this.fullWidth[i],	
					'height': this.fullHeight[i]
				},
				'1': {
					'width': this.fullWidth[i],	
					'height': this.sizes.height
				}
			}).chain(function() {
				if(this.options.enable.arrows) $$(this.arrowsBox, this.arrowsBoxText).setStyle('visibility', 'visible');	
			}.bind(this));
		}
		else if(this.options.effect == 'fix') {
			if(Browser.firefox) this.fullpage.setStyle('height', 'auto');
			if(this.options.enable.arrows) { 
				this.createArrowsBox();
				if(!this.fullWidth[i]) this.fullWidth[i] = this.main.getStyle('width').toInt();
				if(!this.fullHeight[i]) this.fullHeight[i] = (!this.arrowsBoxHeight) ? this.sizes.height : this.sizes.height+this.arrowsBoxHeight;
				$$(this.arrowsBox, this.arrowsBoxText).setStyle('visibility', 'visible');
				$$(this.arrowsBox).setStyle('width', this.fullWidth[i]);
			}
			else this.main.inject(this.fullpage);
		}
		else if(this.options.effect == 'fold') {
			if(Browser.firefox) this.fullpage.setStyle('height', 'auto');
			if(this.options.enable.arrows) this.createArrowsBox();
			else this.main.inject(this.fullpage);
			
			$$(this.main).setStyle('overflow', 'hidden');
			
			if(!this.fullWidth[i]) this.fullWidth[i] = this.main.getStyle('width').toInt();
			if(!this.fullHeight[i]) this.fullHeight[i] = (!this.arrowsBoxHeight) ? this.sizes.height : this.sizes.height+this.arrowsBoxHeight;
			
			$$(this.main, this.wrapper).setStyles({'visibility': 'visible', 'height': '0px', 'width': '0px'});
			$$(this.arrowsBox).setStyles({'height': '0px', 'width': '0px'});
			//$$(this.arrowsBox).setStyle('width', this.fullWidth[i]);
			
			this.effects.main.elements = (this.options.enable.arrows) ? $$(this.main, this.wrapper, this.arrowsBox) : $$(this.main, this.wrapper);
			
			var width = {
				'0': { 'width': [this.main.getStyle('width').toInt(), this.fullWidth[i]] },
				'1': { 'width': [this.main.getStyle('width').toInt(), this.fullWidth[i]] }
			};
			
			var height = {
				'0': { 'height': [this.main.getStyle('height').toInt(), this.fullHeight[i]] },
				'1': { 'height': [this.main.getStyle('height').toInt(), this.sizes.height] }
			};
			
			if(this.options.enable.arrows) {
				var arrwidth = { '2': { 'width': this.fullWidth[i] } };
				var arrheight = { '2': { 'height': [0, this.arrowsBoxHalfHeight] } };
			}
			
			this.effects.main.start((arrwidth) ? $merge(width, arrwidth) : width).chain(function() {
				this.effects.main.start((arrheight) ? $merge(height, arrheight) : height);
			}.bind(this)).chain(function() {
				if(this.options.enable.arrows) $$(this.arrowsBox, this.arrowsBoxText).setStyle('visibility', 'visible');	
			}.bind(this));
		}
		else if(this.options.effect == 'slide:vertical' || this.options.effect == 'slide:horizontal' || this.options.effect == 'slide') {
			if(Browser.firefox) this.fullpage.setStyle('height', 'auto');
			if(this.options.enable.arrows) this.createArrowsBox();
			else this.main.inject(this.fullpage);
			
			if(!this.fullWidth[i]) this.fullWidth[i] = this.main.getStyle('width').toInt();
			if(!this.fullHeight[i]) this.fullHeight[i] = (!this.arrowsBoxHeight) ? this.sizes.height : this.sizes.height+this.arrowsBoxHeight;
			
			var direction = this.options.effect.split(':')[1] || 'vertical';
			
			if(direction == 'vertical')
				$$(this.main).setStyles({'visibility': 'visible', 'height': this.fullHeight[i], 'width': this.fullWidth[i], 'top': -1000});
			else if(direction == 'horizontal')
				$$(this.main).setStyles({'visibility': 'visible', 'height': this.fullHeight[i], 'width': this.fullWidth[i], 'left': -1000});
			
			$$(this.arrowsBox).setStyle('width', this.fullWidth[i]);
			
			switch(direction) {
				case 'vertical': var styles = {'top': window.getSize().y.toInt()/2 };
								break;
				case 'horizontal': var styles = {'left': window.getSize().x.toInt()/2 };
								break;
			}
	
			this.effects.main.elements = $$(this.main);
			this.effects.main.start({
				'0': styles
			}).chain(function() {
				if(this.options.enable.arrows) $$(this.arrowsBox, this.arrowsBoxText).setStyle('visibility', 'visible');	
			}.bind(this));
			
		}
	},
	
	virtualStyle: function(path) {
		new Asset.css(path, {id: 'virtualStyle'});
		return this;
	},
	
	setIDs: function(names) {
		if($object(names)) {
			for(var name in names) {
				if(this[name]) this[name].set('id', names[name]);
			}	
		}
		return this;
	}
});

Virtual.single = new Class({
						   
	attachElement: function() {
		this.element.addEvent('click', function(event) {
			event.preventDefault();
			this.attach(0);	
		}.bind(this));
	},
	
	create: function() {
		this.attach(0);	
	}
});

Virtual.Box = new Class({
						
	Extends: Virtual,
	
	initialize: function(options, single) {
		this.links = $$('a[class=virtualbox]');
		this.preload = [];
		this.parent(options);
		
		this.mechanize();
		
		if(!single) {
			this.links.each(function(el, i) {
									 
				this.preload[i] = new Element('img');
				this.preload[i].src = el.getProperty('href');
		
				var fullText = el.getProperty('virtualbox').split(' :: ');
				
				this.preload[i].store('title', fullText[0]);
				this.preload[i].store('text', fullText[1]);
				
				el.addEvent('click', function(event) {
					event.preventDefault();
					this.attach(i);	
				}.bind(this));
				
			}, this);
		}
		
		this.count = 0;
		this.length = this.preload.length-1;
		this.fullLength = this.preload.length;
	},
	
	attach: function(i) {
		this.img = this.preload[i];
		this.count = i;
		
		if(!this.overlayActive) { 
			this.injectOverlay(true);
		}
		
		this.reset();
		
		this.prepareImage(i);
		this.makeCaptionEffect(i);
	},
	
	prepareImage: function(i) {
		this.sizes = {
			width: this.preload[i].width,
			height: this.preload[i].height,
			title: this.preload[i].retrieve('title'),
			text: this.preload[i].retrieve('text')
		};
		
		this.main.setStyles({
			'position': 'absolute',
			'width': this.sizes.width,
			'height': this.sizes.height,
			'top': window.getSize().y.toInt()/2,
			'left': window.getSize().x.toInt()/2,
			'margin-top': -(this.sizes.height/2),
			'margin-left': -(this.sizes.width/2)
		});
		
		this.wrapper.setStyles({
			'background-color': '#FFFFFF',
			'background-repeat': 'no-repeat',
			'background-image': 'url(' + this.preload[i].src + ')',
			'overflow': 'hidden',
			'width': this.sizes.width,
			'height': this.sizes.height			   
		});
		
		$$(this.caption, this.captionText).setStyles({'width': this.sizes.width});
		
		this.setArrowsBoxText('image ' + (i+1) + '/' + this.preload.length);
		this.fireEvent('onShow');
		this.makeEffect(i);
	}
});

Virtual.Box.single = new Class({
								
	Extends: Virtual.Box,
	
	Implements: Virtual.single,
	
	initialize: function(element, options) {
		this.element = $(element);
		this.parent($merge(options, {enable: {arrows: false, arrowsKeyboard: false}}), true);
		this.preload[0] = new Element('img');
		var fullText = this.element.getProperty('title').split(' :: ');
	
		this.preload[0].src = this.element.getProperty('href');
		this.preload[0].store('title', fullText[0]);
		this.preload[0].store('text', fullText[1]);
			
		this.attachElement();
	}
});

Virtual.Ajax = new Class({
						
	Extends: Virtual,
	
	options: {
		width: 400,
		height: 300,
		requestOptions: {}
	},
	
	initialize: function(options, single) {
		this.links = $$('a[class=virtualajax]');
		this.preload = [];
		this.parent(options);
		this.request = new Request.HTML($merge(this.options.requestOptions, {update: this.wrapper}));
		
		this.mechanize();
		this.wrapreq = new Element('div').inject(this.wrapper, 'top');
		
		if(!single) {
			this.links.each(function(el, i) {				 
				this.preload[i] = new Hash();
				var fullText = el.getProperty('virtualbox').split(' :: ');
				
				this.preload[i].set('src',  el.get('href'));
				this.preload[i].set('width',  fullText[0].toInt() || this.options.width);
				this.preload[i].set('height',  fullText[1].toInt() || this.options.height);
                // this.preload[i].set('title',  fullText[2]);
				this.preload[i].set('text', fullText[3]);
				
				el.addEvent('click', function(event) {
					event.preventDefault();
					this.attach(i);	
				}.bind(this));
			}, this);
		}
		
		this.count = 0;
		this.length = this.preload.length-1;
		this.fullLength = this.preload.length;
	},
	
	attach: function(i) {
		this.img = this.preload[i];
		this.count = i;
		
		if(!this.overlayActive) { 
			this.injectOverlay(true);
		}
		
		if(Browser.opera) this.main.dispose();
		this.reset();
		this.prepareRequest(i);
		this.makeCaptionEffect(i);
	},
	
	prepareRequest: function(i) {
		this.sizes = {
			width: this.preload[i].get('width'),
			height: this.preload[i].get('height'),
			title: this.preload[i].get('title'),
			text: this.preload[i].get('text')
		};
		
		this.main.setStyles({
			'position': 'absolute',
			'width': this.sizes.width,
			'height': this.sizes.height,
			'top': window.getSize().y.toInt()/2,
			'left': window.getSize().x.toInt()/2,
			'margin-top': -(this.sizes.height/2),
			'margin-left': -(this.sizes.width/2)
		});
		
		this.wrapper.setStyles({
			'width': this.sizes.width,
			'height': this.sizes.height
		});
		
		$$(this.caption, this.captionText).setStyles({'width': this.sizes.width});
		           
		var tmp = (new Date()).getTime();
		this.request.setOptions({url: this.preload[i].src, update: this.wrapreq,
			onSuccess: function() {
				if(this.options.enable.caption) {
					$$(this.caption, this.captionText).setStyles({
						'width': this.sizes.width				   
					}).inject(this.wrapper);
					this.captionTextTitle.set('html', this.sizes.title).inject(this.captionText);
					this.captionTextContent.set('html', this.sizes.text).inject(this.captionText);
				}		
			}.bind(this, i)
		}).send({data:{t:tmp}});
		
		this.setArrowsBoxText('Virtual Ajax ' + (i+1) + '/' + this.preload.length);
		this.fireEvent('onShow');
		this.makeEffect(i);
	}
});

Virtual.Ajax.single = new Class({
								
	Extends: Virtual.Ajax,
	
	Implements: Virtual.single,
	
	initialize: function(element, options) {
		this.element = $(element);
		this.parent($merge(options, {enable: {arrows: false, arrowsKeyboard: false}}), true);
		this.preload[0] = new Hash();
		var fullText = this.element.getProperty('virtualbox').split(' :: ');
		this.preload[0].set('src',  this.element.get('href'));
		this.preload[0].set('width',  fullText[0].toInt() || this.options.width);
		this.preload[0].set('height',  fullText[1].toInt() || this.options.height);
        // this.preload[0].set('title',  fullText[2]);
		this.preload[0].set('text', fullText[3]);
			
		this.attachElement();
	}
});

Virtual.HTML = new Class({
						
	Extends: Virtual,
	
	options: {
		width: 400,
		height: 300,
		contents: []
	},
	
	initialize: function(options, single) {
		this.links = $$('a[class=virtualhtml]');
		this.preload = [];
		this.parent(options);
		
		this.mechanize();
		this.content = new Element('div', {'id': 'virtualHTMLContent'});
		
		if(!single) {
			this.links.each(function(el, i) {
									 
				this.preload[i] = new Hash();
				var fullText = el.getProperty('virtualbox').split(' :: ');
				
				this.preload[i].set('width',  fullText[0].toInt() || this.options.width);
				this.preload[i].set('height',  fullText[1].toInt() || this.options.height);
				this.preload[i].set('title',  fullText[2]);
				this.preload[i].set('text', fullText[3]);
				
				el.addEvent('click', function(event) {
					event.preventDefault();
					this.attach(i);	
				}.bind(this));
				
			}, this);
		}
		
		this.count = 0;
		this.length = this.preload.length-1;
		this.fullLength = this.preload.length;
	},
	
	attach: function(i) {
		this.img = this.preload[i];
		this.count = i;
		
		if(!this.overlayActive) { 
			this.injectOverlay(true);
		}
		
		if(Browser.opera) this.main.dispose();
		this.reset();
		this.prepareContent(i);
		this.makeCaptionEffect(i);
	},
	
	prepareContent: function(i) {
		this.sizes = {
			width: this.preload[i].get('width'),
			height: this.preload[i].get('height'),
			title: this.preload[i].get('title'),
			text: this.preload[i].get('text')
		};
		
		this.main.setStyles({
			'position': 'absolute',
			'width': this.sizes.width,
			'height': this.sizes.height,
			'top': window.getSize().y.toInt()/2,
			'left': window.getSize().x.toInt()/2,
			'margin-top': -(this.sizes.height/2),
			'margin-left': -(this.sizes.width/2)
		});
		
		this.wrapper.setStyles({
			'width': this.sizes.width,
			'height': this.sizes.height
		});
		
		$$(this.caption, this.captionText).setStyles({'width': this.sizes.width});
		
		this.content.set('html', this.options.contents[i]).inject(this.wrapper, 'top');
		this.setArrowsBoxText('Virtual HTML ' + (i+1) + '/' + this.preload.length);
		this.fireEvent('onShow');
		this.makeEffect(i);
	}
});

Virtual.HTML.single = new Class({
								
	Extends: Virtual.HTML,
	
	Implements: Virtual.single,
	
	options: {
		content: ''
	},
	
	initialize: function(element, options) {
		this.element = $(element);
		this.parent($merge(options, {enable: {arrows: false, arrowsKeyboard: false}}), true);
		this.preload[0] = new Hash();
		var fullText = this.element.getProperty('virtualbox').split(' :: ');
		this.preload[0].set('width',  fullText[0].toInt() || this.options.width);
		this.preload[0].set('height',  fullText[1].toInt() || this.options.height);
        // this.preload[0].set('title',  fullText[2]);
		this.preload[0].set('text', fullText[3]);
		
		this.options.contents[0] = this.options.content;
		this.attachElement();
	}
});