var hexa=["0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F"];
var a="0",b=a,color=a,colorfd=0,z=0,page="1";
position=["tout","haut gauche : ","milieu gauche : ","bas gauche : ","milieu : ","haut droite : ","bas droite : "];
g=[null,"290px","290px","290px","320px","345px","345px"];
h=[null,"190px","230px","270px","230px","200px","260px"];
// preload
pl0=new Image(); pl0.src="images/alea.png";
pl1=new Image(); pl1.src="images/colorator10.png";
pl10=new Image(); pl10.src="images/R.jpg";
pl11=new Image(); pl11.src="images/V.jpg";
pl12=new Image; pl12.src="images/B.jpg";
pl13=new Image(); pl13.src="images/nav.png";
pl14=new Image(); pl14.src="images/selcase.png";

var pseudo=getCookie('pseudo'),email=getCookie('email');

if (!pseudo) {pseudo="votre pseudo ?";}
if (!email) {email="votre email ?";}
visit_txt=pseudo +' &nbsp; ' +email;
function getCookie(Name) {
   var search = Name + "=";
   if (document.cookie.length > 0) { 
      offset = document.cookie.indexOf(search); 
      if (offset != -1) { 
         offset += search.length ;
         end = document.cookie.indexOf(";", offset); 
         if (end == -1) 
            end = document.cookie.length;
         return unescape(document.cookie.substring(offset, end));
      } 
   }
}

function sc(code){
page=code;

document.getElementById("curcase").style.left = g[page] ;
document.getElementById("curcase").style.top = h[page] ;
  var obj = eval('document.getElementById("im'+page+'").style') ;
obj=obj.backgroundColor;
obj=obj.slice(4,-1);
couleur=obj.split(',');
  xR=parseInt(couleur[0])  ;
  xV=parseInt(couleur[1])  ;
  xB=parseInt(couleur[2])  ;

    document.getElementById("curR").style.left=xR+400+"px";
    document.getElementById("curV").style.left=xV+400+"px";
    document.getElementById("curB").style.left=xB+400+"px";
document.getElementById("fdlogin").style.backgroundColor=eval('document.getElementById("im'+page+'").style.backgroundColor');
document.getElementById("fdcolorator").style.backgroundColor=eval('document.getElementById("im'+page+'").style.backgroundColor');
document.getElementById("test").innerHTML=position[page]+eval('document.getElementById("im'+page+'").style.backgroundColor') ;
enregistre();
}

function loge(){
document.getElementById("loge").style.visibility="visible";
}
function deloge(formul){
document.getElementById("loge").style.visibility="hidden";
}
var moving = false ;
var myattr ;
function start()
{ document.getElementById("curR").addEventListener("mousedown",beginDrag, false) ;
  document.getElementById("curV").addEventListener("mousedown",beginDrag, false) ;
  document.getElementById("curB").addEventListener("mousedown",beginDrag, false) ;
  //window.setCursor("auto") ;
  sc(1);
  document.getElementById("visitor").innerHTML=visit_txt;
  enregistre();
}
function beginDrag(e)
{ window.lastX=e.clientX ;
  myattr=e.target.getAttribute("ID") ;
  window.onmousemove=doDrag ;
  window.onmouseup=endDrag ;
  moving= true ;
  document.getElementById(myattr).style.zIndex=1 ;
  //event.preventDefault() ;
}
function doDrag(e)
{ if (moving)
  { var difX=e.clientX-window.lastX;
    var newX1 = parseInt(document.getElementById(myattr).style.left)+difX;
    if (newX1<400) {newX1=400};
    if (newX1>655) {newX1=655} ;   
    document.getElementById(myattr).style.left=newX1+"px";
    window.lastX=e.clientX;
    //event.preventDefault();
   }
}
function endDrag(e)
{ moving= false ;
  document.getElementById(myattr).style.zIndex=0 ;
  window.onmousemove=null ;
  window.onmouseup=null ;
  var objR = document.getElementById("curR").style ;
  var objV = document.getElementById("curV").style ;
  var objB = document.getElementById("curB").style ;  
  xR=parseInt(objR.left)-400 ; 
  xV=parseInt(objV.left)-400 ; 
  xB=parseInt(objB.left)-400 ;
  color="#"+hexa[Math.floor(xR/16)]+hexa[xR%16]+hexa[Math.floor(xV/16)]+hexa[xV%16]+hexa[Math.floor(xB/16)]+hexa[xB%16]
eval('document.getElementById("im'+page+'").style.backgroundColor=color');
eval('document.getElementById("fdlogin").style.backgroundColor=color');
eval('document.getElementById("fdcolorator").style.backgroundColor=color');
document.getElementById("test").innerHTML=position[page]+eval('document.getElementById("im'+page+'").style.backgroundColor');
enregistre();
}

function novimg() {
alea();
z = Math.random(7);z=5*z; z = Math.round(z)+1;
eval('document.getElementById("im'+z+'").style.backgroundColor=color');
eval('document.getElementById("fdlogin").style.backgroundColor=color');
eval('document.getElementById("fdcolorator").style.backgroundColor=color');
sc(z);
}
function alea(){
color="#";n=0;
for (n=0; n<=5; n++) {
a = Math.random(7);a=16*a; b = Math.round(a);b=hexa[b];
color=color+b;};
}

function enregistre() {
r="<br>";v=",";
obj1=document.getElementById("im1").style.backgroundColor.slice(4,-1);
obj2=document.getElementById("im2").style.backgroundColor.slice(4,-1);
obj3=document.getElementById("im3").style.backgroundColor.slice(4,-1);
obj4=document.getElementById("im4").style.backgroundColor.slice(4,-1);
obj5=document.getElementById("im5").style.backgroundColor.slice(4,-1);
obj6=document.getElementById("im6").style.backgroundColor.slice(4,-1);
sauv_obj=obj1+v+obj2+v+obj3+v+obj4+v+obj5+v+obj6+v;
dec=sauv_obj.split(",");sauv_obj="";
for (n=0; n<18;n++){
dec[n]="00"+dec[n];
l=dec[n].length-3;
sauv_obj+=dec[n].substr(l,3);
}
obj="<table cellpadding=4><tr><td>"+obj1+r+obj2+r+obj3+"</td><td>"+obj4+"</td><td>"+obj5+r+r+obj6+"</td></tr></table>";
//obj=obj+r+sauv_obj
document.getElementById("registre").innerHTML=obj;

}
