var navArrowSlider = function(navWrap, navElementsArray, activeID, subnavElementsArray, arrowY, leftOffset) {
	$$(subnavElementsArray).each(function(subnav) {
		$(subnav).set('slide', { duration: 1000, transition: Fx.Transitions.Elastic.easeOut });
		$(subnav).slide('hide');
	});

	var youAreHere = new Fx.Morph($("tabOrange"), { 
		duration: 500,
		transition: Fx.Transitions.Back.easeInOut  
	});
	var currentItem;

	$$(navElementsArray).each(function(item){
		item.addEvent('mouseenter', function() {
			if (currentItem) {
				if (currentItem.getElement('a')) {
					var currentItemColorFx = new Fx.Tween (currentItem.getElement('a'), { 
						duration: 300
					});
					currentItemColorFx.start('color', '#9c866a');
				}
			}

//			var thisPos = item.getPosition(navWrap).x + item.getSize().x - leftOffset;
			if (item.hasClass("nav1Home")) {
				var tabWidth = 60;
				var thisPos = 0;
			} else {
				var tabWidth = item.getSize().x + 2;
				var thisPos = item.getPosition(navWrap).x + 5;
			}
			// Firefox
			if (Browser.Engine.gecko)
				thisPos += 318;

			youAreHere.cancel();
//			youAreHere.start('background-position', thisPos + 'px ' + arrowY + 'px');
			//youAreHere.set('width', tabWidth + 'px');
			youAreHere.start({'left': thisPos + 'px', 'width': tabWidth + 'px'});
			var colorFx = new Fx.Tween (item.getElement('a'), { 
				duration: 300
			});
			colorFx.start('color', '#FFFFFF');
			if (item.hasClass("nav1Home"))
				$$(".nav1Home")[0].innerHTML = "<a href=\"core.php?pag_id=" + $$(".nav1Home")[0].getProperty("rel") + "\"><img src=\"../medias/img/nav1_home_on.png\" width=\"17\" height=\"21\" style=\"margin-top:6px\" /></a>";
			else
				$$(".nav1Home")[0].innerHTML = "<a href=\"core.php?pag_id=" + $$(".nav1Home")[0].getProperty("rel") + "\"><img src=\"../medias/img/nav1_home_off.png\" width=\"17\" height=\"21\" style=\"margin-top:6px\" /></a>";

			// réinitialisation des positions des sous-nav
			$$(subnavElementsArray).each(function(subnav) {
				subnav.set('styles', {'position': 'static'});
			});
			// positionnement de la sous-nav adéquate
			if ($(item.getProperty("rel"))) {
				$(item.getProperty("rel")).set('styles', {'display': 'inline'});
				var subnavWidth = $(item.getProperty("rel")).getSize().x;
				subnavWidth = (subnavWidth == 0) ? 0: subnavWidth
				var thisPos = item.getPosition(navWrap).x + 10;
				if ((thisPos + subnavWidth) > $("nav1Wrapper").getSize().x)
					subnavPos = $("nav1Wrapper").getSize().x - subnavWidth;
				else
					subnavPos = thisPos;
				
				$(item.getProperty("rel")).set('styles', {'position': 'absolute', 'left': subnavPos + 'px'});
			}

			// dissimulation de toutes les autres sous-nav et apparition du sous-menu actif
			$$(subnavElementsArray).each(function(subnav) {
				subnav.get('slide').cancel();
				subnav.slide('hide');
			});
			//alert (document.getElementById('nav2_1'));
			objSubnav = document.getElementById(item.getProperty("rel"));
//alert (objSubnav.innerHTML);
			$(objSubnav).slide('in');
			currentItem = item;
		});
	});
	$("nav1Wrapper").addEvent('mouseleave', function() {
		if ($(currentItem) !== $(activeID)) {
			$$(".nav1Home")[0].innerHTML = "<a href=\"core.php\"><img src=\"../medias/img/nav1_home_on.png\" width=\"17\" height=\"21\" style=\"margin-top:6px\" /></a>";
			var colorFx = new Fx.Tween (currentItem.getElement('a'), { 
				duration: 300
			});
			colorFx.start('color', '#9c866a');
			//$(item.getProperty("rel")).slide('out');

			// dissimulation de la sous-nav affichée
			$(currentItem.getProperty("rel")).get('slide').cancel();
			$(currentItem.getProperty("rel")).slide('out');
			$(currentItem.getProperty("rel")).set('styles', {'display': 'none'});

			currentTab();
		}
	});

	var currentTab = function() {
//alert ($(activeID));
		if (currentItem) {
			var colorFx = new Fx.Tween (currentItem.getElement('a'), { 
				duration: 300
			});
			colorFx.start('color', '#9c866a');
		}

		currentItem = $(activeID);
		if ($(activeID).hasClass("nav1Home")) {
			var tabWidth = 60;
			var thisPos = 0;
		} else {
			var tabWidth = $(activeID).getSize().x + 2;
			var thisPos = $(activeID).getPosition(navWrap).x + 5;
		}
		// Firefox
		if (Browser.Engine.gecko)
			thisPos += 318;

		youAreHere.cancel();
//		var activePos = $(activeID).getPosition(navWrap).x  + $(activeID).getSize().x - leftOffset; 
//		youAreHere.start('background-position', activePos + 'px ' + arrowY + 'px');
		youAreHere.start({'left': thisPos + 'px', 'width': tabWidth + 'px'});
		var colorFx = new Fx.Tween ($(activeID).getElement('a'), { 
			duration: 300
		});
		colorFx.start('color', '#FFFFFF');
		if ($(activeID).hasClass("nav1Home"))
			$$(".nav1Home")[0].innerHTML = "<a href=\"core.php?pag_id=" + $$(".nav1Home")[0].getProperty("rel") + "\"><img src=\"../medias/img/nav1_home_on.png\" width=\"17\" height=\"21\" style=\"margin-top:6px\" /></a>";
		else
			$$(".nav1Home")[0].innerHTML = "<a href=\"core.php?pag_id=" + $$(".nav1Home")[0].getProperty("rel") + "\"><img src=\"../medias/img/nav1_home_off.png\" width=\"17\" height=\"21\" style=\"margin-top:6px\" /></a>";

		// réinitialisation des positions des sous-nav
		$$(subnavElementsArray).each(function(subnav) {
			subnav.set('styles', {'position': 'static'});
		});
		if ($(currentItem.getProperty("rel"))) {
			var subnavWidth = $(currentItem.getProperty("rel")).getSize().x;
			var thisPos = currentItem.getPosition(navWrap).x + 10;
			if ((thisPos + subnavWidth) > $("nav1Wrapper").getSize().x)
				subnavPos = $("nav1Wrapper").getSize().x - subnavWidth;
			else
				subnavPos = thisPos;
			$(currentItem.getProperty("rel")).set('styles', {'display': 'inline', 'position': 'absolute', 'left': subnavPos + 'px'});
		}

		$$(subnavElementsArray).each(function(subnav) {
			$(subnav).get('slide').cancel();
			$(subnav).slide('out');
		});
		$($(activeID).getProperty("rel")).slide('in');
	};

	//correct IE rendering problem (without this, it wont go to the active nav onload)
//	var activePos = $(activeID).getPosition(navWrap).x  + $(activeID).getSize().x - leftOffset; 
//	$(navWrap).setStyle('background-position', activePos + 'px ' + arrowY + 'px');
	var bolInitNav = true;
	if (!$(activeID)) {
		bolInitNav = false;
	} else if ($(activeID).hasClass("nav1Home")) {
		var tabWidth = 60;
		var thisPos = 0;
	} else {
		var tabWidth = $(activeID).getSize().x - 20;
		var thisPos = $(activeID).getPosition(navWrap).x + 15;
	}
	// Firefox
	if (Browser.Engine.gecko)
		thisPos += 318;

	if (bolInitNav) {
		youAreHere.cancel();
		youAreHere.start({'left': thisPos + 'px', 'width': tabWidth + 'px'});
		var colorFx = new Fx.Tween ($(activeID).getElement('a'), { 
			duration: 300
		});
		colorFx.start('color', '#FFFFFF');
		if ($(activeID).hasClass("nav1Home"))
			$$(".nav1Home")[0].innerHTML = "<a href=\"core.php?pag_id=" + $$(".nav1Home")[0].getProperty("rel") + "\"><img src=\"../medias/img/nav1_home_on.png\" width=\"17\" height=\"21\" style=\"margin-top:6px\" /></a>";
		else
			$$(".nav1Home")[0].innerHTML = "<a href=\"core.php?pag_id=" + $$(".nav1Home")[0].getProperty("rel") + "\"><img src=\"../medias/img/nav1_home_off.png\" width=\"17\" height=\"21\" style=\"margin-top:6px\" /></a>";

		$$(subnavElementsArray).each(function(subnav) {
			$(subnav).get('slide').cancel();
			$(subnav).slide('out');
		});
///	$($(activeID).getProperty("rel")).set('styles', {'display': 'inline'});
//alert ($(activeID).getProperty("rel"));
		if (typeof ($(activeID).getProperty("rel")) != "undefined") {
///			$($(activeID).getProperty("rel")).set('styles', {'display': 'inline'});
			var subnavWidth = $($(activeID).getProperty("rel")).getSize().x;
			var thisPos = $(activeID).getPosition(navWrap).x + 10;
			if ((thisPos + subnavWidth) > $("nav1Wrapper").getSize().x)
				subnavPos = $("nav1Wrapper").getSize().x - subnavWidth;
			else
				subnavPos = thisPos;
			// Firefox
			if (Browser.Engine.gecko)
				subnavPos = subnavPos + 318;
			$($(activeID).getProperty("rel")).set('styles', {'position': 'absolute', 'left': subnavPos + 'px'});
			$($(activeID).getProperty("rel")).slide('in');
		}
	}
	currentItem = $(activeID);
	
	//works to set image to starting position in other browsers
//	currentTab(); 
	
//	$(navWrap).addEvent('mouseleave', currentTab);
}; 
	
window.addEvent('domready', function() {
	navArrowSlider(
		'nav1', // ID of nav wrap
		'#nav1 td', // Array selector of nav elements 
		'activeTab', // ID of current nav element
		'#nav2 div.nav2Wrap',
		'20px', //  Background position y of background image
		'20' //  INT ONLY - How far left from the right edge of the nav element that the image settles
	); 	
}); 

