// JavaScript Document

// identification -- begin
//
//   Script: ui-accueil.js
//
//   Auteur: Benoit Dubuc - benoit.dubuc@espacecourbe.com
//   Site Web: http://www.espacecourbe.com/
//   Création: <2010-05-16 13:44:00 benoit>
//
//   Fonction: Permet d'ajouter les fonctionnalités de gestion de l'interface
//             usager de la page d'accueil (ouverture du menu, image aléatoire, injection du menu)

//   Dépendancse: Utilise la librairie jquery v1.3.2, easing, jquery.randomimage.js
//
//   Hypothèses: aucune
//	
//
//	Modifications: aucune
// 
//
// identification - end

jQuery = Versions.use('jquery','1.3.2');

jQuery(function($){


//pause avant animation
$.fn.pause = function(duration) {
	$(this).stop().animate({ dummy: 1 }, duration);
	return this;
};

function mouseleft() {
	$("#menu-horizontal").triggerHandler("mouseleave");
}


function fillMenuPrincipal() {
	// fonction pour l'injection des items de 2e niveau du menu principal
	var menuprinarr = $('#menu-principal ul li');
	menuprinarr.each(function(index,element){
		var id = $(this).attr('id').replace(/menu-p-/,'');
		if (id) {
			//console.log(id);
			var sourceUl = $('#'+id);
			var ul = document.createElement('ul');
			$('ul li a',sourceUl).each(function(i,e){
				var li = document.createElement('li');
				$(li).append($(e).clone());
				ul.appendChild(li);
			});
			element.appendChild(ul);
		}
	});
}

$(document).ready(function(){
	
	// ouvrir/fermer la navigation quand on passe dessus
	var selectedInput = null;
	$("#um-boite-recherche").focus(function() {
		selectedInput = this;
	});
	$("#um-boite-recherche").blur(function() {
		selectedInput = null;
	});
	$("#um-enveloppe-entete-menu-horizontal").mouseenter(
		function () {

			$(this).stop().pause(60).animate({ height:"250px" }, 400, "easeInQuad" );
		}).mouseleave(
		function () {

				$(this).stop().pause(60).animate({ height:"33px" }, 400, "easeOutQuad" );
	
		}
	);
	
	// objet pour image aléatoire
	var randomImgObj = {
		//'array':  ['image01.jpg', 'image02.jpg', 'image03.jpg', 'image04.jpg', 'image05.jpg', 'image06.jpg'],
		'dir': 'images/contenu/aleatoire/',
		'width': 966,
		'height': 300
	}	
	$(document).preloadRandomImages(randomImgObj);
	$(document).ready(function() {
		$('#imagealeatoire').displayRandomImage(randomImgObj);
	});
	
	// aller injecter les sous items du menu principal
	fillMenuPrincipal();
	
	
});


});
