var ie=document.all;

var nn6=document.getElementById&&!document.all;

var isdrag=false;

//MODIF var x,y;
var x,y,tx=0,ty=0,tw,th,iw,ih;

var dobj;
var MyID;


function setdisplay(objj,visible)
{
    var i;

    if (objj.children)
    {
        for (i=0;i<objj.children.length;i++)
        {
            if (visible==false)
            {
                objj.children[i].style.display="none";
                objj.children[i].style.visibility="hidden";
            }
            else
            {
	            if (objj.children[i].id!="noremove") objj.children[i].style.display="";
	            if (objj.children[i].id!="noremove") objj.children[i].style.visibility="";
            }
        }
    }
    else
    {
        for (i=0;i<objj.childNodes.length;i++)
        {
            if (objj.childNodes[i].nodeType!=Node.TEXT_NODE)
            {
                if (visible==false)
	            {
	                objj.childNodes[i].style.display="none";
	                objj.childNodes[i].style.visibility="hidden";
	            }
	            else
	            {
		            if (objj.childNodes[i].id!="noremove") objj.childNodes[i].style.display="";
		            if (objj.childNodes[i].id!="noremove") objj.childNodes[i].style.visibility="";
	            }
	       }
        }
    }
}

function movemouse(e)

{
//MODIF 
	var ax,ay;
	
  if (isdrag)

  {
    ax= nn6 ? tx + (e.clientX - x)*100/100 : tx + (event.clientX - x)*100/100;
    if (ax>0) ax=0;
	if (ax+iw<tw+1) ax=tw-iw+1;

    ay= nn6 ? ty + (e.clientY - y)*100/100 : ty + (event.clientY - y)*100/100;
    if (ay>0) ay=0;
	if (ay+ih<th) ay=th-ih;
	
    dobj.style.backgroundPosition=ax+"px "+ay+"px";

    return false;

  }
}



function selectmouse(e)

{

  var fobj       = nn6 ? e.target : event.srcElement;

  var topelement = nn6 ? "HTML" : "BODY";

  while (fobj!=null && fobj.tagName != topelement && fobj.className != "dragme")

  {

    fobj = nn6 ? fobj.parentNode : fobj.parentElement;

  }
  if (fobj==null) return;
    
  var ok=(MyID=="index"||MyID=="bandeau-centre"||MyID=="communication"||MyID=="travail-personnel"||MyID=="bande-dessinee"||MyID=="carnet-croquis"||
		  MyID=="contact"||MyID=="blog"||MyID=="liens");

  if (fobj.className=="dragme"&&ok==true)

  {
    isdrag = true;
    setdisplay(fobj,false);
    fobj.style.cursor="url(images/Cursor_smiley.cur),crosshair";

    dobj = fobj;

    var nam=dobj.style.backgroundPosition;
    tx=parseInt(nam.substring(0,nam.indexOf(" ")));
    ty=parseInt(nam.substring(nam.indexOf(" ")+1,nam.length));

    if (dobj.style.background.indexOf("_drag")==-1)
    {
        nam=dobj.style.background.substring(0,dobj.style.background.indexOf("."))+"_drag"+dobj.style.background.substr(dobj.style.background.indexOf("."),dobj.style.background.length);
        dobj.style.background=nam;
    }
//    dobj.style.backgroundPosition=tx+"px "+ty+"px";

//MODIF     
	var de = document.documentElement;
	tw = window.innerWidth || self.innerWidth || (de&&de.clientWidth) || document.body.clientWidth;
	th = window.innerHeight || self.innerHeight || (de&&de.clientHeight) || document.body.clientHeight;

var pic = new Image();
var nam=dobj.style.backgroundImage.substring(dobj.style.backgroundImage.indexOf("(")+1,dobj.style.backgroundImage.indexOf(")"));
pic.src = nam;
iw=pic.width;
ih=pic.height;
    
    x = nn6 ? e.clientX : event.clientX;

    y = nn6 ? e.clientY : event.clientY;

    document.onmousemove=movemouse;

    return false;

  }

}

function upmouse(e)
{
	var fobj       = nn6 ? e.target : event.srcElement;
	var topelement = nn6 ? "HTML" : "BODY";

	while (fobj.tagName != topelement && fobj.className != "dragme")
	{
		fobj = nn6 ? fobj.parentNode : fobj.parentElement;
	}
	if (fobj.className=='dragme')
	{
        setdisplay(fobj,true);
	}
    if (isdrag==true) fobj.style.cursor="url(images/question.cur),crosshair";
	isdrag = false;

//    var nam=fobj.style.backgroundPosition;
//    tx=parseInt(nam.substring(0,nam.indexOf(" ")));
//    ty=parseInt(nam.substring(nam.indexOf(" ")+1,nam.length));

    if (fobj.style.background.indexOf("_drag")!=-1)
    {
        nam=fobj.style.background.substring(0,fobj.style.background.indexOf("_drag"))+fobj.style.background.substr(fobj.style.background.indexOf("."),fobj.style.background.length);
        fobj.style.background=nam;
    }
//    fobj.style.background="url(images/fond.jpg)";
//    fobj.style.backgroundPosition=tx+"px "+ty+"px";
}

function hop(e)
{
	var fobj       = nn6 ? e.target : event.srcElement;

	MyID=fobj.id;
    var ok=(MyID=="index"||MyID=="bandeau-centre"||MyID=="communication"||MyID=="travail-personnel"||MyID=="bande-dessinee"||MyID=="carnet-croquis"||
	    	MyID=="contact"||MyID=="blog"||MyID=="liens");

	var topelement = nn6 ? "HTML" : "BODY";
	while (fobj.tagName != topelement && fobj.className != "dragme")
	{
		fobj = nn6 ? fobj.parentNode : fobj.parentElement;
	}

	if (fobj.className=='dragme'&&isdrag ==false)
	{
        if (ok==true) fobj.style.cursor="url(images/question.cur),crosshair";
        else fobj.style.cursor="default";
	}
}

document.onmousedown=selectmouse;

document.onmouseup=upmouse;
