// JavaScript Document
function ele(divid) {return document.getElementById(divid);}

function wh(wh) {return wh.substring(0,(wh.length-2));}

var mousex = 0;
var mousey = 0;
var grabx = 0;
var grabx2 = 0;
var graby = 0;
var orix = 0;
var orix2 = 0;
var oriy = 0;
var elex = 0;
var elex2 = 0;
var eley = 0;
var algor = 0;
var rapport = 1;
var rapport2 = 1;

var dragobj = null;
var dragobj2 = null;

function falsefunc() { return false; } // used to block cascading events

function init()
{
  document.onmousemove = update; // update(event) implied on NS, update(null) implied on IE
  update();
}

function getMouseXY(e) // works on IE6,FF,Moz,Opera7
{ 
  if (!e) e = window.event; // works on IE, but not NS (we rely on NS passing us the event)

  if (e)
  { 
    if (e.pageX || e.pageY)
    { // this doesn't work on IE6!! (works on FF,Moz,Opera7)
      mousex = e.pageX;
      mousey = e.pageY;
      algor = '[e.pageX]';
      if (e.clientX || e.clientY) algor += ' [e.clientX] '
    }
    else if (e.clientX || e.clientY)
    { // works on IE6,FF,Moz,Opera7
      mousex = e.clientX + document.body.scrollLeft;
      mousey = e.clientY + document.body.scrollTop;
      algor = '[e.clientX]';
      if (e.pageX || e.pageY) algor += ' [e.pageX] '
    }  
  }
}

function update(e)
{
  getMouseXY(e); // NS is passing (event), while IE is passing (null)

/*
  document.getElementById('onglet').style.position = 'absolute';
  document.getElementById('onglet').style.left = mousex +'px';
  document.getElementById('onglet').style.top = mousey +'px';
*/
}

function grab(context,context2)
{
  document.onmousedown = falsefunc; // in NS this prevents cascading of events, thus disabling text selection
  dragobj = context;
  dragobj2 = context2;
  //dragobj.style.zIndex = 10; // move it to the top
/*
if (wh(dragobj2.style.left)>0) {
}
*/
  document.onmousemove = drag;
  document.onmouseup = drop;
  grabx = mousex;
  grabx2 = mousex;
  //graby = mousey;
  elex = orix = dragobj.offsetLeft;
  elex2 = orix2 = dragobj2.offsetLeft;
  //eley = oriy = dragobj.offsetTop;
  update();
}

function drag(e) // parameter passing is important for NS family 
{
  if (dragobj2)
  {
    elex2 = orix2 + 1*(mousex-grabx2)*rapport2;
    //eley = oriy + (mousey-graby);
    //dragobj.style.position = "relative";
	if (elex2>7) {
		if (elex2>(wh(ele('div_ascenceur').style.width)-wh(dragobj2.style.width)-7)) {
			elex2 = orix2 = wh(ele('div_ascenceur').style.width)-wh(dragobj2.style.width)-7;
		}
	} else {
		elex2 = orix2 = 7;
	}
	dragobj2.style.left = (elex2).toString(10) + 'px';
	dragobj2.title=' width total='+wh(dragobj.style.width)+' '+(elex)+' '+elex2;
    //dragobj.style.top  = (eley).toString(10) + 'px';
  }
  if (dragobj)
  {
    elex = orix + -1*(mousex-grabx)*rapport;
    //eley = oriy + (mousey-graby);
    //dragobj.style.position = "relative";
	if (elex<(wh(ele('div_diabolo_0').style.width)/rapport)) {
		if (elex<(wh(ele('div_diabolo_0').style.width)-wh(dragobj.style.width))) {
			elex = orix = wh(ele('div_diabolo_0').style.width)-wh(dragobj.style.width);
		}
	} else {
		elex = orix = (wh(ele('div_diabolo_0').style.width)/rapport);
		//wh(ele('div_diabolo_0').style.width)-wh(dragobj.style.width);
	}
	dragobj.style.left = (elex).toString(10) + 'px';
	//dragobj.style.top  = (eley).toString(10) + 'px';
  }
  update(e);
  return false; // in IE this prevents cascading of events, thus text selection is disabled
}

function drop()
{
  if (dragobj)
  {
    //dragobj.style.zIndex = 0;
    dragobj = null;
  }
  if (dragobj2)
  {
    //dragobj.style.zIndex = 0;
    dragobj2 = null;
  }
  update();
  document.onmousemove = update;
  document.onmouseup = null;
  document.onmousedown = null;   // re-enables text selection on NS
}



			var xhry = null; 
	 
	 		function getXhr(){
				if(window.XMLHttpRequest) // Firefox et autres
				   xhry = new XMLHttpRequest(); 
				else if(window.ActiveXObject){ // Internet Explorer 
				   try {
			                xhry = new ActiveXObject("Msxml2.XMLHTTP");
			            } catch (e) {
			                xhry = new ActiveXObject("Microsoft.XMLHTTP");
			            }
				}
				else { // XMLHttpRequest non supporté par le navigateur 
				   alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest..."); 
				   xhry = false; 
				}
				return xhry;
			}
			
			function doo(fichier,ele,var_post,val_post){
				var xhrdoo = null;
				xhrdoo=getXhr();
				xhrdoo.onreadystatechange = function(){
				alert('xhrdoo.status='+xhrdoo.status+' et xhrdoo.readyState='+xhrdoo.readyState);
					if(xhrdoo.readyState == 4 && xhrdoo.status == 200){
						leselect = xhrdoo.responseText;
						document.getElementById(ele).innerHTML = leselect;
					}
				}
				xhrdoo.open('GET',fichier,true);
				xhrdoo.send(var_post + "=" + val_post);
				
			}

function ajax_url(div,url) {
	new Ajax(url, {
		method: 'get',
		update: $(div),
		evalScripts: true,
		evalResponse: false
	}).request();
}


function hp_init()
{
var asto=setTimeout('document.getElementById(\'txt_pignon\').innerHTML=\'is under Reconstruction ...\';',2000);	
//asto=setTimeout('doo(\'home_page.php\',\'tt\',\'?\',\'?\')',2000);	
//asto=setTimeout('window.location=\'home_page.php\';',2000);	
}
  
function active_menu_top(menu) {
var d=document.getElementById('menu_top_rose_marie');
d.style.color='#999999';
d.style.background='#333333';
//.class='menu_top_rose_marie';
var d=document.getElementById('menu_top_galerie');
d.style.color='#999999';
d.style.background='#333333';
//document.getElementById('menu_top_galerie').class='menu_top_galerie';
var d=document.getElementById('menu_top_contact');
d.style.color='#999999';
d.style.background='#333333';
//document.getElementById('menu_top_contact').class='menu_top_contact';
d=document.getElementById(menu);
d.style.color='#CCCCCC';
d.style.background='#111111';
	//d.class="'"+menu+"'"+'_actif';
}