function slideReferences(node) {
	window.addEvent('domready', function() {
		var node_id = new Fx.Slide('id_'+node+'_child', {duration: 500});
		node_id.hide();
		
		$('id_'+node+'_parent').addEvent('click', function(e){
			e.stop();
			node_id.toggle();
		});
	});
}

function slideReferencesNotExtensible(node) {
	window.addEvent('domready', function() {
		var node_id = new Fx.Slide('id_'+node+'_child', {duration: 500});
		node_id.hide();
	});
}

function displayReferences(node) {
	var children = $('references').getChildren();
	//var clients = $('clients').getChildren();
	var clients = $('produits').getChildren();
	var produits = $('produits').getChildren();

	for (i = 0; i < clients.length; i++) {
		clients[i].set('class', 'left_menu_li');
		var img_cli = clients[i].getChildren();
		var img_cli_2 = img_cli[0].getChildren();
		img_cli_2[0].set('src', '/design/extellient/images/gmenu-puce-blanc.gif');
	}
	
	for (i = 0; i < produits.length; i++) {
		produits[i].set('class', 'left_menu_li');
		var img_svc = produits[i].getChildren();
		var img_svc_2 = img_svc[0].getChildren();
		img_svc_2[0].set('src', '/design/extellient/images/gmenu-puce-blanc.gif');
	}
	
	$(node).set('class', 'selected');
	$(node+'_img').set('src', '/design/extellient/images/gmenu-puce-orange.gif');
	$('ref_title').innerHTML = '<h1>Nos dernieres references "'+$(node+'_txt').get('text')+'"</h1>';
	
	for (i = 0; i < children.length; i++) {
		if (children[i].get('tag') != 'a') {
			if (node.substr(0, 3) == 'cli') {
				filter = children[i].get('id').substr(0, 7);
				
				if (filter.indexOf('_', 5) != -1) {
					filter = children[i].get('id').substr(0, 6);
				}
				
				if (filter != node) {
					children[i].style.display = "none";
				} else {
					children[i].style.display = "block";
				}
			
			} else {
				//filter = children[i].get('id').substr(7, 7);
				filter = children[i].get('id').substr(5, 7);
				
				var pos = filter.indexOf('svc_', 0);
				filter = filter.substr(pos + 4, 3);
				
				if (filter.indexOf('_') != -1) {
					filter = filter.substr(0, 2);
				}
				
				filter = 'svc_' + filter;
				
				if (filter != node) {
					children[i].style.display = "none";					
				} else {
					children[i].style.display = "block";
				}
			}
		}
	}
}

function displayReference(node) {
	window.addEvent('domready', function() {
		var node_id = new Fx.Slide('id_'+node+'_child', {duration: 200});
		node_id.show();
	});
	
	window.location = '#id_'+node;
}

function initReferences() {
	//var client = document.location.href.indexOf('cli_', 0);
	var client = document.location.href.indexOf('svc_', 0);
	var produit = document.location.href.indexOf("svc_", 0);
	var node = document.location.href.indexOf("id_", 0);
	
	if (client == -1 && produit == -1) {
		//return displayReferences('cli_71');
		return displayReferences('svc_74');
	}
	
	if (client != -1) {
		var node_client = document.location.href.substr(client + 4);
		
		node_client = node_client.substr(0, 3);
		if (node_client.indexOf('_') != -1) {
			node_client = node_client.substr(0, 2);
		}
		
		/*if (node == -1) {
			return displayReferences('cli_' + node_client);
		} else {
			type = 'cli_' + node_client;
		}*/
		if (node == -1) {
			return displayReferences('svc_' + node_client);
		} else {
			type = 'svc_' + node_client;
		}
		
	} else {
		var node_produit = document.location.href.substr(produit + 4);
		
		node_produit = node_produit.substr(0, 3);
		if (node_produit.indexOf('_') != -1) {
			node_produit = node_produit.substr(0, 2);
		}
		
		if (node == -1) {
			return displayReferences('svc_' + node_produit);
		} else {
			type = 'svc_' + node_produit;
		}
	}
	
	if (node != -1) {
		var node_id = document.location.href.substr(node + 3);
		
		node_id = node_id.substr(0, 3);
		if (node_id.indexOf('_') != -1) {
			node_id = node_id.substr(0, 2);
		}
		
		displayReferences(type);
		
		displayReference(node_id);
	}
}

