//document.write("<script type='text/javascript' src='http://o.aolcdn.com/dojo/1.1.0/dojo/dojo.xd.js'></script>");

dojo.provide("ade.ade");

dojo.require("dojo.NodeList-fx");
dojo.require("dojox.fx.easing");
dojo.require("dojox.fx.style");

(function(){
	
	var d = dojo;

	if (d.getObject("ade")) {
		
		d.declare("_ade", null, {
			constructor: function(q){
				
				if (typeof(q) == "string") {
					this.searchString = q;
					this.target = d.query(q);
				}
				else {
					this.searchString = "";
					this.target = new dojo.NodeList(q);
				}

			},
			
			animate: function(params, duration, easing, callback) {
				this.target.anim(params, duration, easing, callback);
				return this;
			}, 
			
			append: function(content) {	
				this.target.addContent(content);
				return this;
			},
			
			appendTo: function(parentObject) {
				d.query(parentObject).addContent(this.target, 'after');
				return this;
			},
			
			after: function(content) {
				this.target.addContent(content, 'after');
				return this;
			},
			
			before: function(content) {
				this.target.addContent(content, 'before');
				return this;
			},
			
			bind: function(eventName, fn) {
				// event should be passed just as in connect, but is it already "fixed"?
				if (! eventName.match(/^on/)) eventName = "on"+eventName; // add ON to the event name string as needed
				
				d.forEach(this.target, function(item) {
					var c = dojo.connect(item, eventName, null, fn);			
					ade._cxn.push(c); // should get tighter, need better lookup system so we don't need to loop/loop on unbind
				});
				
				return this;
			},
			
			unbind: function(eventName) {
				if (! eventName.match(/^on/)) eventName = "on"+eventName;
				
				d.forEach(this.target, function(item) {
					d.forEach(ade._cxn, function(b) {
						if (item == b[0] && b[1] == eventName) dojo.disconnect(b);
					});
				});
				
				return this;
			},
			
			css: function(styleParams) {
				this.target.style(styleParams);
				return this;
			},
			
			style: function(styleParams) {
				this.target.style(styleParams);
				return this;
			},
			
			empty: function() {
				this.target.empty();
				return this;
			},
			
			dolly: function(index, speed) {
				// node must have w and h for this?
				var w = parseInt(this.target.style('width')) + index; // should be a fraction of current 
				var h = parseInt(this.target.style('height')) + index;
				var o = 1 + (index / 1000) // just to get going, need fix for IE
				var s = speed || 500;
				
				// and we should move the object's l and t accordingly
			
				
				this.target.anim({ width: w, height: h, opacity: o }, s, ade.easing.sineInOut);
			},
			
			tween: function(targetClass, duration, easing, callback) {
				// manually implement if we can't reliably get addClass to run
				d.forEach(this.target, function(n) {
					dojox.fx.addClass({ node: n, cssClass: targetClass, duration: duration, easing: easing, onEnd: callback }).play();
				});
				return this;
			}, 
			
			addClass: function(c) {
				this.target.addClass(c);
				return this;
			},
			
			removeClass: function(c) {				
				this.target.removeClass(c)
				return this;
			},
			
			remove: function() {
				d.forEach(this.target, function(item) {
					item.parentNode.removeChild(item);
				});
				return this;
			},
			
			toggleClass: function(c) {
				this.target.toggleClass(c);
				return this;
			},
			
			attr: function(n, v) {
				if (v === undefined) return this.target.attr(n); // this going to be a snag?  return the obj here, too?
				else {
					this.target.attr(n, v);
					return this;
				}
			}
			
		});
		
		ade = function(arg) {
			return new _ade(arg);
		}
		
		ade.ready = function(fn) { // on DOM ready, a la jQuery
			dojo.addOnLoad(fn);
		}
		
		ade._cxn = new Array(); // the library of connections
		
		//easing shortcuts, delaying this in onload because easing isn't there yet when we cdn
		dojo.addOnLoad(function() {
			ade.easing = d.mixin({}, dojox.fx.easing);
		});
		
	}

})();


		


/*

 ade tbd
----

media support, 
	simple embeds for audio, video, flash


selector ade(".class").anim()


ade.dolly(-5) // send to negative number, neg means more opacity, smaller
ade.dolly(15) // send to positive number, means less opacity, bigger


draw = ade.draw(elements, rate), calls draw on all of them at rate
WAITING -  queue = ade.queue(1, 2, 3)
toolTip('.class', timeToLive, rounded?).append("please click here")

lightbox = var lb = ade.lightbox(bgColor, opacity, fadeIn?)
json = ade.json().value
xhr = ade.get/post
comet = ade.comet?
svg = 	// auto gen a canvas?
	// class is auto by shape unless specified to ade('.line') will get you all the lines
	ade.line(xy, xy, stroke, fill, 'class').render(canvas||container) 
	ade.point(xy, xy, stroke, fill, 'class').render(canvas||container)
	ade.rect(xy, xy, stroke, fill, 'class').render(canvas||container)
	ade.roundRect(xy, xy, cornerRad)
	ade.arc(xy, xy, stroke, fill, 'class').render(canvas||container)
	ade.circle(xy, xy, stroke, fill, 'class').render(canvas||container)
	ade.vertex([xy, xy], stroke, fill, 'class').render(canvas||container)
	ade.quad([xy, xy, xy, xy ], stroke, fill, 'class').render(canvas||container)
	ade.bezier()
	ade.canvas(target)

friendly aliases for easing ("elastic in/out/inout", "bounce in/out/inout", etc)
always return a ade for chaining?  arg for that?

generators ade generate page(elements) 

ade(function() {})

< 100k?


*/
