Magma = {
	
	active:"",previous:"",
	
	start:function(){
		Magma.items = $$('li.thumbitem');
		Magma.activateThumb();
		new Ajax('magma.xml',{onComplete:function(resp){
			Magma.json = xml2json.parser(resp);}
			}).request();
	},
	
	activateThumb:function(){
		var Mmenu = Magma.items;
		var fx = new Fx.Elements(Mmenu, {wait:false,duration:200,transition:Fx.Transitions.sineInOut,
								onStart:function(){
									if(Magma.active != Magma.previous && Magma.previous != "")
										Magma.clearText(Magma.previous);

									},
								onComplete:function(){
									if(Magma.active != "")
										Magma.showText(Magma.active);
									Magma.previous = Magma.active;
									}
								});
		Mmenu.each(function(thumb,i){
			thumb.addEvent('mouseover',function(ev){
				Magma.active = this.id
				//console.log(this.id);
				ev = new Event(ev).stop();
				var obj = {};
				var tw = thumb.getStyle('width').toInt();
				//obj[i] = {'width': [tw, 110],'padding-left':[0,50]}
				obj[i] = {'width': [tw, 110]};
				Mmenu.each(function(other,j){
					if (other != thumb){
						//var p = other.getStyle('padding-left').toInt();
						//if(p>0) obj[j] = {'padding-left':[p,0]};
						var w = other.getStyle('width').toInt();
						if (w != 20) obj[j] ={'width': [w, 20]};
						
					}																		
				});
				fx.start(obj);
			})
			
		});
		
	},
	
	showText:function(el){
		//console.log("show: "+el);
		var indx = el.substr(2).toInt()-1;
		var jnode = Magma.json.magma.shades.shade[indx];
		//$(el).setStyle('padding-left','40px');
		$(el).setHTML(jnode.code+"<br/>"+jnode.name);
		
	},
	
	clearText:function(el){
		//$(el).setStyle('padding-left','0px');
		$(el).setHTML("");
	}
	
	
}

window.addEvent('domready',Magma.start);