//MooTools More, <http://mootools.net/more>. Copyright (c) 2006-2008 Valerio Proietti, <http://mad4milk.net>, MIT Style License.

/*
Script: Fx.Elements.js
	Effect to change any number of CSS properties of any number of Elements.

	License:
		MIT-style license.
		*/

		Fx.Elements = new Class({

			Extends: Fx.CSS,

				initialize: function(elements, options){
						this.elements = this.subject = $$(elements);
								this.parent(options);
									},

										compute: function(from, to, delta){
												var now = {};
														for (var i in from){
																	var iFrom = from[i], iTo = to[i], iNow = now[i] = {};
																				for (var p in iFrom) iNow[p] = this.parent(iFrom[p], iTo[p], delta);
																						}
																								return now;
																									},

																										set: function(now){
																												for (var i in now){
																															var iNow = now[i];
																																		for (var p in iNow) this.render(this.elements[i], p, iNow[p], this.options.unit);
																																				}
																																						return this;
																																							},

																																								start: function(obj){
																																										if (!this.check(arguments.callee, obj)) return this;
																																												var from = {}, to = {};
																																														for (var i in obj){
																																																	var iProps = obj[i], iFrom = from[i] = {}, iTo = to[i] = {};
																																																				for (var p in iProps){
																																																								var parsed = this.prepare(this.elements[i], p, iProps[p]);
																																																												iFrom[p] = parsed.from;
																																																																iTo[p] = parsed.to;
																																																																			}
																																																																					}
																																																																							return this.parent(from, to);
																																																																								}

																																																																								});

																																																																								/*
																																																																								Script: Assets.js
																																																																									Provides methods to dynamically load JavaScript, CSS, and Image files into the document.

																																																																									License:
																																																																										MIT-style license.
																																																																										*/

																																																																										var Asset = new Hash({

																																																																											javascript: function(source, properties){
																																																																													properties = $extend({
																																																																																onload: $empty,
																																																																																			document: document,
																																																																																						check: $lambda(true)
																																																																																								}, properties);
																																																																																										
																																																																																												var script = new Element('script', {'src': source, 'type': 'text/javascript'});
																																																																																														
																																																																																																var load = properties.onload.bind(script), check = properties.check, doc = properties.document;
																																																																																																		delete properties.onload; delete properties.check; delete properties.document;
																																																																																																				
																																																																																																						script.addEvents({
																																																																																																									load: load,
																																																																																																												readystatechange: function(){
																																																																																																																if (['loaded', 'complete'].contains(this.readyState)) load();
																																																																																																																			}
																																																																																																																					}).setProperties(properties);
																																																																																																																							
																																																																																																																									
																																																																																																																											if (Browser.Engine.webkit419) var checker = (function(){
																																																																																																																														if (!$try(check)) return;
																																																																																																																																	$clear(checker);
																																																																																																																																				load();
																																																																																																																																						}).periodical(50);
																																																																																																																																								
																																																																																																																																										return script.inject(doc.head);
																																																																																																																																											},

																																																																																																																																												css: function(source, properties){
																																																																																																																																														return new Element('link', $merge({
																																																																																																																																																	'rel': 'stylesheet', 'media': 'screen', 'type': 'text/css', 'href': source
																																																																																																																																																			}, properties)).inject(document.head);
																																																																																																																																																				},

																																																																																																																																																					image: function(source, properties){
																																																																																																																																																							properties = $merge({
																																																																																																																																																										'onload': $empty,
																																																																																																																																																													'onabort': $empty,
																																																																																																																																																																'onerror': $empty
																																																																																																																																																																		}, properties);
																																																																																																																																																																				var image = new Image();
																																																																																																																																																																						var element = $(image) || new Element('img');
																																																																																																																																																																								['load', 'abort', 'error'].each(function(name){
																																																																																																																																																																											var type = 'on' + name;
																																																																																																																																																																														var event = properties[type];
																																																																																																																																																																																	delete properties[type];
																																																																																																																																																																																				image[type] = function(){
																																																																																																																																																																																								if (!image) return;
																																																																																																																																																																																												if (!element.parentNode){
																																																																																																																																																																																																	element.width = image.width;
																																																																																																																																																																																																						element.height = image.height;
																																																																																																																																																																																																										}
																																																																																																																																																																																																														image = image.onload = image.onabort = image.onerror = null;
																																																																																																																																																																																																																		event.delay(1, element, element);
																																																																																																																																																																																																																						element.fireEvent(name, element, 1);
																																																																																																																																																																																																																									};
																																																																																																																																																																																																																											});
																																																																																																																																																																																																																													image.src = element.src = source;
																																																																																																																																																																																																																															if (image && image.complete) image.onload.delay(1);
																																																																																																																																																																																																																																	return element.setProperties(properties);
																																																																																																																																																																																																																																		},

																																																																																																																																																																																																																																			images: function(sources, options){
																																																																																																																																																																																																																																					options = $merge({
																																																																																																																																																																																																																																								onComplete: $empty,
																																																																																																																																																																																																																																											onProgress: $empty
																																																																																																																																																																																																																																													}, options);
																																																																																																																																																																																																																																															if (!sources.push) sources = [sources];
																																																																																																																																																																																																																																																	var images = [];
																																																																																																																																																																																																																																																			var counter = 0;
																																																																																																																																																																																																																																																					sources.each(function(source){
																																																																																																																																																																																																																																																								var img = new Asset.image(source, {
																																																																																																																																																																																																																																																												'onload': function(){
																																																																																																																																																																																																																																																																	options.onProgress.call(this, counter, sources.indexOf(source));
																																																																																																																																																																																																																																																																						counter++;
																																																																																																																																																																																																																																																																											if (counter == sources.length) options.onComplete();
																																																																																																																																																																																																																																																																															}
																																																																																																																																																																																																																																																																																		});
																																																																																																																																																																																																																																																																																					images.push(img);
																																																																																																																																																																																																																																																																																							});
																																																																																																																																																																																																																																																																																									return new Elements(images);
																																																																																																																																																																																																																																																																																										}

																																																																																																																																																																																																																																																																																										});
