
dojo.require("dojo.parser");
dojo.require("dojo.fx");
//dojo.require("dijit.layout.ContentPane");

mca={
	
	load:function(){
		//console.debug("...mca.load()");
		dojo.addOnUnload(function(){mca.unload();});
		//dojo.connect(window,"onbeforeunload",this,"beforeUnload");
		document.cookie="jsEnabled=1";
		this.flash.load();
		this.color.load();
		return true;
	},
	beforeUnload:function(e){
		//console.debug("...mca.beforeUnload()");
		//return true;
	},
	unload:function(){
		//console.debug("...mca.unload()");
		return true;
	},
	
	flash:{
		load:function(){
			//console.debug("..mca.flash.load()");
		},
		start:function(){
			//console.debug("..mca.flash.start()");
		},
		stop:function(){
			//console.debug("..mca.flash.stop()");
			var props = {
				backgroundColor:{
					start:dojo.getComputedStyle(dojo.byId("main")).backgroundColor,
					end:dojo.byId("page").style.backgroundColor
				}
			};
			//console.debug(props);
			var args = {
				node:"main",
				duration:2000,
				properties:props
			};
			//console.debug(args);
			this.bg = dojo.animateProperty(args);
			//console.debug(this.bg);
			this.bg.play();
		}
	},
	
	color:{
		
		duration:5000,
		anim:[],
		
		load:function() {
			//console.debug("...mca.color.load()");
			var elem = dojo.query(".color");
			//elem = [elem[0]];
			for(var i=0; elem[i]; i++) {
				var	bgTo = elem[i].getAttribute("bgTo"),
					bdTo = elem[i].getAttribute("bdTo");
					fgTo = elem[i].getAttribute("fgTo");
				if(bgTo || fgTo || bdTo) {
					var props = {};
					if(bgTo) {
						props.backgroundColor = { 
							start:elem[i].style.backgroundColor,
							end:bgTo
						};
					}
					if(bdTo) {
						props.borderColor = { 
							start:elem[i].style.borderColor,
							end:bdTo
						};
					}
					if(fgTo) {
						props.color = { 
							start:elem[i].style.color,
							end:fgTo
						};
					}
					var args = {
						node:elem[i],
						duration:this.duration,
						properties:props
					};
					this.anim[i] = dojo.animateProperty(args);
					this.anim[i].play();
				}
			}
			// play each anim individually (above)
			// prevents all anim from failing if one has error
			//if(this.anim.length > 0) {
			//	this.all = dojo.fx.combine(this.anim);
			//	this.all.play();
			//}
			return true;
		},
		beforeUnload:function(e){
			//console.debug("...mca.color.unload()");
		}
		
	}	
};

dojo.addOnLoad(function(){mca.load();});
