$(function()
{
/* Misc --------------------------------------------------------------------- */
	
	// Run sammy first on the homepage
	app.run('#!/accueil');
	
	$('#top').css('opacity', 0.96);

	$('#top #logo').hover(function()
	{
		$('#logo_home').stop().fadeTo(250, 1);
	}, function()
	{
		$('#logo_home').fadeTo(250, 0);
	});

	// Insert email by JS to try prevent spam
	$('.email_js').attr('href','mailto:info@lubie.co');
	$('.email_js').html('info@lubie.co');

/* Main navigation ---------------------------------------------------------- */

	// Lavalamp menu
	// nb: top and left are set to 0.1 since it can't be 0 according hot the plugin works
	$('#top nav ul').lavaLamp({homeTop:0.1, homeLeft:0.1, homeHeight:38, homeWidth:5, returnHome: true});

	$('#logo a').click(function()
	{
		$('#top nav ul li').removeClass('current');
	});

/* Login section ------------------------------------------------------------ */
	
	$('#private_login label').inFieldLabels();

	$('#login_link a').click(function()
	{
		$('#private_login > div:first').fadeOut('normal',function()
		{
			$('#private_login > div:last div:eq(0)').fadeIn('normal', function()
			{
				$('#private_login > div:last div:eq(1)').fadeIn('normal', function()
				{
					$('#private_login > div:last div:eq(2)').fadeIn('normal');	
				});
			});
		});

		return false;
	});

/* Footer ------------------------------------------------------------------- */	

	$('#bottom .box_02 nav a').hover(function()
	{
		$(this).stop().animate({paddingLeft: '25px'}, {duration: 300});
	}, function()
	{
		$(this).stop().animate({paddingLeft: '20px'}, {duration: 300});
	});

});


/* Functions misc ----------------------------------------------------------- */	

function explode(delimiter, string, limit)
{
	var emptyArray =
	{
		0: ''
	};
 
	// third argument is not required
	if (arguments.length < 2 || typeof arguments[0] == 'undefined' || typeof arguments[1] == 'undefined')
	{
		return null;
	}
 
	if (delimiter === '' || delimiter === false || delimiter === null)
	{
		return false;
	}

	if (typeof delimiter == 'function' || typeof delimiter == 'object' || typeof string == 'function' || typeof string == 'object')
	{
		return emptyArray;
	}
 
	if (delimiter === true)
	{
		delimiter = '1';
	}
 
	if (!limit)
	{
		return string.toString().split(delimiter.toString());
	}

	// support for limit argument
	var splitted = string.toString().split(delimiter.toString());
	var partA = splitted.splice(0, limit - 1);
	var partB = splitted.join(delimiter.toString());
	partA.push(partB);
	return partA;
}

