function init()
{
	$('a[rel*=external]').live('click', function() { window.open(this.href); return false; });
	$('#prestigenav').hoverIntent({sensitivity: 1, interval: 0, over: showmainnav, timeout: 400, out: hidemainnav });
}

function fancyHome()
{
	$("a.welcome").fancybox({
		'overlayColor'	: '#000',
		'overlayOpacity': 0.9		
	});
}

function showmainnav()
{	
	$('#subnav').stop(true,true).slideDown('fast', 'easeOutExpo');		
}

function hidemainnav()
{	
	$('#subnav').stop(true,true).slideUp('fast', 'easeOutExpo');
}	

function equalize()
{
	if(!($.browser.msie && $.browser.version=="6.0"))
	{
		leftheight = $('.leftcol').height();
		rightheight = $('.rightcol').height();		
		if ( (rightheight) > leftheight)
		{
			$('.leftcol').height(rightheight);
		}
	}
}

function galleryFancy()
{
	$("a.fancyimg").fancybox({
		'overlayColor'	: '#000',
		'overlayOpacity': 0.9,
		'speedIn'		: 600, 
		'speedOut'		: 200,
		'changeSpeed'	: 100,
		'titleShow'		: false
	});
}

function initForm()
{
	$('#sendbtn').click( function()
	{
		// Form validation
		if ( $('#nom').val() == '' )
		{
			showError('X - Veuillez entrer votre nom');
			$('#nom').focus();
			return false;
		}
				
		if ( $('#prenom').val() == '' )
		{
			showError('X - Veuillez entrer votre prénom');
			$('#prenom').focus();
			return false;
		}
				
		if ( $('#telephone').val() == '' )
		{
			showError('X - Veuillez entrer votre numéro de téléphone');
			$('#telephone').focus();
			return false;
		}
		
		if ( $('#courriel').val() == '' )
		{
			showError('X - Veuillez entrer votre courriel');
			$('#courriel').focus();
			return false;
		}
		
		// SEND PROCESS
		$('#error').html('<img src="../images/35.gif" width="14" height="14" alt="" />');
		$('#error').show();

		qts1 = $('input[name=qts1]:checked').val(); if ( !qts1 ) qts1 = '';
		qts2 = $('input[name=qts2]:checked').val(); if ( !qts2 ) qts2 = '';
		qts2_txt = $('#autre').val();
		qts3 = $('input[name=qts3]:checked').val(); if ( !qts3 ) qts3 = '';
		nom = $('#nom').val();
		prenom = $('#prenom').val();
		telephone = $('#telephone').val();
		courriel = $('#courriel').val();
		message = $('#message').val();		
		
		
		$.post('sendmail.php',  { 
			qts1: qts1,
			qts2: qts2,
			qts2_txt: qts2_txt,
			qts3: qts3,
			nom : nom,
			prenom : prenom,
			telephone : telephone,
			courriel : courriel,
			message : message }, function(data, success)
		{
			if ( data == 'true')
			{
				$('#error').hide();
				$('#success').show();
				$('.btn').hide();
			}
			else
			{
				showError('Désolé, une erreur s\'est produite.<br />Recommencez ou écrivez-nous à l\'adresse <a href="mailto:info@rodimax.com" title="info@rodimax.com">info@rodimax.com</a>');
			}
		})
		.error(function()
		{
			showError('Désolé, une erreur s\'est produite.<br />Recommencez ou écrivez-nous à l\'adresse <a href="mailto:info@rodimax.com" title="info@rodimax.com">info@rodimax.com</a>');
		})		
		
		return false;
	});
}

function initFormEn()
{
	$('#sendbtn').click( function()
	{
		// Form validation
		if ( $('#nom').val() == '' )
		{
			showError('X - Please, enter your last name');
			$('#nom').focus();
			return false;
		}
				
		if ( $('#prenom').val() == '' )
		{
			showError('X - Please, enter your first name');
			$('#prenom').focus();
			return false;
		}
				
		if ( $('#telephone').val() == '' )
		{
			showError('X - Please, enter your phone number');
			$('#telephone').focus();
			return false;
		}
		
		if ( $('#courriel').val() == '' )
		{
			showError('X - Please, enter your email');
			$('#courriel').focus();
			return false;
		}
		
		// SEND PROCESS
		$('#error').html('<img src="../images/35.gif" width="14" height="14" alt="" />');
		$('#error').show();

		qts1 = $('input[name=qts1]:checked').val(); if ( !qts1 ) qts1 = '';
		qts2 = $('input[name=qts2]:checked').val(); if ( !qts2 ) qts2 = '';
		qts2_txt = $('#autre').val();
		qts3 = $('input[name=qts3]:checked').val(); if ( !qts3 ) qts3 = '';
		nom = $('#nom').val();
		prenom = $('#prenom').val();
		telephone = $('#telephone').val();
		courriel = $('#courriel').val();
		message = $('#message').val();		
		
		
		$.post('sendmail.php',  { 
			qts1: qts1,
			qts2: qts2,
			qts2_txt: qts2_txt,
			qts3: qts3,
			nom : nom,
			prenom : prenom,
			telephone : telephone,
			courriel : courriel,
			message : message }, function(data, success)
		{
			if ( data == 'true')
			{
				$('#error').hide();
				$('#success').show();
				$('.btn').hide();
			}
			else
			{			
				showError('Sorry, an error occurred.<br />Repeat or write to us at <a href="mailto:info@rodimax.com" title="info@rodimax.com">info@rodimax.com</a>');
			}
		})
		.error(function()
		{
			showError('Sorry, an error occurred.<br />Repeat or write to us at <a href="mailto:info@rodimax.com" title="info@rodimax.com">info@rodimax.com</a>');
		})		
		
		return false;
	});
}

function showError(str)
{
	$('#error').html(str);
	$('#error').show();
}
