function show2(e){
	if(!e)return;
	var a=e.coords.split(',');
	var c=$('selected').getContext('2d');
	c.clearRect(0,0,w,h);
	c.beginPath();
	if(e.shape.toLowerCase()=='rect'){
		c.lineWidth=5;
		c.lineJoin='round';
		c.strokeStyle="rgba(255,0,0,0.8)";
		c.strokeRect(a[0]-0,a[1]-0,a[2]-a[0],a[3]-a[1]);
	}else{
		c.moveTo(a[0],a[1]);
		for(i=2,j=a.length;i<j;i+=2)
			c.lineTo(a[i]-0,a[i+1]-0);
		c.strokeStyle="rgba(255,0,0,0.8)";
		c.stroke();
	}
}
function show(nr){
	if(typeof(nr)=='object')nr=nr.getAttribute('nr');
	var p=koords[nr].split(' ');
	var c=$('selected').getContext('2d');
	c.clearRect(0,0,w,h);
		c.beginPath();
		c.lineCap=c.lineJoin='round';
		c.lineWidth=25;
		c.strokeStyle='rgba(255,255,0,0.9)';
		if(p.length==1 && p[0]!=''){
			t=p.shift().split('x');
			c.strokeRect(t[0]-2,t[1]-2,4,5);
		}
		else if(p.length>1){
			var cmd='m';
			while(t=p.shift()){
				if(t.length==1){cmd=t;continue;}
				t=t.split('x');
				switch(cmd){
					case'm':c.moveTo(t[0],t[1]);cmd='';break;
					default:c.lineTo(t[0],t[1]);break;
				}
			}
			c.stroke();
		}
}
Array.prototype.arrRotate=function(){
var b=this.shift();
this.push(b);
return b;
}
function showKoords(){
	var g=new Array().concat(koords);
	var c=$('tracks').getContext('2d');
	var t;
	var ca=[
'255,0,0','0,255,0','0,0,255',
'0,221,255','255,0,255','255,187,0',
'128,0,0','0,128,0','0,34,238','153,0,255',
'255,255,0','255,128,0','128,255,0','0,128,255','128,128,255','0,255,0','0,0,255','255,128,0','128,255,0','0,128,255','128,128,255'];
	c.clearRect(0,0,600,600);
	while(p=g.shift()){
		c.beginPath();
		c.lineCap=c.lineJoin='round';
		// c.lineWidth=9;
		// c.strokeStyle='rgba('+(ca.arrRotate())+',0.9)';
		p=p.split(' ');
		if(p.length==1 && p[0]!=''){
			t=p.shift().split('x');
			c.strokeRect(t[0]-2,t[1]-2,4,5);
		}
		else if(p.length>1){
			var cmd='m';
			while(t=p.shift()){
				if(t.length==1){cmd=t;continue;}
				t=t.split('x');
				switch(cmd){
					// case'n':
						// c.stroke();
						// c.strokeStyle='rgba('+(ca.shift())+',0.8)';
						// c.moveTo(t[0],t[1]);
						// cmd='';
						// break;
					case'm':c.moveTo(t[0],t[1]);cmd='';break;
					default:c.lineTo(t[0],t[1]);break;
				}
			}
			c.lineWidth=9;
			c.strokeStyle='rgba('+ca.arrRotate()+',.9)';
			c.stroke();
		}

	}
}
var koords;
window.addEvent('load',function(){
	$$('map area').each(function(e){
		e.addEvent('mouseover',function(){
			show(this);
		})
		e.addEvent('mouseout',function(){
			$('selected').getContext('2d').clearRect(0,0,w,h);
		})
	});
	$$('div.navL a').each(function(e){
		var z=$(e).getAttribute('nr');
		e.addEvent('mouseover',function(){
			show(z);
		})
		e.addEvent('mouseout',function(){
			$('selected').getContext('2d').clearRect(0,0,w,h);
		})
	});
	koords=$('koords').innerHTML.split(' n ');
	showKoords();
});
