$(document).ready(function(){
	$('.select').addClass("hide");
});

/********************************************************/
// Variables globales
/********************************************************/

ongletHover = 0;

/********************************************************/
// Fonctions
/********************************************************/

//Impression de la fenêtre
function toPrint(){	
		window.print();
		return false;	
}

var eventsTools = function (){
	
	// Affichage / Masquage des événements
	function toggleView(){		
	
		 var eContent = $(this).parent().parent().find('.content');
		 eContent.css('display');
				 
		 if (eContent.css('display') == 'block')
			eContent.hide();
		 else
			eContent.show(); 
		 
		$(this).parent().parent().toggleClass('close');
		 
		 return false;
	
	};

	//Gestion de la zone de commentaire
	function toggleTextArea(){
		
		$(this).parent().prev().toggleClass('on');	
		$(this).parent().prev().attr('disabled','');	
			
		return false;
			
	};
	
	function init(){
		
		//On masque le bouton submit
		$('p.lienModifier input').hide();
		//pour afficher le lien html
		$('p.lienModifier a').show();
		
		$('textarea.toggleTextArea').addClass('off');

		//Gestionnaire d'évenement pour ouvrir / fermer les événements
		$('a.arr').bind('click', toggleView );
		//On masque les inputs text
		$('ul.tools li.inputDate').hide();
		//On affiche le picto Agenda
		$('ul.tools li.agendaButton').css('display','inline');
		//On affiche le picto Map
		$('ul.tools li.mapButton').css('display','inline');
		
		$('p.lienModifier a').bind('click', toggleTextArea);

	};		

	return {		
		init: init		
	};
		
}();

function showPopin(type){
    
	var dim = getPageSize();
	var scroll = getPageScroll();
	var overlay = $('#popinOverlay');
	var popin = $('#'+type);
	var popinBG = $('.popinBG');

	overlay.css({
		width: dim[0],
		height: dim[1],
		opacity: 0.7,
		display: 'block'
	}).fadeIn();
	
	if($('.popinBG').length){
		
		$(popinBG).css({
			top: scroll[1] + ($(popinBG).height() / 10),
			left: (dim[2]-$(popinBG).width())/2,
			opacity: 1,
			display: 'block'
		});
	}
	popin.css({
		top: scroll[1] + (dim[3] / 10),
		left: (dim[2]-$(popin).width())/2,
		opacity: 1,
		display: 'block'
	}).fadeIn();
	
	popin.find('.btnFermer').bind('click', function(){
		overlay.fadeOut();
		popin.fadeOut(function(){
			if($.browser.msie){ $("select").css("visibility","visible");	}	// enlever les selects pour IE
		});
		if(popinBG) popinBG.fadeOut();
		
	});			
}

function focusBlur(){
    
    // Search fields
    $("input[@id=search]").bind('focus', function (event){
            $("input[@id=search]").val('');
        }
    );
}


/********************************************************/
// Chargement de la page
/********************************************************/

$(document).ready(function(){
	
	focusBlur();

	$('li.print a').bind('click', toPrint );
	
	//Commentaires
	eventsTools.init();	

	/* Fix pb titre Home 3 */
	$('#inner .homeNiveau3 .intro h2').css('display', 'block');
	
	navigationDisplay();
	
	/* affichage/masquage du choix de date sur la home, en fonction de la sélection dans le bloc "rechercher un événement" */
	radioCheckAndSwap(".radioContainer input[name='rWhen']",".dateContainer",3);
});

/* affichage/masquage du choix de date sur la home, en fonction de la sélection dans le bloc "rechercher un événement" */
var radioCheckAndSwap = function(radioList,itemToSwap,numForSwapingItem){	
	jQuery(radioList+":eq("+numForSwapingItem+")").bind("click",function(){
		jQuery(itemToSwap+" input").each(function(index){jQuery(this).removeAttr("disabled")});
		jQuery(itemToSwap+" img").css({"visibility":"visible"});	
	});
	jQuery(radioList).each(function(index){
		if(index!=numForSwapingItem){
			jQuery(this).bind("click",function(){
				jQuery(itemToSwap+" input").each(function(index){jQuery(this).attr("disabled","disabled")});
				jQuery(itemToSwap+" img").css({"visibility":"hidden"});		
			});
		}
	});		
	//on masque la première fois
	jQuery(itemToSwap+" input").each(function(index){jQuery(this).attr("disabled","disabled")});
	jQuery(itemToSwap+" img").css({"visibility":"hidden"});	
}
	

/**
 * On stoppe la recherche MNO Go search s'il y a moins de 4 caractères
 */
function stopRecherche() {
	var champsRecherche = document.getElementById('search');
	if (champsRecherche.value.length >= 3) {
		return true;
	}
	return false;
}

/* Fonction show/hide nav */
function navigationDisplay(){
	jQuery("ul#mainNav > li").hover(function(){
				 jQuery(this).addClass("activeMenuItem");
	  },function(){
			 jQuery(this).removeClass("activeMenuItem");
	  });
}


