
var urlRegEx = new RegExp(/([^\/]+)\/([0-9]+)\/([^\/]+)\.html(.*)?/);
	
/**
 * Parse an href an load page by ajax
 */
function loadPage( url )
{
	var container = $('#dynamic-content');
	container.fadeOut(200, function()
	{
		var path = url.replace(URL_BASE, '');
		path = path.split('?')[0];
		path = path.split('#')[0];
		if( path == "" )
			path = "fr/1/index.html";
		var res = path.match(urlRegEx);
		$.ajax({
			url: URL_BASE + 'dyn-content.php?id='+res[2],
			success: function(data)
			{
				container
					.html(data)
					.fadeIn();
				closeMenu();
				$("#list-items")
					.scrollable({ mousewheel: true })
					.navigator({
						history: true,
						indexed: true,
						navi: '#list-items-nav'
					}
				);
				$('.list-item').tooltip({ position: 'top left', offset: [40,-10], effect: 'slide'});
				initActus();
			}
		});
	});
}

/** 
 * UI Actus
 */
function initActus()
{
	$(".actu-head").click(function(e)
	{
		$(this)
			.css('background-image', "url("+URL_BASE+"images/close-btn.png)")
			.next("div.actu-body")
			.slideToggle("fast", function()
			{
				$(this)
				.siblings("div.actu-body")
				.slideUp("fast");
			})
	   	$(this)
	   		.siblings('.actu-head')
	   		.css('background-image', "url("+URL_BASE+"images/plus-btn.png)");
	});
}


/**
 * Open the main menu
 */
function openMenu()
{
	menu.css({width:680})
	menuContainer.animate({width:750}, 'fast');
	menu.show(400);
	//menuTitle.hide();
	menuIsOpen = true;
}

/**
 * Close the main menu
 */
function closeMenu()
{
	menu.css({width:'auto'});
	menuContainer.animate({width:w}, 100, null, function(){ menuIsOpen = false });
	menu.hide();
}



/* mousetrack.js */
var yTop; // distance wrapslide is from the top of the page


jQuery.easing.def = "easeInOutQuart"; // apply easeInOutQuart easing

function mouseFollow(e, id) { // mouseFollow() is called whenever the mouse enters a nav slider, id assigned to be slidePrev or slideNext
	var mouseYPos = e.pageY - yTop; // y-coord of mouse relative to wrapslide
	
	var heightBox = $(id).height(); // find height of clickable a tag
	var slideHeight = $(id).parent().height(); // height of slidePrev or slideNext, the length of the whole slide-able area
	if (mouseYPos > 0 && mouseYPos < slideHeight ) { //ensure clickable a tag does not slide off #slidePrev or #slideNext

		var boxYPos; // this will track where the top of the a tag should be
		if (mouseYPos < (heightBox / 2)) { // prevents a tag from sliding above #slidePrev when the mouse is near the top of the div
			boxYPos = heightBox / 2;	 // force a tag to stay within div
		}
		else if (mouseYPos > slideHeight - (heightBox / 2)) { // prevents a tag from sliding below div when the mouse is near the bottom of the div
			boxYPos = slideHeight - (heightBox / 2); // force a tag to stay within div
		}
		else { boxYPos = mouseYPos; } // allow a tag to follow mouse if the mouse is in the middle of the div
	
		$(id).stop(true, true); // stops the mouseEnd() animation, so the a tag follows the mouse without delay.
		//$(id).css('top', boxYPos - (heightBox / 2)); // - (heightBox/2) puts the mouse pointer in the center of the a tag.
		$(id).css('top', e.pageY - 180); // - (heightBox/2) puts the mouse pointer in the center of the a tag.
	}
}

function mouseEnd(id) { // mouseEnd is called when the mouse leaves the nav slider
	var slideHeight = $(id).parent().height();
	var heightBox = $(id).height();
	//$(id).animate({top: (slideHeight/2) - (heightBox/2)}, 500); // a tag will ease back to the center of the div when the mouse leaves the div area
	$(id).animate({top: 0});
}



