/*******************************************************************************
 *******************************************************************************   
 *	+ MAIN INFO   
 *
 *	@filename		: utils.js
 *	@description	: librairie de fonctions  utilitaires générales
 *	@authors		: Daniel Vaillancourt <dvaillancourt@os.ca>,
 *					  Sébastien Tremblay  <stremblay@os.ca>
 *	@date			: 30/10/2009
 *
 ******************************************************************************/  

/**
 * jumpToAnchor -- Fonction qui permet de naviguer avec les "anchors" via JS.
 * @param {string} targetAnchor 	-> Anchor à atteindre
 */
function jumpToAnchor(targetAnchor) {
   window.location = String(window.location).replace(/\#.*$/, "") + "#" +targetAnchor;
}

/**
* nl2br -> semblable à php's nl2br
* 
*/
function nl2br(str) { return str.replace(/\n/g, '<br />'); }

/**
* fcm -> commentaire formatté pour la console
*
*/

function fcm(str){ return console.debug("-----------------------------------------------------------------------------------\n- "+str+"\n- \n. \n"); }


window.addEvent('domready',function() {
	/* settings */
	var showDuration = 4000;
	var container = $('slideshow-container');
	var images = container.getElements('img');
	var currentIndex = 0;
	var interval;
	/* opacity and fade */
	images.each(function(img,i){ 
		if(i > 0) {
			img.set('opacity',0);
		}
	});
	
	/* worker */
	var show = function() {
		images[currentIndex].fade('out');
		images[currentIndex = currentIndex < images.length - 1 ? currentIndex+1 : 0].fade('in');
	};
	/* start once the page is finished loading */
	window.addEvent('load',function(){
		interval = show.periodical(showDuration);
	});
});

var timeout         = 500;
var closetimer		= 0;
var ddmenuitem      = 0;

function jsddm_open()
{	jsddm_canceltimer();
	jsddm_close();
	ddmenuitem = $(this).find('ul').eq(0).css('visibility', 'visible');}

function jsddm_close()
{	if(ddmenuitem) ddmenuitem.css('visibility', 'hidden');}

function jsddm_timer()
{	closetimer = window.setTimeout(jsddm_close, timeout);}

function jsddm_canceltimer()
{	if(closetimer)
	{	window.clearTimeout(closetimer);
		closetimer = null;}}

$(document).ready(function()
{	$('#jsddm > li').bind('mouseover', jsddm_open);
	$('#jsddm > li').bind('mouseout',  jsddm_timer);});

document.onclick = jsddm_close;