var tour=3;
var cz=5
var dde=document.documentElement;

function disableselecte(e){
return false;
}
function enableselecte(e){
return true;
}

function tarto(s){
if(navigator.appName.substring(0,3)=="Net"){
setY = s.clientY+dde.scrollTop;
setX = s.clientX+dde.scrollLeft;
}
else{
setY=event.y+dde.scrollTop;
setX=event.x+dde.scrollLeft;
return false;
}
}

if(navigator.appName.substring(0,3)=="Net"){
dde.addEventListener("mousemove", tarto, false);
}
else{
dde.attachEvent('onmousemove', tarto);
}


function centrezoom(){
if(adi.offsetWidth<adi.parentNode.offsetWidth/1.5 && adi.offsetWidth>adi.offsetHeight){
raz();
}
if(adi.offsetHeight<adi.parentNode.offsetHeight/1.5 && adi.offsetHeight>adi.offsetWidth){
raz();
}
if(tour==2){
document.onmousedown=enableselecte;
tour=3;
return false;
}
if(tour==3){
py=setY;
tour=1;
adi=document.getElementById('divim');
}
var dirle=(adi.offsetWidth/2)-((adi.parentNode.offsetWidth/2)-(adi.offsetLeft));
var dirto=(adi.offsetHeight/2)-((adi.parentNode.offsetHeight/2)-(adi.offsetTop));
var lf=adi.offsetWidth;
var rf=adi.offsetHeight;
if(setY!=py){  
if(setY<py){
var cons=((setY-py)/(setY-py))/100*6;
}
if(setY>py){
var cons=-((setY-py)/(setY-py))/100*6;
}
adi.style.width=(lf*(1+cons))+'px';
adi.style.height=(rf*(1+cons))+'px';
adi.style.left=adi.offsetLeft-((adi.offsetWidth-lf)/2)+(dirle*cons)+'px';
adi.style.top=adi.offsetTop-((adi.offsetHeight-rf)/2)+(dirto*cons)+'px';
}
dde.onmousedown=disableselecte;
py=setY;
setTimeout(centrezoom,15);
}

function cadrezoom(){
if(cz==5){
oper=adi.offsetWidth/adi.offsetHeight;
px=setX;
py=setY;
adi=document.getElementById('divim');
adi.parentNode.appendChild(document.createElement('div')).setAttribute("id",'cadre');
cd=document.getElementById('cadre');
cd.style.position='absolute';
cd.style.top=setY-adi.parentNode.offsetTop+"px";
cd.style.left=setX-adi.parentNode.offsetLeft+"px";
cd.style.height = 10+"px";
cd.style.width = 10+"px";
cd.style.minWidth  =20+"px";
cd.style.minHeight =20+"px";
cd.style.backgroundColor='black';
if(document.all && !window.opera){ 
cd.style.filter = 'alpha(opacity=25)';
} 
else{ 
cd.style.opacity = 0.3;
}
cz=0
cd.setAttribute("onmouseup","tour=2");
}
if(tour==2){
document.onmousedown=enableselecte;
cz=5;
bour=(adi.offsetLeft-cd.offsetLeft)/adi.offsetWidth;
boul=(adi.offsetTop-cd.offsetTop)/adi.offsetHeight;
adi.style.height=adi.offsetHeight*(adi.parentNode.offsetHeight/cd.offsetHeight)+'px';
adi.style.width=adi.offsetHeight*oper+'px';
adi.style.left=bour*adi.offsetWidth+'px';
adi.style.top=boul*adi.offsetHeight+'px';
cd.parentNode.removeChild(cd);
return false;
}
cd.style.height = (cd.offsetHeight+(setY-py))+"px";
cd.style.width = (cd.offsetWidth)+(setX-px)+"px";
document.onmousedown=disableselecte;
px=setX;
py=setY;
setTimeout(cadrezoom,15);
}


function dirizoom(e){

if(tour==3){
if(navigator.appName.substring(0,3)!="Mic" && e.button == 1 || navigator.appName.substring(0,3)=="Mic" && event.button == 4){
sp();
return false;
}
if(navigator.appName.substring(0,3)!="Mic" && e.button == 2 || navigator.appName.substring(0,3)=="Mic" && event.button == 2){
val=-0.03;
}
else{
val=0.03;
}
tour=0;
}
if(tour==2){
tour=3;
document.onmousedown=enableselecte;
return false;
}
adi=document.getElementById('divim');
var dirle=(adi.offsetWidth/2)-(setX-(adi.parentNode.offsetLeft+adi.offsetLeft));
var dirto=(adi.offsetHeight/2)-(setY-(adi.parentNode.offsetTop+adi.offsetTop));
var lf=adi.offsetWidth;
var rf=adi.offsetHeight;
adi.style.width=lf+(lf*val)+'px';
adi.style.height=rf+(rf*val)+'px';
adi.style.left=adi.offsetLeft-((adi.offsetWidth-lf)/2)+(dirle*val)+'px';
adi.style.top=adi.offsetTop-((adi.offsetHeight-rf)/2)+(dirto*val)+'px';
document.onmousedown=disableselecte;
setTimeout(dirizoom,15);
}
function sp(){
if(tour==2){
document.onmousedown=enableselecte;
tour=3;
return false;
}
if(tour==3){
px=setX;
py=setY;
tour=0;
adi=document.getElementById('divim');
}
adi.style.left=(adi.offsetLeft+setX-px)+'px';
adi.style.top=(adi.offsetTop+setY-py)+'px';
document.onmousedown=disableselecte;
px=setX;
py=setY;
setTimeout(sp,10);
}

function dispatche(quelle){
adi=document.getElementById('divim');
if(quelle=='zoom'){
adi.style.cursor='n-resize';
adi.onmousedown=centrezoom;
}
if(quelle=='drag'){
adi.style.cursor='move';
adi.onmousedown=sp;
}
if(quelle=='dirizoom'){
adi.style.cursor='auto';
adi.onmousedown=dirizoom;
}
if(quelle=='cadrezoom'){
cz=5
adi.style.cursor='auto';
adi.onmousedown=cadrezoom;
}

}
function raz(){
adi=document.getElementById('divim');
oper=adi.offsetWidth/adi.offsetHeight;
adi.style.height=400+'px';
adi.style.width=oper*400+'px';
adi.style.left=((adi.parentNode.offsetWidth-adi.offsetWidth)/2)+'px';
adi.style.top=((adi.parentNode.offsetHeight-adi.offsetHeight)/2)+'px';
}
