var SimpleSlide = new Class({
	initialize: function(container,options) {
		this.container = container;
		this.options = options;
		//	Is it on autorun or manual?
		if(this.options.auto == "loop" || this.options.auto == "once") {
			var automated;
			this.automated = this.slider.periodical(this.options.time,this,$(this.container));
		} else {
			this.slider($(this.container))
		}
	},
	slider: function(container) {
		var direction;
		if(this.options) direction = this.options.direction;
		else direction = "forward";
		var child;
		// Get all child nodes to scroll between.
		var children = container.getChildren().getChildren()[0];
		// Run through all child nodes to see if there is a tagged one.
		children.each(function(e) {
			// If there is, make it current child.
			if(e.id == "currentChild") {
				child = e;
			}
		});
		if(!child) {
			// If there isn't, make the first one current child.
			if(direction == "forward") {
				child = children[0].getNext();
			}
			else if(direction == "back") {
				child = container.getChildren()[0].getLast();
			}
			else {
				child = children[direction]
			}
		} else {
			// Are we going to the next or previous node?
			if(direction == "forward") {
				var lastElement = container.getChildren()[0].getLast();
				// Stops the loop at the last element.
				if(lastElement == child.getNext() && this.options.auto == "once") $clear(this.automated);
				// Is the current child the last node? Then set the first node as child, otherwise set the next node as child.
				if(lastElement == child) child = children[0];
				else child = child.getNext();
			}
			else if(direction == "back") {
				var firstElement = container.getChildren()[0].getFirst();
				// Stops the loop at the last element.
				if(firstElement == child.getPrevious() && this.options.auto == "once") $clear(this.automated);
				// Is the current child the last node? Then set the first node as child, otherwise set the next node as child.
				if(firstElement == child) child = container.getChildren()[0].getLast();
				else child = child.getPrevious();			
			}
			else {
				child = children[direction];
			}
		}
		// Is the child defined?
		if(child) {
			// Which type of slider is defined?
			if(this.options.type == "scroll") this.scroll(container,children,child);
			else if(this.options.type == "fade") this.fade(container,children,child);
			else if(this.options.type == "scrollfade") this.scrollfade(container,children,child);
		}
	},
	scroll: function(container,children,child) {
		// Make it a scroll slide.
		var scroll = new Fx.Scroll(container,{duration: this.options.duration, onComplete: function() {
			// Remove tags from all child nodes.
			children.each(function(e) {
				e.id = "";
			});
			// Tag this child as current
			child.id = "currentChild";
		}}).toElement(child);
		
	},
	fade: function(container,children,child) {
		// Make it a fade slide
		var fade = new Fx.Style(container,'opacity',{duration: this.options.duration, onComplete: function() {
			new Fx.Scroll(container,{duration: 1,onComplete: function() {
				// Remove tags from all child nodes.
				children.each(function(e) {
					e.id = "";
				});
				// Tag this child as current
				child.id = "currentChild";
				new Fx.Style(container,'opacity').start(0.01,1);
			}}).toElement(child);
		}})
		fade.start(1,0.01);
	},
	scrollfade: function(container,children,child) {
		// In case you input the miliseconds as a string instead of integer.
		var durationInt = this.options.duration.toInt();
		// Make it a scrollfade slide
		var fade = new Fx.Style(container,'opacity',{duration: (durationInt/2)})
		fade.start(1,0.01).chain(function() {
			fade.start(0.01,1);
		});
		new Fx.Scroll(container,{duration: durationInt, onComplete: function() {
			// Remove tags from all child nodes.
			children.each(function(e) {
				e.id = "";
			});
			// Tag this child as current
			child.id = "currentChild";
		}}).toElement(child);
	}
});


/*
--------------------------------------------------------------------------
CHECK THESE LINKS FOR MULTIPLE SLIDERS
------------------------------------------------
http://forum.mootools.net/viewtopic.php?id=1499
http://forum.mootools.net/topic.php?id=4376
--------------------------------------------------------------------------*/

/*
--------------------------------------------------------------------------
  Window.Growl, version 2.0: http://icebeat.bitacoras.com
 *  Daniel Mota aka IceBeat <daniel.mota@gmail.com>
--------------------------------------------------------------------------*/

/*  Window.Growl, version 2.0: http://icebeat.bitacoras.com
 *  Daniel Mota aka IceBeat <daniel.mota@gmail.com>
--------------------------------------------------------------------------*/
var Gr0wl = {};

Gr0wl.Base = new Class({
	
	options: {
		image: '/images/spacer.gif',
		title: '',
		text: '',
		duration: 2
	},
	
	initialize: function(image) {
		this.image = new Asset.image(image, { onload: this.create.bind(this) });
		return this.show.bind(this);
	},
	
	create: function(styles) {
		this.image.setStyles('position:absolute;display:none').setOpacity(0).injectInside(document.body);
		this.block = new Element('div').setStyles('position:absolute;display:none;z-index:999;color:#fff;font: 12px/14px "Lucida Grande", Arial, Helvetica, Verdana, sans-serif;'+styles.div).setOpacity(0).injectInside(document.body);
		new Element('img').setStyles(styles.img).injectInside(this.block);
		new Element('h3').setStyles(styles.h3).injectInside(this.block);
		new Element('p').setStyles(styles.p).injectInside(this.block);
	},
	
	show: function(options) {
		options = $merge(this.options, options);
		var elements = [this.image.clone(), this.block.clone()];
		elements.each(function(e, i) {
			e.injectInside(document.body);
			e.setStyles(options.position);
			if(i) e.getFirst().setProperty('src', options.image).getNext().setHTML(options.title).getNext().setHTML(options.text);
		});
		new Fx.Elements(elements, {duration:400}).start({
			'0': { 'opacity': 0.75 }, '1': { 'opacity': 1 }
		});
		this.hide.delay(options.duration*1000, this, [elements]);
	},
	
	hide: function(elements, effect) {
		var effects = new Fx.Elements(elements, {duration:400, onComplete: function() {
			this.elements[0].remove();
			this.elements[1].empty().remove();
		}}).start({'0': effect, '1': effect });
	}
	
});


Gr0wl.Smoke = Gr0wl.Base.extend({
	
	create: function() {
		this.queue = [];
		this.parent({
			div: 'width: 298px; height: 75px;',
			img: 'float: left; margin: 12px;',
			h3: 'margin: 0 12px; padding: 6px 0px 5px 0; font: 13px "Lucida Grande", "Lucida Sans Unicode", "Lucida Sans", Helvetica, Verdana; sans-serif;',
			p: 'margin: 0px 10px; padding: 0 10px; font-size: 12px;'
		});
	},
	
	show: function(options) {
		var last = this.queue.getLast(),
		delta = window.getScrollTop()+10+(last*83);
		options.position = {'top':delta+'px', 'right':'10px', 'display':'block'};
		this.queue.push(last+1);
		this.parent(options);
	},
	
	hide: function(elements) {
		this.queue.shift();
		this.parent(elements,{ 'opacity': 0 });
	}
	
});

Gr0wl.Bezel = Gr0wl.Base.extend({
	
	create: function() {
		this.i=0;
		this.parent({
			div: 'width: 212px; height: 204px; text-align: center;',
			img: 'margin-top: 25px;',
			h3: 'margin:0; padding: 38px 12px 0 12px; font: 16px "Lucida Grande", "Lucida Sans Unicode", "Lucida Sans", Helvetica, Verdana; sans-serif;',
			p: 'margin: 12px; font-size: 14px; line-height: 20px;'
		});
	},
	
	show: function(options) {
		var top = window.getScrollTop()+(window.getHeight()/2)-105,
		left = window.getScrollLeft()+(window.getWidth()/2)-103;
		options.position = {'top':top+'px', 'left':left+'px', 'display':'block'};
		this.i++;
		this.chain(this.parent.pass(options,this));
		if(this.i==1) this.callChain();
	},
	
	hide: function(elements) {
		this.queue.delay(400,this);
		this.parent(elements, { 'opacity': 0, 'margin-top': [0,50] });
	},
	
	queue: function() {
		this.i--;
		this.callChain();
	}
	
});

Gr0wl.Bezel.implement(new Chain);

var Growl = function(options) {
	if(Growl[options.type]) Growl[options.type].call(options);
	else Growl.Smoke(options);
};

window.addEvent('domready',function() {
	Growl.Bezel = new Gr0wl.Bezel('/gfx/rlz_bezel.png');
	Growl.Smoke = new Gr0wl.Smoke('/gfx/rlz_smoke.png');
});