window.addEvent('domready', function() {

//Slide pour les produits.
	
	var verticalSlide = new Fx.Slide('conteneur_sous_menu');
	verticalSlide.hide();
	
	$('product').addEvent('click', function(e){

			var url = "menuProduit.php";
			var options = { 
						update : $('conteneur_sous_menu'), 
						method : 'post', 
						onRequest: function(){
							verticalSlide.hide();	
						}, 
						onComplete: function()
						{
							verticalSlide.slideIn();
						}
					};
			var ajax= new Ajax(url, options);			
			ajax.request();	
	});
		
	$('system_comp').addEvent('click', function(e){
			var url = "systemCompatible.php";
			var options = { 
						update : $('conteneur_sous_menu'), 
						method : 'post', 
						onRequest: function(){
							verticalSlide.hide();	
						}, 
						onComplete: function()
						{
							verticalSlide.slideIn();
						}
					};
			var ajax= new Ajax(url, options); 
			ajax.request();
	});
	
	//acccordéon
	var myAccordion = new Accordion($('accordion'), 'h4.togglerDoc', 'div.elementDoc', {
		opacity: false,
		onActive: function(toggler, element){
			toggler.setStyle('color', '#41464D');
		},
		onBackground: function(toggler, element){
			toggler.setStyle('color', '#528CE0');
		}
	});
	
	$('doc').addEvent('click', function(e) {
			var url = "getDoc.php";
			var options = { 
						update : $('conteneur_sous_menu'), 
						method : 'post', 
						onRequest: function(){
							verticalSlide.hide();	
						}, 
						onComplete: function()
						{
							verticalSlide.slideIn();
						}
					};
			var ajax= new Ajax(url, options); 
			ajax.request();
	});

	
	$$('img.toggler').addEvent('click', function(e)
	{
			if(this.alt == "+")
			{
				this.alt = "-";
				var ind = $$('img.toggler').indexOf(this);
				var element = $$('div.element');
				element[ind].setStyle('display','block');
			}
			else
			{
				this.alt = "+";
				var ind = $$('img.toggler').indexOf(this);
				var element = $$('div.element');
				element[ind].setStyle('display','none');
			}
	});
});

function affichComp(div,id)
{
	var ind = $$('img.toggler').indexOf(div);
	var element = $$('div.element');
	var url = "schemaComp.php";
	var options = { update : element[ind], method : 'post', 
		onRequest: function()
		{
				element[ind].innerHTML = '<img src="img/ajax-loader.gif" />';
		}};
		var ajax= new Ajax(url, options);
		var requestVar = {
                id: id
        };
		ajax.request(requestVar);	
}

function adaptateur(id)
{
	if($('comp:'+id).getStyle('display') == 'none')
		$('comp:'+id).setStyle('display','block');
	else
		$('comp:'+id).setStyle('display','none');
}



//Script de fondu.
// var open = 1;

// function fondu(id, opacity){
	// opacity = (!opacity ? 0 : opacity)+10;
	// var item = document.getElementById(id).style;
	// item.opacity = (opacity/100);
	// item.filter = 'alpha(opacity='+opacity+')'; 
	
	// if(opacity < 100){
		// var time = 100;
		// setTimeout('fondu(\''+id+'\', '+opacity+')', time);
	// }
// }

function change_image(photo)
{
	var url = "chargePhoto.php";
	var options = { update : $('image_categorie'), method : 'post', 
		onRequest: function()
		{
				$('image_categorie').innerHTML = '<img src="img/ajax-loader.gif" />';
		}};
		var ajax= new Ajax(url, options);
		var requestVar = {
                photo: photo
        };
		ajax.request(requestVar);
}




//Variable indiquant l'existance ou non du bloc "schema".
var check = 0;


function initCompatibilite()
{
	var schema = new Element('div', {id: 'schema'});
	schema.setStyle('backgroundColor','#FFF');
	schema.inject($('page'), 'top');
	check = 1;
}

function affSchema(_id,e,carte)
{
	if(check == 0)
	{
		initCompatibilite();
	}
	//-------------- Recuperation des coordonnées de la souris -------------------//
	var x;
	var y;
	if (navigator.appName=="Microsoft Internet Explorer") 
	{
		 	x = e.clientX + document.body.scrollLeft + 10;
			y = e.clientY + document.documentElement.scrollTop - 150;
	}
	else
	{
		x = e.pageX + 10;
		y = e.pageY - 150;
	}
		
	//----------------- Chargement du schema ----------------------------//
	if(carte == 1)
	{
		var url = "chargeCarte.php";
	}
	else
	{
		var url = "chargeImage.php";
	}
		var options = { update : $('schema'), method : 'post', 
		onRequest: function()
			{
				$('schema').setHTML('<div align="center"><img src="img/preloader.gif" alt="Chargement ..." /><br />loading ...</div>');
			}};
		var ajax= new Ajax(url, options);
		var requestVar = {
                var1: _id
        };
		ajax.request(requestVar);
		
	//------------------------- Style du bloc de schema ----------------------//
		$('schema').setStyles({
		border: '1px solid #000',
		position: 'absolute',
		top: y+'px',
		left: x+'px'
		});
		
	if (!e) var e = window.event;
	e.cancelBubble = true;
	if (e.stopPropagation) e.stopPropagation();


}

function suppSchema(div)
{
	if(div.getProperty('class')!="imgProd" && check == 1)
	{
		$('schema').remove();
		check = 0;
	}	
}


