var $j = jQuery.noConflict();

$j(document).ready(function()
{
	$j(".submit").click(function()
	{
		$j(this).parents("form").submit();

		return false;
	});
	
	$j('form input[type=text]').click(function()
	{
	  if((this.value) == 'Entrer votre courriel' || (this.value) == 'Enter your email')
		this.value = '';
	});

	$j("#nav li").hover(
		function(){ $j("ul", this).fadeIn("fast"); }, 
		function(){ $j("ul", this).fadeOut("fast") } 
	);
	
	// Get the last tweet from user
	var username = 'groovyyurts';
	var format	 = 'json';
	var total	 = 5;
	
	var url='http://api.twitter.com/1/statuses/user_timeline/' + username + '.' + format + '?callback=?&count=' + total;

	$j.getJSON(url, function(tweet)
	{
		for(var i = 0; i < 3; i++)
		{
			$j("#twitter_timeline ul li:nth-child("+(i+1)+") p").html(replaceURLWithHTMLLinks(tweet[i].text));
		}
	});
	
	$j('a.colorbox').colorbox({ scalePhotos: true, maxWidth: 1000, maxHeight: 700 });

	$j('.wpsc_categories li:nth-child(2n)').addClass('even');
});

function replaceURLWithHTMLLinks(text)
{
	var exp = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig;
	
	return text.replace(exp,"<a href='$1'>$1</a>"); 
}
