/**Verification du formulaire**/
function verifForm(){
	var mess = " est obligatoire";
	var myform = new Form('document.contact');
	myform.addField('nom', "Le nom"+ mess, 'text');
	myform.addField('prenom', "Le prénom "+ mess, 'text');
	myform.addField('email', "L'email "+ mess, 'text');
	myform.addField('email', "L'email est invalide", 'email');
	myform.addField('message', "Le message "+mess, 'text');
	initField($('nom'));
	initField($('prenom'));
	initField($('email'));
	initField($('message'));
	
	if(!myform.verifForm(false)) {
		field = myform.fieldobject;
		if(field){
			new Fx.Style(field, 'background-color', {duration:500}).start('#FFFFFF','#FBC059');
			var vObjEror = $('error');
			$('error').setHTML(myform.message);
			field.addEvent('mouseover', function(){
				var vCoordinates = this.getCoordinates();
				vObjEror.setStyle('top', vCoordinates.top+5);
				vObjEror.setStyle('left', vCoordinates.left+vCoordinates.width+5);
				vObjEror.setStyle('opacity', 0);
				vObjEror.setStyle('display', 'block');
				new Fx.Style(vObjEror, 'opacity', {duration:300}).start(0,1);
			});
			field.addEvent('mouseout', function(){
				vObjEror.setStyle('display', 'none');
			});
		}
		return false;
	}
	return myform.verifForm();
}

/** Affichage du module **/
function showBox(pName){
	$('video').setStyle('visibility', 'visible');
	
	$('contact').reset();
	$('envoyer').setStyle('opacity', 1);
	vObjOverlay = $('div_overlay');
	if(vObjOverlay){
		vHeight = window.getScrollHeight()+'px';
		vObjOverlay.setStyle('width', '100%')
		vObjOverlay.setStyle('height', vHeight);
		vObjOverlay.setStyle('visibility', 'visible');
		vObjOverlay.setStyle('opacity', 0);
		new Fx.Style(vObjOverlay, 'opacity', {duration:500}).start(0,0.8);
	}
	
	/**Initialisation**/
	$('nom').focus();
	//$('end').setStyle('display','none');
	//$('fields').setStyle('display','block');
	vHeight = window.getHeight();
	vWidth = window.getScrollWidth();
	var target = $(pName);
	var vCoordinates = target.getCoordinates();
	vWidth =  (vWidth-vCoordinates.width)/2;
	vHeight = (vHeight-vCoordinates.height)/2;
	vHeight+=window.getScrollTop();
	var fx = new Fx.Styles(target, {duration: 1000, wait: false,
		onComplete: function(){
			if(pName=="div_showreel"){
				vShowreel = (window.ie) ? window['showreel'] : document['showreel'];
				vShowreel.playVideo();
			}
		}
	});
	fx.options.transition = Fx.Transitions.linear;
	fx.start({
		'top': [vHeight+10],
		'left': [vWidth]
		
	});
}

/**Masque le module **/
function hideBox(pName){
	if(pName=="div_showreel"){
		vShowreel = (window.ie) ? window['showreel'] : document['showreel'];
		vShowreel.pauseVideo();
		$('video').setStyle('visibility', 'hidden');
	}
	
	vObjOverlay = $('div_overlay');
	if(vObjOverlay){
		//EFFETS
		new Fx.Style(vObjOverlay, 'opacity', {duration:500}).start(0.8,0);
	}

	var target = $(pName);
	var fx = new Fx.Styles(target, {duration: 1000, wait: false});
	fx.options.transition = Fx.Transitions.linear;
	fx.start({
		'top': [-1000],
		'left': [0]
	});
}

/**Initialisation du drag/drop**/
function initDragDrop(){
	new Drag.Move('div_contact', {'container': null, 'droppables': null});
	new Drag.Move('div_crew', {'container': null, 'droppables': null});
	//new Drag.Move('div_showreel', {'container': null, 'droppables': null});
}

/**Envoi du mail**/
function sendContact(){
	vObj = $('contact');
	$('contact').fireEvent('submit', '');
}

/**Focus sur le champ**/
function onFocus(e){
	if(e.target) e.target.focus();
}

/**Init sur le champ**/
function initField(field){
	field.setStyle('background-color', '#FFFFFF');
	field.removeEvents('mouseover');
	field.removeEvents('mouseout');
}

/**Initialisation**/
window.addEvent('load', function() {
	
	vFlash = AC_FL_RunContent( 'codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0','width','875','height','645','id','index','align','middle','src','htmlmonami','quality','high','bgcolor','#ffffff','name','index','allowscriptaccess','sameDomain','allowfullscreen','false','pluginspage','http://www.macromedia.com/go/getflashplayer','movie','htmlmonami', 'wmode', 'transparent');
	$('div_flash').setHTML(vFlash);
	
	vFlashVideo = AC_FL_RunContent( 'codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0','width','675','height','450','id','showreel','align','middle','src','flash/showreel','quality','high','bgcolor','#ffffff','name','showreel','allowscriptaccess','sameDomain','allowfullscreen','true','pluginspage','http://www.macromedia.com/go/getflashplayer','movie','flash/showreel', 'wmode', 'transparent', 'swLiveConnect', 'true');
	$('video').setHTML(vFlashVideo);
	
	initDragDrop();
	$('nom').addEvent('click', onFocus);
	$('prenom').addEvent('click', onFocus);
	$('email').addEvent('click', onFocus);
	$('tel').addEvent('click', onFocus);
	$('message').addEvent('click', onFocus);
	
	$('contact').addEvent('submit', function(e) {
		/**Fin envoi du mail**/
		//$('fields').setStyle('display','none');
		//$('loading').addClass('loading');
		vObj = $('loading');
		vObj.setStyle('opacity', 0);
		vObj.setStyle('display', 'block');
		new Fx.Style(vObj.id, 'opacity', {duration:300}).start(0,1); 
		new Fx.Style($('envoyer'), 'opacity', {duration:500}).start(0.8,0);
		this.send({
			onComplete: function() {
				//$('loading').removeClass('loading');
				$('loading').setStyle('display', 'none');
				alert('Votre message a bien été envoyé');
				hideBox('div_contact');
			}
		});
	});
});

