

var	optionsSite		= { urlBase	: 'http://www.maileva.com/' };
//var	optionsSite		= { urlBase	: 'http://www.maileva.com/' };
var	currentMenu		= null;
var	currentLink		= null;
var	anime			= false;

/**
 * Comment
 */

function toggleMenu(name, elLink) {

	var	tmp	= currentMenu;

	elLink	= $(elLink);
	
	if(currentMenu != null && currentMenu != name) {
		currentLink.removeClassName('current');
		$(currentMenu).hide();
		currentMenu = null;
	}

	if(name != tmp) {
		elLink.addClassName('current');
		$(name).show().setOpacity(1);
		currentMenu = name;
		currentLink = elLink;
	}
}


var	currentPopup	= null;

function	showPopup(name) {
	
	if(currentPopup) {
		var	el	= $(currentPopup);
		new Effect.Opacity(currentPopup, {duration: 0.3, from: 1, to: 0, afterFinish: function() { el.hide(); }, queue: { position: 'front', scope: 'popup' }});
	}

	new Effect.Opacity(name, {duration: 0.3, from: 0, to: 1, beforeUpdate: function() { $(name).show(); }, queue: { position: 'end', scope: 'popup' }});
	
	currentPopup	= name;
}

function	hidePopup() {
	if(currentPopup) {
		var	el	= $(currentPopup);
		new Effect.Opacity(currentPopup, {duration: 0.3, to: 0, afterFinish: function() { el.hide(); currentPopup = null;}, queue: { position: 'front', scope: 'popup' }});
	}
	
}

function	showPopupLayer(name) {

	if(currentPopup) {
		var	el	= $(currentPopup);
		new Effect.Opacity(currentPopup, {duration: 0.3, from: 1, to: 0, afterFinish: function() { el.hide(); }, queue: { position: 'front', scope: 'popup' }});
	} 

	new Effect.Opacity('layer', {duration: 0.3, from: 0, to: 0.5, beforeUpdate: function() { $('layer').show(); }, queue: {scope: 'popup' }});
	new Effect.Opacity(name, {duration: 0.3, from: 0, to: 1, beforeUpdate: function() { $(name).show(); }, queue: { position: 'end', scope: 'popup' }});

	currentPopup	= name;
}

function	hidePopupLayer() {
	if(currentPopup) {
		var	el	= $(currentPopup);
		new Effect.Opacity('layer', {duration: 0.3, to: 0, afterFinish: function() { $('layer').hide();}, queue: { scope: 'popup' }});
		new Effect.Opacity(currentPopup, {duration: 0.3, to: 0, afterFinish: function() { el.hide(); currentPopup = null;}, queue: { position: 'front', scope: 'popup' }});
	}

}

function	initProduit() {
	new	menuTab('produits_menu');
}

function	initContact() {
	new	menuTab('contact_menu');
}


/**
 * Comment
 */
var	currentStep	= null;
function openStep(id) {
	if(currentStep != null && currentStep != id) {
		closeStep(currentStep);
	}
	Effect.BlindDown(id, { duration: 0.5 });
	currentStep	= id;
}

function closeStep(id) {
	Effect.BlindUp(id, { duration: 0.5 });
}

function	openVideo(urlFLV) {

	var so = new SWFObject("swf/fPlayerIn.swf", "so", '100%', '100%', "9", "#4c241c");
	so.addParam("allowFullScreen", "true");
	so.addParam("wmode", "transparent");
	so.addParam("FlashVars", "urlVideo=" + urlFLV);
	so.write("contentFlash");

	$('contentFlash').show();
}

function	posFlash() {
	var	posTop	= (document.viewport.getHeight()/2) - ($('contentFlash').getHeight()/2);
	var	posLeft	= (document.viewport.getWidth()/2) - ($('contentFlash').getWidth()/2);

	$('contentFlash').setStyle({top: posTop + 'px', left: posLeft + 'px'});
}

function	closePlayer() {
	$('contentFlash').hide();
	$('contentFlash').update('');
}

function	openMiseEnAvant() {
	var so = new SWFObject(urlFlashMiseEnAvant, "so", flashLargeur + "px", flashHauteur + "px", "9", "#4c241c");
	so.addParam("allowFullScreen", "true");
	so.addParam("wmode", "transparent");
	so.write("contentFlash");
	$('contentFlash').setStyle({zIndex: 101, width: flashLargeur + "px", height: flashHauteur + "px"});
	$('contentFlash').show();
	posFlash();

	$('layer').setStyle({color: '#fff'});
	new Effect.Opacity('layer', {duration: 0.3, from: 0, to: 0.01, beforeUpdate: function() { $('layer').show(); }, queue: {scope: 'popup' }});

}

function	closeMiseEnAvant() {
	new Effect.Opacity('layer', {duration: 0.3, to: 0, afterFinish: function() { $('layer').hide();}, queue: { scope: 'popup' }});
	$('contentFlash').hide();
	$('contentFlash').update('');
}

function	setAriane() {
	var	listAriane	= '';
	
	for (var i = 0, length = arguments.length; i < length; i=i+2) {
		if(listAriane != '') {
			listAriane	= listAriane + ',' + arguments[i] + ',' + arguments[i+1];
		} else {
			listAriane	= arguments[i] + ',' + arguments[i+1];
		}
	}

	setCook('ariane', listAriane, 1);
}

document.observe('dom:loaded',	function() {

	initMenu();

	var	ariane	= getCook('ariane');
	if( ariane != '' ) {

		var	elAriane	= $$('.breadcrumb')[0];

		elAriane.update('');

		ariane	= ariane.split(',');
		var	link	= '';
		
		for (var i = 0, length = ariane.length; i < length; i=i+2) {
			
			if( (i+2) < length) {
				link	= new Element('a', {href: ariane[i+1], title: ariane[i]});
				link.update(ariane[i]);
				elAriane.insert(link);
				elAriane.insert(' > ');
			} else {
				link	= new Element('span');
				link.addClassName('current');
				link.update(ariane[i]);
				elAriane.insert(link);
			}

		}

		delCook('ariane');
		
	}

});



