/*
Filename: 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'
}
});
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({
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': 900
}
});
if(Browser.Engine.presto) this.fullpage.setStyle('overflow', 'hidden'); 
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;
}
});
Make.List = new Class({
Extends: Make,
options: {
type: 'ul',
listOptions: {}
},
initialize: function(id, items, options) {
this.idKey = id;
this.items = items;
this.setOptions(options);
},
make: function() {
if(!$(this.idKey)) {
if(this.options.type != 'ul' && this.options.type != 'ol') this.options.type = 'ul';
this.ul = new Element(this.options.type, $merge(this.options.listOptions, {'id': this.idKey}));
this.items.each(function(li) {
if($array(li)) {
li.each(function(item, i) {
var mul = new Element('ul');
if($object(item)) {
var a = new Element('a', $merge(item.linkOptions, {
'href': item.href
})).set(this.options.content, item.text);
var lis = new Element('li');
a.inject(lis);
lis.inject(mul);
mul.inject(this.ul);
} 
else {
var mli = new Element('li').set(this.options.content, item).inject(mul);
mul.inject(this.ul);
}
}, this);
}
else if($object(li)) {
var a = new Element('a', $merge(li.linkOptions, {
'href': li.href
})).set(this.options.content, li.text);
var li = new Element('li');
a.inject(li);
li.inject(this.ul);
}
else {
var li = new Element('li').set(this.options.content, li);
li.inject(this.ul);
}
}, this);
return this.ul;
}
else return;
}
});
Make.Select = new Class({
Extends: Make,
options: {
properties: {}
},
initialize: function(id, items, options) {
this.idKey = id;
this.items = items;
this.setOptions(options);
},
make: function() {
if(!$(this.idKey)) {
this.select = new Element('select', $extend({'id': this.idKey}, this.options.properties));
this.items.each(function(item) {
if($array(item)) {
item.each(function(i, index) {
if(index == 0) {
this.group = new Element('optgroup', { 'label': i });
this.select.adopt(this.group);
}
else {
var opt = new Element('option', {
'label': i,
'value': i
}).set(this.options.content, i);
opt.inject(this.group); 
}
}, this); 
} 
else {
var option = new Element('option', {
'label': item,
'value': item
}).set(this.options.content, item);
option.inject(this.select);
}
}, this);
return this.select;
}
else return;
}
});
var Custom = new Class({
Implements: [Options, Events, Overlay],
options: {
height: 'auto',
width: '300px',
overlay: false,
opacify: true,
draggable: true,
dragOpacity: false,
adjustStyles: true,
promptType: {
box: 'single',
lines: 1,
startValue: '',
search: false,
target: 'new'
},
content: 'text',
enable: {
closeButton: true,
confirmButton: true,
cancelButton: true,
onConfirm: true,
onCancel: true,
textBox: false
},
text: {
confirmButtonText: 'OK',
closeButtonText: 'X',
cancelButtonText: 'Cancel'
},
zones: {
box: null,
head: null,
body: null,
buttonBox: '',
promptBox: ''
},
buttons: {
closeButton: '',
confirmButton: '',
cancelButton: ''
},
onConfirm: $empty,
onCancel: $empty
},
initialize: function(title, text, options) {
this.title = title;
this.text = text;
this.setOptions(options);
this.box = new Element('div', {
'id': 'customBox',
'styles': {
'position': (!Browser.Engine.trident4) ? 'fixed' : 'absolute',
'top': '50%',
'left': '50%',
'z-index': 1000,
'height': this.options.height,
'width': this.options.width
}
});
this.createOverlay('customBoxOverlay', this.options.overlay);
this.createFullPage('customBoxfullpage');
this.mechanize();
this.box.set('tween', {duration: 1000});
this.dragOptions = {container: this.fullpage};
if(this.options.dragOpacity) 
this.dragOptions = $merge(this.dragOptions, {
onDrag: function(element) {
element.set('opacity', 0.6);
},
onComplete: function(element) {
element.set('opacity', 1);
}
});
},
create: function() {
this.customize();
},
mechanize: function() {
if(this.options.zones['box']) this.box.addClass(this.options.zones['box']);
this.head = new Element('div').injectInside(this.box);
if(this.options.zones.head) this.head.addClass(this.options.zones['head']);
this.head.set(this.options.content, this.title);
if(this.options.enable.closeButton) {
this.closebutton = new Element('a', {'id': 'customCloseButton', 'class': this.options.buttons.closeButton}).injectInside(this.head);
this.closebutton.setProperty('href', '#');
this.closebutton.set(this.options.content, this.options.text.closeButtonText);
this.closebutton.addEvent('click', function(event) {
event.preventDefault();
});
this.closebutton.addEvent('click', this.cancelRemove.bind(this));
}
this.content = new Element('div').injectInside(this.box);
if(this.options.zones.body) this.content.addClass(this.options.zones['body']);
this.content.set(this.options.content, this.text);
if(this.options.enable.textBox) { 
this.promptbox = new Element('div', {
'id': 'customPromptTextBox', 'class': this.options.zones.promptBox}).inject(this.box);
this.form = new Element('form', {'id': 'customPromptTextForm', 'action': '#'}).inject(this.promptbox);
switch(this.options.promptType.box) {
case 'single': this.input = new Element('input', {'type': 'text', 'value': this.options.promptType.startValue}).inject(this.form);
break;
case 'multi': this.input = new Element('textarea', {'value': this.options.promptType.startValue}).inject(this.form).inject(this.form).setProperty('rows', this.options.promptType.lines);
break;
}
switch(this.options.promptType.search) {
case 'google':
this.addEvent('onConfirm', function(event) {
if(this.options.promptType.target == 'same')
location.href = 'http://www.google.it/search?q=' + this.input.get('value');
else if(this.options.promptType.target == 'new')
window.open('http://www.google.it/search?q=' + this.input.get('value'));
});
break;
case 'yahoo':
this.addEvent('onConfirm', function(event) {
if(this.options.promptType.target == 'same')
location.href = 'http://search.yahoo.com/search?p=' + this.input.get('value');
else if(this.options.promptType.target == 'new')
window.open('http://search.yahoo.com/search?p=' + this.input.get('value'));
});
break;
case 'wikipedia':
this.addEvent('onConfirm', function(event) {
if(this.options.promptType.target == 'same')
location.href = 'http://en.wikipedia.org/wiki/' + this.input.get('value');
else if(this.options.promptType.target == 'new')
window.open('http://en.wikipedia.org/wiki/' + this.input.get('value'));
});
break;
}
}
this.closebox = new Element('div', {'id': 'customButtonBox', 'class': this.options.zones.buttonBox}).injectInside(this.box);
if(this.options.enable.confirmButton) {
this.button = new Element('a', {'id': 'customButton', 'class': this.options.buttons.confirmButton}).injectInside(this.closebox);
this.button.setProperty('href', '#');
this.button.set(this.options.content, this.options.text.confirmButtonText);
this.button.addEvent('click', function(event) {
event.preventDefault();
});
this.button.addEvent('click', this.confirmRemove.bind(this));
}
if(this.options.enable.cancelButton) {
this.cancelButton = new Element('a', {'id': 'customCancelButton', 'class': this.options.buttons.cancelButton}).injectInside(this.closebox);
this.cancelButton.setProperty('href', '#');
this.cancelButton.set(this.options.content, this.options.text.cancelButtonText);
this.cancelButton.addEvent('click', function(event) {
event.preventDefault();
});
this.cancelButton.addEvent('click', this.cancelRemove.bind(this));
}
},
customize: function() {
if($(this.box.get('id'))) return;
if(this.options.opacify) this.box.set('opacity', 0);
this.box.injectInside(this.fullpage);
this.injectOverlay(true);
var dimensions = this.dimensions = { 
top: this.box.getSize().y/2,
left: this.box.getSize().x/2,
fullTop: this.fullpage.getSize().y.toInt()/2,
fullLeft: this.fullpage.getSize().x.toInt()/2
};
this.box.setStyles({
'margin-left': -dimensions.left,
'margin-top': -dimensions.top,
'top': dimensions.fullTop,
'left': dimensions.fullLeft 
});
if(this.options.opacify) this.box.fade('in');
if(this.options.draggable) this.drag = new Drag.Move(this.box, this.dragOptions);
if(this.options.adjustStyles) {
this.newsizes = function() {
this.box.setStyles({
'top': window.getSize().y.toInt()/2,
'left': window.getSize().x.toInt()/2
});
if(this.options.draggable) this.drag = new Drag.Move(this.box, this.dragOptions);
};
this.boundsizes = this.newsizes.bind(this);
window.addEvent('resize', this.boundsizes);
}
},
remove: function() {
this.box.dispose();
this.fullpage.dispose();
this.removeOverlay();
window.removeEvent('resize', this.boundsizes);
},
checkremove: function() {
if(this.options.opacify) {
this.box.fade('out');
this.remove.delay(this.box.get('tween').options.duration.toInt(), this);
}
else {
this.remove();
}
},
confirmRemove: function() {
if(this.options.enable.onConfirm) (this.input) ? this.fireEvent('onConfirm', this.input.get('value')) : this.fireEvent('onConfirm');
this.checkremove();
},
cancelRemove: function() {
if(this.options.enable.onCancel) this.fireEvent('onCancel');
this.checkremove();
},
setText: function(text) {
this.text = text;
this.content.set(this.options.content, this.text);
return this;
},
setTitle: function(title) {
this.title = title; 
this.head.set(this.options.content, this.title);
return this;
},
setIDs: function(box, overlay, fullpage) {
this.box.set('id', box);
this.overlay.set('id', overlay);
this.fullpage.set('id', fullpage);
}
});
Fx.Cycle = new Class({
Extends: Fx.Morph,
options: {
animeOut: {},
animeIn: {},
cssBefore: {},
//cssAfter: {},
animeInType: 'set',
overflow: 'visible',
autostart: true,
steps: 2000,
handles: {
next: false,
prev: false,
toFirst: false,
toLast: false,
autostart: false,
stop: false
},
enable: {
keyboard: false 
},
onAnimeIn: $empty,
onAnimeOut: $empty
},
initialize: function(element, options) {
this.parent(element, options);
this.imgs = this.element.getChildren();
this.uimgs = this.element.getChildren().reverse();
this.element.setStyles({'position': 'relative', 'overflow': this.options.overflow});
this.first = this.element.getFirst();
this.height = this.first.getStyle('height').toInt();
this.width = this.first.getStyle('width').toInt();
this.parentHeight = this.element.getStyle('height').toInt();
this.parentWidth = this.element.getStyle('width').toInt();
this.uimgs.each(function(img, i) {
img.setStyles({'position': 'absolute', 'top': '0px', 'left': '0px', 'z-index': i});
}, this);
this.count = 0;
this.length = this.imgs.length-1;
this.fullLength = this.imgs.length;
if(this.options.autostart) this._autostart = this.next.periodical(this.options.steps, this);
this.attachHandles();
if(this.options.enable.keyboard) this.attachKeys.bindWithEvent(this)();
},
next: function() {
if(!this.timer) {
this.checkAutostart();
this.element = this.imgs[this.count];
(this.count != this.length) ? this.count++ : this.count = 0;
this.main();
}
},
prev: function() {
if(!this.timer) {
this.checkAutostart();
this.element = this.imgs[this.count];
(this.count == 0) ? this.count = this.length : this.count--;
this.main();
}
},
goTo: function(to) {
if(!this.timer && to != this.count) {
this.checkAutostart();
this.element = this.imgs[this.count];
this.count = to;
this.main();
}
},
toFirst: function() {
if(!this.timer && this.count != 0) {
this.checkAutostart();
this.element = this.imgs[this.count];
this.count = 0;
this.main();
}
},
toLast: function() {
if(!this.timer && this.count != this.length) {
this.checkAutostart();
this.element = this.imgs[this.count];
this.count = this.length;
this.main();
}
},
autostart: function() {
this._autostart = this.next.periodical(this.options.steps, this);
},
stop: function() {
this._autostart = $clear(this._autostart); 
},
checkAutostart: function() {
if(this._autostart) {
this._autostart = $clear(this._autostart);
this._autostart = this.next.periodical(this.options.steps, this);
}
},
attachHandles: function() {
for(var mtd in this.options.handles) {
var method = mtd.toString();
if(this.options.handles[mtd] && $function(this[method])) {
$(this.options.handles[mtd]).addEvent('click', function(event, method) {
event.preventDefault(); 
this[method]();
}.bindWithEvent(this, method)); 
}
}
},
attachKeys: function(event) {
$(document).addEvent('keydown', function(event) {
switch(event.key) {
case 'left': this.prev();
break;
case 'right': this.next();
break;
case 'a': this.autostart();
break;
case 's': this.stop();
break;
case 'f': this.toFirst();
break;
case 'l': this.toLast();
break;
}
}.bind(this));
},
main: function() {
this.element.setStyle('z-index', this.fullLength);
this.imgs[this.count].setStyle('z-index', 4); //modifica parametro slide!
this.currSlide = this.element;
this.nextSlide = this.imgs[this.count];
this.fireEvent('onAnimeOut', [this.currSlide, this.nextSlide]);
this.start(this.options.animeOut).chain(
function() {
var type = this.options.animeInType;
if(type == 'set') this.fireEvent('onAnimeIn', [this.currSlide, this.nextSlide]);
this.element.setStyle('z-index', 0);
this.imgs.each(function(img, i) {
if(i != this.count) img.setStyle('z-index', 0).setStyles(this.options.cssBefore);
}, this);
if(type == 'set') this[type](this.options.animeIn); // set instead of start
if(type == 'start') this[type](this.options.animeIn).chain(function() { this.fireEvent('onAnimeIn', [this.currSlide, this.nextSlide]); });
}
);
}
});
(function() {
var methods = {};
['animeOut', 'animeIn', 'cssBefore'].each(function(method) {
methods[method] = function(styles) {
for(var style in styles)
if($defined(styles[style])) this.options[method][style] = styles[style]; 
} 
});
Fx.Cycle.implement(methods);
})();
Fx.Cycle.fade = new Class({
Extends: Fx.Cycle,
options: {
animeOut: {
opacity: 0
},
cssBefore: {
opacity: 1 
}
},
initialize: function(element, options) {
this.parent(element, options);
}
});
Fx.Cycle.slideUp = new Class({
Extends: Fx.Cycle,
options: {
cssBefore: {
top: 0, left:0
},
overflow: 'hidden'
},
initialize: function(element, options) {
this.parent(element, options);
this.animeOut({top: -this.parentHeight});
}
});
Fx.Cycle.slideDown = new Class({
Extends: Fx.Cycle,
options: {
cssBefore: {
top: 0, left:0
},
overflow: 'hidden'
},
initialize: function(element, options) {
this.parent(element, options);
this.animeOut({top: this.parentHeight});
}
});
Fx.Cycle.slideRight = new Class({
Extends: Fx.Cycle,
options: {
cssBefore: {
top: 0, left:0
},
overflow: 'hidden'
},
initialize: function(element, options) {
this.parent(element, options);
this.animeOut({left: this.parentWidth});
}
});
Fx.Cycle.slideLeft = new Class({
Extends: Fx.Cycle,
options: {
cssBefore: {
top: 0, left:0
},
overflow: 'hidden'
},
initialize: function(element, options) {
this.parent(element, options);
this.animeOut({left: -this.parentWidth});
}
});
Element.implement({
cycle: function(type, options) {
return new Fx.Cycle[type](this, options);
} 
});
Fx.Cycles = new Class({
Extends: Fx.Elements,
options: {
animeOut: {},
animeIn: {},
cssBefore: {},
cssAfter: {},
reset: {},
overflow: 'visible',
autostart: true,
steps: 2000,
duration: 3000,
handles: {
next: false,
prev: false,
toFirst: false,
toLast: false,
autostart: false,
stop: false
},
enable: {
keyboard: false 
},
onAnimeIn: $empty,
onAnimeOut: $empty
},
initialize: function(element, options) {
this.element = $(element);
this.elements = this.element.getChildren();
this.parent($$(this.elements), options);
this.imgs = this.element.getChildren();
this.uimgs = this.element.getChildren().reverse();
this.element.setStyles({'position': 'relative', 'overflow': this.options.overflow});
this.first = this.element.getFirst();
this.height = this.first.getStyle('height').toInt();
this.width = this.first.getStyle('width').toInt();
this.parentHeight = this.element.getStyle('height').toInt();
this.parentWidth = this.element.getStyle('width').toInt();
this.uimgs.each(function(img, i) {
img.setStyles({'position': 'absolute', 'top': '0px', 'left': '0px', 'z-index': i});
}, this);
this.count = 0;
this.where = -1;
this.length = this.imgs.length-1;
this.fullLength = this.imgs.length;
if(this.options.autostart) this._autostart = this.next.periodical(this.options.steps, this);
this.attachHandles();
if(!this.options.enable.keyboard) this.attachKeys.bindWithEvent(this)();
},
next: function() {
if(!this.timer) {
this.checkAutostart();
this.element = this.imgs[this.count];
(this.count != this.length) ? this.count++ : this.count = 0;
(this.where == -1) ? this.where = 0 : (this.count == 0) ? this.where = this.length : this.where = this.count-1;
this.main();
}
},
prev: function() {
if(!this.timer) {
this.checkAutostart();
this.element = this.imgs[this.count];
(this.count == 0) ? this.count = this.length : this.count--;
(this.where == -1) ? this.where = 0 : (this.count == this.length) ? this.where = 0 : this.where = this.count+1;
this.main();
}
},
goTo: function(to) {
if(!this.timer && to != this.count) {
this.checkAutostart();
this.element = this.imgs[this.count];
this.where = this.count;
this.count = to;
this.main();
}
},
toFirst: function() {
if(!this.timer && this.count != 0) {
this.checkAutostart();
this.element = this.imgs[this.count];
this.where = this.count;
this.count = 0;
this.main();
}
},
toLast: function() {
if(!this.timer && this.count != this.length) {
this.checkAutostart();
this.element = this.imgs[this.count];
this.where = this.count;
this.count = this.length;
this.main();
}
},
autostart: function() {
this._autostart = this.next.periodical(this.options.steps, this);
},
stop: function() {
this._autostart = $clear(this._autostart); 
},
checkAutostart: function() {
if(this._autostart) {
this._autostart = $clear(this._autostart);
this._autostart = this.next.periodical(this.options.steps, this);
}
},
attachHandles: function() {
for(var mtd in this.options.handles) {
var method = mtd.toString();
if(this.options.handles[mtd] && $function(this[method])) {
$(this.options.handles[mtd]).addEvent('click', function(event, method) {
event.preventDefault(); 
this[method]();
}.bindWithEvent(this, method)); 
}
}
},
attachKeys: function(event) {
$(document).addEvent('keydown', function(event) {
switch(event.key) {
case 'left': this.prev();
break;
case 'right': this.next();
break;
case 'a': this.autostart();
break;
case 's': this.stop();
break;
case 'f': this.toFirst();
break;
case 'l': this.toLast();
break;
}
}.bind(this));
},
main: function() {
this.element.setStyle('z-index', this.fullLength);
this.imgs[this.count].setStyle('z-index', 1).setStyles(this.options.current);
this.imgs.each(function(img, i) {
if(i!=this.where)
img.setStyles(this.options.cssBefore);
}, this);
var o = {};
var curr = this.where;
var next = this.count;
this.currSlide = this.imgs[curr];
this.nextSlide = this.imgs[next];
o[curr] = this.options.animeOut;
o[next] = this.options.animeIn;
this.fireEvent('onAnimeOut', [this.currSlide, this.nextSlide]);
this.imgs[next].setStyles(this.options.reset);
this.start(o).chain(function() {
this.imgs[curr].setStyles(this.options.cssAfter); 
this.fireEvent('onAnimeIn', [this.currSlide, this.nextSlide]); 
});
}
});
(function() {
var methods = {};
['animeOut', 'animeIn', 'cssBefore', 'cssAfter', 'reset'].each(function(method) {
methods[method] = function(styles) {
for(var style in styles)
if($defined(styles[style])) this.options[method][style] = styles[style]; 
} 
});
Fx.Cycles.implement(methods);
})();
Element.implement({
cycles: function(type, options) {
return new Fx.Cycles[type](this, options);
} 
});
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.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();
	}
});