/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Fonction appelé par le flash pour afficher un golf.
 */
function	displayGolfBis(id_golf, domaine, lang) {
	
	$('reseauGolf').fade({duration: 0.1, from: 1, to: 0});


//	new Effect.Highlight('reseauGolf',{duration: 2});

//	$('reseauGolf').fadeOut();

	new	Ajax.Updater('reseauGolf', 'spip.php?page=infoGolfDomaine&id_item=' + id_golf + '&idLang=' + lang,
					{
						onComplete: function(){$('reseauGolf').appear({duration: 0.5});},
						onSuccess: function(){$('reseauGolf').appear({duration: 0.5});}
					});
}


/**
 * Charge un contenu en Ajax pour le layer
 */
function loadAjaxLayer(url) {
	new	Ajax.Updater('blocLayer', url, 
						{
							onComplete	: openLayer,
							evalScripts	: true
						});
}

/**
 * Ouvre le layer
 */
function openLayer() {
	$('blocLayer').insert('<div id="layerClose" onclick="closeLayer();"><a href="#" title=""></a></div>');

	if(!Prototype.Browser.IE) {
		$('blocLayer').appear({duration: 0.2});
	} else {
		$('blocLayer').show();
	}
}

/**
 * Ferme le layer
 */
function closeLayer() {
	
	if(!Prototype.Browser.IE) {
	    $('blocLayer').fade({duration: 0.2, afterFinish: function(){$('blocLayer').hide();}});
	} else {
		$('blocLayer').hide();
	}
}

var	continuScroll	= null;
var	currentInterval	= 300;

/**
 * Création d'une scrollbar
 */
function addScrollBar(id_content, id_track, id_up, id_down) {
	var scrollbar = new Control.ScrollBar(id_content, id_track);
//	$(id_up).observe('mousedown',function(event){scrollbar.scrollBy(-10);});
//	$(id_down).observe('mousedown',function(event){scrollbar.scrollBy(10);});

	$(id_up).observe('mousedown',
		function() {
			continuScroll	= true;
			scrollUpContinu(scrollbar);
		}
	);
		
	$(id_down).observe('mousedown',
		function() {
			continuScroll	= true;
			scrollDownContinu(scrollbar);
		}
	);
		
	Event.observe(document, "mouseup", stopScrollContinu);
	
	return	scrollbar;
}

/**
 * Comment
 */
function scrollUpContinu(scrollbar) {
//	alert('ok');
	scrollbar.scrollBy(-10);

	if(continuScroll == true) {
		setTimeout(scrollUpContinu.bind(this, scrollbar), currentInterval);
	}

	if(currentInterval > 30) {
		currentInterval	= currentInterval/1.2;
	}

}

function scrollDownContinu(scrollbar) {
	scrollbar.scrollBy(10);

	if(continuScroll == true) {
		setTimeout(scrollDownContinu.bind(this, scrollbar), currentInterval);
	}

	if(currentInterval > 30) {
		currentInterval	= currentInterval/1.2;
	}

}

/**
 * Comment
 */
function stopScrollContinu() {
	continuScroll	= null;
	currentInterval	= 300;
}
/**
 * initialisation des menus déroulants
 */
function initMenu() {

	$('menuNavigation').select('div.mustOpen').each(
		function(el) {
			if(el.select('ul')[0]) {
				
				new protoMenu(el.readAttribute('id'), {
					delayHide		: 0.15,
					durationShow	: 0.3,
					durationHide	: 0.3,
					idContent		: el.select('ul')[0]
				});
			}
		}
	);

}

/**
 * initialisation du choix de langue
 */
function initChoiceLanguage() {
	$('langue').hide();
	var	link	= $$('#menuLangue a')[0];

	link.observe('click', function(){
		Effect.toggle($('langue'), 'blind', {duration: 0.3});
	});

	link.onclick	= function() {return false;};

}

/**
 * initialisation du formulaire d'identification
 */
function initLogin() {
	var	link	= $$('#menuMembre a')[0];

	link.observe('click', function(){
		Effect.toggle($('espaceMembre'), 'slide', {duration: 0.3});
	});

	link.onclick	= function() {return false;};
	
}

/**
 * Initialise les liens Ajax qui s'affiche dans un layer
 */
function initAjaxLayer() {

	$$('.ajaxLayer').each(
		function(el) {
//			alert(el);
			el.observe('click', function(){
				loadAjaxLayer(this.href);
			});

			el.onclick	= function(){return false;};
		}
	);
}

/**
 * intialisation global de la page
 */
function init() {
	
	initMenu();
	initLogin();
	initChoiceLanguage();
	initAjaxLayer();

}


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


