
function init() {
	initToggleLink();
	initInputField();
	initHelpLinkFtpAccess();
	initFormulaire();
}

function initToggleLink() {
	$$( 'a.toggle_link' ).each( function( elt ) {
		
		$(elt.id+"_content").hide();
		
		Element.observe( elt, "click", switchLink );
	})
}

function switchLink( event ) {
	event.stop();
	var contentId = this.id+"_content";
	Effect.toggle( contentId, 'blind', { duration: 0.5 });
	//$( contentId ).toggle();
	
	resizeBlocLeft.delay( 0.6 );
}

function initInputField() {
	$$( 'input[type=text]' ).each( function( elt ) {
		Element.observe( elt, "focus", function() {
			if( this.value == this.alt ) {
				this.value = '';
			}
			
		})
		Element.observe( elt, "blur", function() {
			if( this.value == '' ) {
				this.value = this.alt;
			}
			
		})
	})
}

function initBookPageLink() {
	if( $$( '.bloc_book_object' ) ) {
		if( $( 'movie' ).value == '' || $( 'source' ).src == '' ) {
			var firstVidz = $( 'first_video_to_load' ).readAttribute( 'alt' );
			console.log( firstVidz );
			$( 'movie' ).value = firstVidz;
			$( 'source' ).src = firstVidz;
		}
		
		$$( '.bloc_book_object a' ).each( function( elt ) {
			Element.observe( elt , "click", displayVideo );
		})
	}
	
}

function displayVideo( event ) {
	/*Event.stop( event );
	var newVidz = Event.findElement( event, 'a' ).readAttribute( 'alt' );
	console.log( newVidz );
	$( 'movie' ).value = newVidz;
	$( 'source' ).src = newVidz;
	$( 'bloc_video' ).hide();
	$( 'bloc_video' ).show();
	Effect.ScrollTo( 'bloc_video', {duration : 1} );*/
	//return false;
}

function initblocLeft() {
	resizeBlocLeft();
}

function resizeBlocLeft() {
	if( $( 'left_menu_metiers' ) ) {
		var heightMax = $( 'content' ).getHeight() + 20;
		console.log( heightMax );
		if( heightMax > $( 'left_menu_metiers' ).getHeight() ) {
			$( 'left_menu_metiers' ).setStyle( { height : heightMax+'px' } );
		}
	}
}

function initHelpLinkFtpAccess() {
	if( $('aide_ftp_access') ) {
		Event.observe( $('aide_ftp_access'), "click", function(event) {
			event.stop();
			var file_dir = event.findElement( 'a' ).href;
			window.open( file_dir,'Aide | AttrapTemps', 'width=650,height=650,screenX=300,screenY=100,menubar=no,status=no,location=no' )
		});
	}
		
}

function initFormulaire() {
	if( $$('.formulaire') ) {
		$$('.formulaire').each( function( elt ) {
			elt.observe( "submit", function( event ) {
				var retour = '';
				$$('.formulaire .req').each( function( elt ) {
					if( elt.getValue() == ' ' || elt.getValue() == elt.alt ) {
						retour += '\t'+elt.alt+'\n';
						elt.setStyle( 'color:#FF0000');
					} else {
						elt.setStyle( 'color:#666');
					}
				});
				if( retour != '' ) {
					event.stop();
					alert('Ces champs sont obligatoires :\n'+retour);
				}
			})
		});
	}
}


document.observe("dom:loaded", init );