// script.aculo.us scriptaculous.js v1.7.0, Fri Jan 19 19:16:36 CET 2007

// Copyright (c) 2005, 2006 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us)
// 
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
// 
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
// For details, see the script.aculo.us web site: http://script.aculo.us/

var Scriptaculous = {
  Version: '1.7.0',
  require: function(libraryName) {
    // inserting via DOM fails in Safari 2.0, so brute force approach
    document.write('<script type="text/javascript" src="'+libraryName+'"></script>');
  },
  load: function() {
    if((typeof Prototype=='undefined') || 
       (typeof Element == 'undefined') || 
       (typeof Element.Methods=='undefined') ||
       parseFloat(Prototype.Version.split(".")[0] + "." +
                  Prototype.Version.split(".")[1]) < 1.5)
       throw("script.aculo.us requires the Prototype JavaScript framework >= 1.5.0");
    
    $A(document.getElementsByTagName("script")).findAll( function(s) {
      return (s.src && s.src.match(/scriptaculous\.js(\?.*)?$/))
    }).each( function(s) {
      var path = s.src.replace(/scriptaculous\.js(\?.*)?$/,'');
      var includes = s.src.match(/\?.*load=([a-z,]*)/);
      (includes ? includes[1] : 'builder,effects,dragdrop,controls,slider').split(',').each(
       function(include) { Scriptaculous.require(path+include+'.js') });
    });
  }
}

Scriptaculous.load();



// les onglet dynamique sur plussieur niveau :

//SuckerTree Horizontal Menu (Sept 14th, 06)
//By Dynamic Drive: http://www.dynamicdrive.com/style/

var menuids=["treemenu1"] //Enter id(s) of SuckerTree UL menus, separated by commas

function buildsubmenus_horizontal(){
for (var i=0; i<menuids.length; i++){
  var ultags=document.getElementById(menuids[i]).getElementsByTagName("ul")
    for (var t=0; t<ultags.length; t++){
		if (ultags[t].parentNode.parentNode.id==menuids[i]){ //if this is a first level submenu
			ultags[t].style.top=ultags[t].parentNode.offsetHeight+"px" //dynamically position first level submenus to be height of main menu item
			ultags[t].parentNode.getElementsByTagName("a")[0].className="mainfoldericon"
		}
		else{ //else if this is a sub level menu (ul)
		  ultags[t].style.left=ultags[t-1].getElementsByTagName("a")[0].offsetWidth+"px" //position menu to the right of menu item that activated it
    	ultags[t].parentNode.getElementsByTagName("a")[0].className="subfoldericon"
		}
    ultags[t].parentNode.onmouseover=function(){
    this.getElementsByTagName("ul")[0].style.visibility="visible"
    }
    ultags[t].parentNode.onmouseout=function(){
    this.getElementsByTagName("ul")[0].style.visibility="hidden"
    }
    }
  }
}

if (window.addEventListener)
window.addEventListener("load", buildsubmenus_horizontal, false)
else if (window.attachEvent)
window.attachEvent("onload", buildsubmenus_horizontal)




// OVERTRAIL
var OverTrailHeight, OverTrailWidth;
function OverTrail(imagename,width,height) {
	cadre = 0;
	OverTrailWidth = width+cadre;
	OverTrailHeight = height+cadre;
	document.getElementById("overtrail").innerHTML = '<img src="' + imagename + '" border="0">';
	document.onmousemove = FollowMouse;
}
function HideTrail() {
	document.getElementById("overtrail").style.visibility="hidden";
	document.onmousemove="";
}
function FollowMouse(e) {
	x=15, y=-150;
	xmax=document.all? document.body.clientWidth+document.body.scrollLeft : window.innerWidth+window.pageXOffset-15;
	ymax=document.all? document.body.clientHeight+document.body.scrollTop : window.innerHeight+window.pageYOffset-15;
	if (typeof e != "undefined") {
		x+=e.pageX; y+=e.pageY;
	} else if (typeof window.event !="undefined") {
		x+=document.body.scrollLeft+event.clientX; y+=document.body.scrollTop+event.clientY;
	}
	if (x+OverTrailWidth>xmax) x=x-OverTrailWidth-30;
	if (y+OverTrailHeight>ymax) y=y-OverTrailHeight-15;
	document.getElementById("overtrail").style.left=x+"px";
	document.getElementById("overtrail").style.top=y+"px";
	document.getElementById("overtrail").style.visibility="visible";
}



function PopupPic(sPicURL) 
{
	window.open('popups/voir_img.php?mod=images&action=preview&view=prod&image='+sPicURL, '', 'status=1,resizable=1,HEIGHT=200,WIDTH=200,top=400,left=350');
 }

 function PopupPicfiche(sPicURL) 
{
	window.open('popups/voir_img.php?mod=images&action=preview&view=fiche&image='+sPicURL, '', 'status=1,resizable=1,HEIGHT=200,WIDTH=200,top=400,left=350');
 }
	
	
	


var delay = 100;
var timeout;
var timeout2;
var nbItems = 0;
var nbSubItems = 0;
var idPereActif = '';

function showMenu(num)
{
	id = 'menu_' + num;
	idpere = 'menup_' + num;
	idlink = 'menu-btn_' + num;
	
	if(num==1)
		var decalage = 0;
	else
		var decalage = 0;
	
	hideAll();
	cancelDelay();
	el = getElement(id);
	
	var pos = getPos(document.getElementById(idpere));
	if(window.innerWidth)
	{
		largeurFenetre = window.innerWidth;
	}
	else
	{
		largeurFenetre = document.body.offsetWidth;
	}
	if(largeurFenetre < 560)
	{
		largeurFenetre = 550;
	}
	if((pos.x + 100) >= largeurFenetre)
	{
		el.left = (pos.x - decalage - 75) + 'px';
	}
	else
	{
		el.left = (pos.x - decalage) + 'px';
	}
	el.top = (pos.y + 27) + 'px';
	


	if(document.getElementById(idlink).className!='btn_on_' + num){
	document.getElementById(idlink).className='btnHover_' + num;
	}
	document.getElementById(id).className='menu-on';
}

function showSubmenu(num, numPere)
{
	id = 'submenu_' + num;
	idpere = 'menu_' + numPere;
	
	hideAllSub();
	cancelDelay();
	cancelSubDelay();
	el = getElement(id);
	
	var pos = getPos(document.getElementById(idpere));
	var largeur = document.getElementById(idpere).offsetWidth - 6;
	document.getElementById(idpere).className='sub-menu-ss-actif';
	idPereActif = idpere;
	document.getElementById(id).className='submenu-on';
	if(window.innerWidth)
	{
		largeurFenetre = window.innerWidth;
	}
	else
	{
		largeurFenetre = document.body.offsetWidth;
	}
	if(largeurFenetre < 550)
	{
		largeurFenetre = 550;
	}
	if((pos.x + 300) >= largeurFenetre)
	{
		el.left = (pos.x - document.getElementById(id).offsetWidth) + 'px';
	}
	else
	{
		el.left = (pos.x + largeur) + 'px';
	}
	el.top = (pos.y + 3) + 'px';
}

function hideAll(num)
{
	
	for(var i=1; i<=nbItems; i++)
	{
		if(document.getElementById('menu-btn_' + i).className!='btn_on_' + i){
		document.getElementById('menu-btn_' + i).className='btn_' + i;
		}
		document.getElementById('menu_' + i).className='menu-off';
	}
}

function hideAllSub()
{
	for(var i=1; i<=nbSubItems; i++)
	{
		document.getElementById('submenu_' + i).className='submenu-off';
	}
	if(idPereActif != '')
	{
		document.getElementById(idPereActif).className='sub-menu-ss';
		idPereActif = '';
	}
}

function hideDelay()
{
	timeout = setTimeout('hideAll()', delay);
}

function hideSubDelay()
{
	timeout2 = setTimeout('hideAllSub()', delay);
}

function cancelDelay()
{
	clearTimeout(timeout);
}

function cancelSubDelay()
{
	cancelDelay();
	clearTimeout(timeout2);
}

function getPos(element)
{
	for(var lx=0,ly=0; element!=null; lx+=element.offsetLeft,ly+=element.offsetTop,element=element.offsetParent)
		;
	return {x:lx,y:ly};
}

function getElement(id)
{
	// getElementById ==> Navigateurs recents supportant le DHTML
	// document.layers ==> Netscape 4.x
	el = document.all ? document.all[id] : document.getElementById ? document.getElementById(id) : document.layers[id];
	el = document.layers ? el : el.style;
	return el;
}

