/***********************/
/******* CONFIG ********/
/***********************/

var max_elt_col = 7;

/***********************/

// Scripts communs aux pages
$(document).ready(function()
{	
	/////////////////
	// ZONES TEXTE //
	/////////////////
	$('.input_text').click(function(event){ this.value=''; });
	
	
	////////////////////
	// MENU DEROULANT //
	////////////////////
	jQuery('ul.main_menu').superfish();
	
	$('ul.main_menu ul.ul01').each(function(){
		var $$ = $(this);
		var li01 = $$.find('.li01');
		var li01_len = li01.length;
		
		if(li01_len > max_elt_col)
		{
			var first_elt_second_col = parseInt(li01_len/2);
			if(li01_len % 2 == 1) first_elt_second_col++;
			
			var sec_col = $$.next('.sec_col');
			for(i = first_elt_second_col; i <  li01_len; i++)
			{
				sec_col.append(li01.eq(i));
			}
		}
	});
	
	$('ul.main_menu ul ul').each(function(){
		var $$ = $(this);
		var li02 = $$.find('li');
		var li02_len = li02.length;
		
		if(li02_len > max_elt_col)
		{
			var first_elt_second_col = parseInt(li02_len/2);
			if(li02_len % 2 == 1) first_elt_second_col++;
			
			var sec_col = $$.next('.sec_col');
			for(i = first_elt_second_col; i <  li02_len; i++)
			{
				sec_col.append(li02.eq(i));
			}
		}
	});
});

function diapoMultiDim()
{
	/////////////////////
	// DIAPO MULTI DIM //
	/////////////////////
	var options = {
		type : 'multi-dim',
		widthMove : 488,
		heightMove : 485,
		maxAbcissElements : 5,
		duration : 700
	}
	var multi_dim = new FreeWalkDiaporama('block-fiches-produits', options);
	multi_dim.initialize();
}

function diapoFicheProduit()
{
	/////////////////////////
	// DIAPO FICHE PRODUIT //
	/////////////////////////
	var photos_produits = $('#diapo-single-main a');
	var thumb_produit = $('#diapo-single-thumbnails a').not('.video');
	
	thumb_produit.each(function(i){ 
		$(this).bind('mouseover', function(){ 
			photos_produits.each(function(){ $(this).removeClass('default'); }); 
			photos_produits.eq(i).addClass('default'); 
		});
	});
}

function diapoBottom()
{	
	//////////////////
	// DIAPO BOTTOM //
	//////////////////
	var options = {
		type : 'diapo-h',
		widthMove : 958,
		duration : 700,
		delay : 4000,
		auto_play : true,
		loop : true
	}
	var diapo_bott = new FreeWalkDiaporama('diapo_bottom', options);
	diapo_bott.initialize();
}

function diapoNews()
{
	////////////////
	// DIAPO NEWS //
	////////////////
	var options = {
		type : 'diapo-v',
		heightMove : 285,
		duration : 1400,
		delay : 5000,
		auto_play : true,
		loop : true
	}
	var diapo_news = new FreeWalkDiaporama('diapo-news', options);
	diapo_news.initialize();
}

/* Fonction qui retourne la position d'un objet dans la page quel que soit son parent */
function GetDomOffset( Obj, Prop )
{
	var iVal = 0;
	while (Obj && Obj.tagName != 'BODY')
	{
		eval('iVal += Obj.' + Prop + ';');
		Obj = Obj.offsetParent;
	}
	return iVal;
}

function getEl(id) { return document.getElementById(id)}

// Fonction d'association de gestionnnaire
// function addListener(element, baseName, handler)
// {
	// if (element.addEventListener)
		// element.addEventListener(baseName, handler, false);
	// else if (element.attachEvent)
		// element.attachEvent("on"+baseName,handler);
// }
//addListener('body', 'load', runAfterContentLoad);
