/*
 *	@titre: contact.
 *	@description: javascript contact - dream on.
 *	@auteur: neov - http://www.neov.net.
 *	@creation: 20091109.
 *	@modification: -
 *	@required: jQuery 1.3.2
 *
 */

var textContact = new Array();
textContact['fr_FR'] = ['Annuler', 'Votre message'];
textContact['en_EN'] = ['Cancel','Your message'];
textContact['es_ES'] = ['Cancel','Your message'];
textContact['de_DE'] = ['Cancel','Your message'];

var timeout = null;

$.fn.setMap = function()
{
	var map, geocoder, center, marker;
	
	geocoder = new google.maps.Geocoder();
	
	var options = {
		zoom: 15,
		navigationControl: true,
		navigationControlOptions: {
			style: google.maps.NavigationControlStyle.DEFAULT
		},
    	scaleControl: true,
		mapTypeId: google.maps.MapTypeId.ROADMAP
	};
	
	map = new google.maps.Map(document.getElementById("map"), options);
	
	if (geocoder) {
		geocoder.geocode(
			{'address': 'Dream On 21 rue Vauvenargues 75018 Paris'},
			function(results, status)
			{
				
				if (status == google.maps.GeocoderStatus.OK)
				{
					center = results[0].geometry.location;
					map.setCenter(results[0].geometry.location);
					marker = new google.maps.Marker(
						{
							map: map,
							position: results[0].geometry.location,
							title: 'Dream On'
						}
					);
				} else {
					alert("Geocode was not successful for the following reason: " + status);
				}
			}
		);
	}
}
	



$(
	function()
	{
		// initialisation.
		$('.contact-bottom form').addClass('inactive');
		$('.contact-bottom form .file').hide();
		
		var oldText = null, initFormText = null, tHeight = 0, dHeight = 0;
		
		// choix mouseover
		function doOver()
		{
			$('.choix').not(this).stop().animate({opacity: 0.44}, {queue: true, duration: $.browser.msie?10:gtime, easein: 'linear'});
				
			$(this).addClass('current');
		}
		
		// choix mouseout
		function doOut()
		{
			/*
			if($.browser.msie)
				$('.choix').not(this).removeClass('nselect');
			else
			*/
				$('.choix').not(this).stop().animate({opacity: 1}, {queue: true, duration: $.browser.msie?0:gtime, easein: 'linear'});
				
			$(this).removeClass('current');
		}
		
		// choix select

		function doSelect()
		{	
			
			if ($('a', this).hasClass('active'))
			{
				$('a', this).removeClass('active');
				$('a strong', this).text(oldText);
				
				$('.contact-bottom form .titre').text(initFormText);
				$('.contact-bottom form').find(':input').attr({disabled: 'disabled'});
				$('.contact-bottom form input[type=text]').val('').focus().blur();
				$('.contact-bottom form textarea').val('').focus().blur();;
				$('.contact-bottom form').addClass('inactive');
				
				$('.contact-bottom form *').removeClass('error');
				
				$('.choix').bind('mouseover', doOver);
				$('.choix').bind('mouseout', doOut);
				
				$('.contact-bottom .brwse input').val('').focus().blur().hide();
				
				// enlever les classes erreur
				$('.contact-bottom form *').removeClass('error');
					
				// affectation du type contact
				$('#iTypeContact').val(0);	
					
			} else {
				if ($(this).hasClass('current'))
				{
					$('.choix').unbind('mouseover');
					$('.choix').unbind('mouseout');
					
					$('.contact-bottom form').removeClass('inactive');
					
					oldText = 	$('a strong', this).text();
					
					$('a', this).addClass('active');
					$('a strong', this).text(textContact[lang][0]);
					
					initFormText = $('.contact-bottom form .titre').text();
					$('.contact-bottom form .titre').text(textContact[lang][1]);
					
					$('.contact-bottom form *').removeAttr('disabled');
					
					// enlever les classes erreur
					$('.contact-bottom form *').removeClass('error');
					
					// affectation du type contact
					$('#iTypeContact').val($(this).attr('id'));
				} else {
					$('.current a strong').text(oldText)
					$('.current a').removeClass('active');
					
					$('.choix').not(this).removeClass('current');
					$('.choix').not(this).stop().animate({opacity: 0.4}, {queue: true, duration: gtime, easing: 'sineEaseOut'});
					
					
					$(this).stop().animate({opacity: 1}, {queue: true, duration: gtime, easing: 'sineEaseOut'});
					$(this).addClass('current');
					
					oldText = $('a strong', this).text();
					$('a', this).addClass('active');
					$('a strong', this).text(textContact[lang][0]);	
					
					// enlever les classes erreur
					$('.contact-bottom form *').removeClass('error');
					
					// affectation du type contact
					$('#iTypeContact').val(0);				
					
				}
				
				
			}					
			return false;
		}
		
		// contact choix.
		$('.choix').each(
			function(cIndex)
			{
				
				tHeight = (tHeight > $(this).find('.titre').height())? tHeight : $(this).find('.titre').height();
				dHeight = (dHeight > $(this).find('.desc').height())? dHeight : $(this).find('.desc').height();
				
				$(this)
					.bind('mouseover', doOver)
					.bind('mouseout', doOut)
					.bind('click', doSelect);
			}
		);
		
		$('.contact-bottom .joindre').click(
			function()
			{
				$('.contact-bottom .brwse input').toggle();
				return false;
			}
		);
		
		$('.choix .titre').height(tHeight);
		$('.choix .desc').height(dHeight);
		
		if ($('.contact-bottom .form .titre').height() > $('.contact-bottom .map .titre').height())
			$('.contact-bottom .map .titre').height($('.contact-bottom .form .titre').height());
		
		$('.choix .lwrapper').height($('.choix').height());
		
		// google map.
		$().setMap();
		
		// formulaire contact
		$('#formulaireContact').submit(
			function()
			{
			
				//tmt_validatorInit(true)
				if (!tmt_validateForm(this)) {
					return false;	
				} 
				
				$('#formulaireContact').hide();
				$('.message-conf').show();
				
				var options = {
					url :		j_basepath + 'ajax.php?module=contactFo&action=default:validerContact',
					type:		'POST',
					dataType :	'json',
					clearForm:	true,
					resetForm: true,
					success:	function(result){
									$('#mess-nom').val(result.msgnom);
									$('#mess-prenom').val(result.msgprenom);
									$('#mess-mail').val(result.msgmail);
									$('#mess-telephone').val(result.msgtelephone);
									$('#mess-message').val('');
									
									if (timeout) clearTimeout(timeout);
									timeout = setTimeout(function(){
										$('.message-conf').hide();										
										$('#formulaireContact').show();											
										$('.current').trigger('click');
										}, 5000);
										$('.choix').removeClass('current');
								}
				};
				
				$(this).ajaxSubmit(options);
				
				return false;
			}
		);
		
		
		// active par defaut un onglet
		// utiliser pour la page "offre d'emploi"
		if (iTypeContact) {
			$('#'+iTypeContact+'.choix').trigger('mouseover').trigger('click');
		}
	}
);

// display error.
function displayError(frm, invalidFields)
{
	return true;
}
