/*test svn*/


/* ______________________[ 03 | equalizeCols ]________________________ */
(function($) {
	/**
	 * equalizes the heights of all elements in a jQuery collection
	 * thanks to John Resig for optimizing this!
	 * usage: $("#col1, #col2, #col3").equalizeCols();
	 */	 
	$.fn.equalizeCols = function(){
		var height = 0;	  
		function normalize(el) {
			return (parseInt(el.css("paddingTop"), 10) || 0)
				+ (parseInt(el.css("paddingBottom"), 10) || 0)
				+ (parseInt(el.css("borderTopWidth"), 10) || 0)
				+ (parseInt(el.css("borderBottomWidth"), 10) || 0);
  		};  
		return this
			.css("height", "auto")
			.each(function() {
				height = Math.max(height, $(this).outerHeight());
			})
			.css("height", function() {
				return height - normalize($(this));
			});
	};	
})(jQuery);


/* ********************************* APPEL DES FONCTIONS */
$(document).ready(function() {	
	navProv();
	specialIE6();
	roundIt();
	tabsHpEcoute();
	SH1();
	SH2();
	SH3();
	cycleAgenda();
	tabsNotions();
	ocZone();
	firstLI();
	accor();
	toutOuvrirClose(); 
	togglePerso();
	toggleOuiNon();
	lastTxtvisu();
	fnTooltip();
	
	
	$("body").sizetypo({ less: "#less", more: "#more", step: 1 });
	if( $(".jblur").length > 0 ) { $(".jblur").toggleFocus(); }
	
	affSubNav();
	facebox();
	afficonaf();
	setHeight();
	setSchemas();	
	plansite();
	
});

var fnTooltip = function(){
	var div = $(".m1-content .bl-12-i div");
	if( div.length > 0 ) {		
		div.each(function(){
			var f = $(this).find("p.fenetre");
			$(this).mouseenter(function(){
				f.stop(true,true).show(300);
				return false;
			}).mouseleave(function(){
				f.hide(200);
				return false;
			});
		});	
	}	
};

var lastTxtvisu = function(){
	if( $('#mediatheque .m2-content .txtVisu').length > 0 ) {
		$('#mediatheque .m2-content .txtVisu:last').addClass("last");
	}	
}

/* ********************************* NavigationPrincipale */
var affSubNav = function(){	
	if( $('ul#NavigationPrincipale').length < 1 ) {
		return;
	}	
	
	$('ul#NavigationPrincipale li a').each(function(){
		var a = $(this);
		var li = a.parent();
		var ul = li.find('ul:first');
		if( ul.length > 0) {
			li.hover(
				function(){					
					ul.addClass("over");
				},
				function(){
					ul.removeClass("over");
				}
			);		
		}
	});	
}

/* ********************************* Accordion */
var accor = function() {
	if( jQuery(".accor").size() < 1 )
	return false;
	
	$(".accor").accordion({
			collapsible: true,
			autoHeight: false,
			active : ".on"
		});
	return false;
}

/* ********************************* first li */
var firstLI = function() {
	$("ul").each(function(){
		$("li:eq(0)", this).addClass("first");
	});
}

/* ********************************* OPEN/CLOSE NAV PROVISOIRE */
var navProv = function() {
	$('.navProvOC a').click(function() {	
		if($(this).html()=='open') {
			$(this).html('close');
			$('.navProvContent').show();
		}
		else {
			$(this).html('open');
			$('.navProvContent').hide();
		}		
		return false;		
	});
}
/* ********************************* SPECIAL IE6 */
var specialIE6 = function() {
	if ($.browser.msie && $.browser.version == 6.0) {
		$.ifixpng('img/pix.gif');
		$('img[src$=.png]').ifixpng();
	}
}

/* ********************************* CORNERS */
var roundIt = function() {	
	if( !$.browser.msie ){	
		$('.button').corners("2px");
		$('.more').corners("3px");
		if( $('p.tout-liens a').length > 0 ) {
			$('p.tout-liens a').corners("3px");
		}
	}	
}

/* ********************************* TABS ECOUTE HP */
var tabsHpEcoute = function() {
	if( $("#fadeShow").length < 1 ) return false;	
		$("#fadeShow").tabs().tabs('rotate', 15000);
}

/* ********************************* HP : same height */
var SH1 = function() {
	if( jQuery(".sh-line-1").size() < 1 ) return false;
	                    
	var heightBlockMax=0;
	$('.sh-line-1 .contenu').each(function(){ if( $(this).height() > heightBlockMax ) heightBlockMax = $(this).height(); });
	$('.sh-line-1 .contenu').each(function(){ $(this).css("height",heightBlockMax+"px"); });
	heightBlockMax=0;
}

var SH2 = function() {
	if( jQuery(".sh-line-2").size() < 1 ) return false;
	                    
	var heightBlockMax=0;
	$('.sh-line-2 .contenu').each(function(){ if( $(this).height() > heightBlockMax ) heightBlockMax = $(this).height(); });
	$('.sh-line-2 .contenu').each(function(){ $(this).css("height",heightBlockMax+"px"); });
	heightBlockMax=0;
}

var SH3 = function() {
	if( jQuery("#meo").size() < 1 ) return false;
	                    
	var heightBlockMax=0;
	$('.bl-8-i').each(function(){ if( $(this).height() > heightBlockMax ) heightBlockMax = $(this).height(); });
	$('.bl-8-i').each(function(){ $(this).css("height",heightBlockMax+"px"); });
	heightBlockMax=0;
}

/* ********************************* CYCLE Agenda */
function cycleAgenda() {	
	var d = new Date();
	var jour = d.getDay();
	var v = 0;
	switch(jour){
		case 0 : 
		case 1 : 
		case 6 : v = 0; break;
		case 2 : v = 1; break;
		case 3 : v = 2; break;
		case 4 : v = 3; break;
		case 5 : v = 4; break;
	}
	if( $("#cycleAgenda").length < 1 ) return false;
	$('#cycleAgenda').cycle({ 
		prev:   '.btPrevious', 
	    next:   '.btNext',
		startingSlide : v,
	    timeout: 3000
    }).cycle('pause');
}

/* ********************************* TABS NOTIONS HP */
var tabsNotions = function() {
	if( $("#notions3").length < 1 ) return false;
	
	$('#notions3 .bl-4').tabs();
}

/* ********************************* OPEN/CLOSE BLOC CIF */
var ocZone = function() {
	if( $(".bl-oc,.bl-classement-oc").length < 1 ) return false;
	$('.bl-oc h3').each( function(){
    $(this).html($(this).html()+"<a href='javascript:;' class='inter inter-off'><span>ouvrir</span></a>");
  });
	$('.bl-oc .inner2,.bl-classement-oc .inter-content').hide();
	
	$('.inter').click(function() {		
		if( $.trim( $("span", this).html() ) == 'ouvrir') {
			$("span", this).html('fermer');
			$(this).removeClass("inter-off").addClass("inter-on");
		}
		else {
			$("span", this).html('ouvrir');
			$(this).removeClass("inter-on").addClass("inter-off");
		}
		
		if( !$(this).parent().next().is(':visible') ){
			$('.bl-classement-oc .inter-content:visible').each(function(){
				$(this).hide(300);	
				var inter = $(this).parent().find('h3 a');
				inter.find('span').html('ouvrir');
				inter.removeClass("inter-on").addClass("inter-off");
			});		
		}
		
		$(this).parent().next().animate({height: "toggle"}, 500);
		
		return false;
	});
	
	$('.open .inter').click();
}


var toutOuvrirClose = function(){
	if( $('.bl-oc').length < 1) return false;
	if ($(".ListeActus").length < 1 ){
    $('.bl-oc:first').before("<p class='al-r tt-ouvrir'><a class='more-2' href='#'' id='tout-OC'>Tout ouvrir</a></p>");  
  }

	$('#tout-OC').click(function(){
		if( $(this).text() == 'Tout ouvrir' ) {
			$(this).text('Tout fermer');
			$('.inter.inter-off').removeClass("inter-off").addClass("inter-on");
			$('.bl-oc .inner2:hidden').css("display","block");
		}else {
			$(this).text('Tout ouvrir');
			$('.inter.inter-on').removeClass("inter-on").addClass("inter-off");
			$('.bl-oc .inner2:visible').css("display","none");
		}
		return false;
	});
}

var toggleDesc = function(){
	if( $('#modivations .desc .toggle').length < 1 ) return false;
	$('#modivations .desc').each(function(){
		var tog = $(this).find('.toggle');
		var p = $(this).find('.inner-desc');
		tog.click(function(){
			p.slideToggle(500,function(){
				tog.toggleClass('plus');
			});			
		});
	});

}


var toggleOuiNon = function(){	
	if( $('.bl-quest .bl-ck input').length < 1 ) {
		return;
	}		
	
	toggleDesc();
	
	$('.bl-quest').each(function(){
		var quest = $(this);
		var inputs = quest.find('.bl-ck input');
		var desc = quest.find('.desc');
		var pOui = quest.find('.inner-desc p.oui');
		var pNon = quest.find('.inner-desc p.non');
		inputs.each(function(){							 
			var input = $(this);
			var val = input.val();
			
			input.click(function(){	
				if( val == "non" ) {				
					pOui.css("display","none");
					pNon.css("display","block");
				}else {
					pNon.css("display","none");
					pOui.css("display","block");
				}
				desc.addClass("on");
			});
			
			if( input.is(':checked') ) {		
				input.trigger('click');
			}			
		});
	});	
};




/* ********************************* OPEN/CLOSE PERSO */
//togglePerso();

var togglePerso = function() {
	if( $('#perso-space .title').length < 1 ) return false;
	$('#perso-space .title').html($('#perso-space .title').html()+"<a href='javascript:;' class='oc-log on'><span>Fermer</span></a>");	
	$('.oc-log').click(function() {
		if($("span", this).html()=='ouvrir') {
			$("span", this).html('fermer');
			$(this).removeClass("off").addClass("on");
		}
		else {
			$("span", this).html('ouvrir');
			$(this).removeClass("on").addClass("off");
		}	
		$(this).parent().next().animate({height: "toggle"}, 500);
		return false;
	});
}

/* ********************************* Ajouter aux favoris */

function mybookmark() {
	bookmarksite(document.title,document.location.href);
}

function bookmarksite(title,url) {
	if (window.sidebar) { // firefox
		window.sidebar.addPanel(title, url, "");
	}
	else if(window.opera && window.print){ // opera
		var elem = document.createElement('a');
		elem.setAttribute('href',url);
		elem.setAttribute('title',title);
		elem.setAttribute('rel','sidebar');
		elem.click();
	} 
	else if(document.all) {// ie
		window.external.AddFavorite(url, title);
	}
};

/* ********************************* Print */
function DirectPrint() {
	if (window.print) self.print();
}

/* ********************************* afficher un lightbox */
var facebox = function(){
	if( $('a[rel*=facebox]').length > 0 ) {			
		$('a[rel*=facebox]').facebox();
	}
}

var afficonaf = function(){	
	if( $('a.af').length > 0 ) {		
		$('a.af').each(function(){
			var af = $(this);
			af.hide();
			var li = af.parents("li:first");		
			li.hover(
				function(){
					af.fadeIn(500);
				},
				function(){
					af.fadeOut(500);
				}
			);	
		});	
	}
}

var setHeight = function(){
	if( $('#dispositif .contenu').length > 0 || $('#dispositif .contenu2').length > 0 ) {
		$("#dispositif .contenu, #idf .contenu2").equalizeCols();
	}
}

/*_______schemas_________*/

var setSchemas = function(){

	if( $('div#col-c div#map').length > 0 ) {	
		var map = $('div#col-c div#map');
		if( map.length > 0 ) {
			var areas = map.find("area");
			var img = map.find("#imgMap");
			var oldsrc = img.attr('src');
			var path = oldsrc.substring(0,oldsrc.lastIndexOf('/')+1);
			areas.each(function(){
				var area = $(this);
				var id = area.attr('id');
				var newsrc = path + id + '.jpg';
				area.hover(
					function(){
						img.attr("src",newsrc);
					},
					function(){
						img.attr("src",oldsrc);
					}
				);
			});
		}
	}
}

/*______plan du site________*/

var plansite = function(){
	if( $('div#plansite').length < 0 ) {
		return;
	}
	var txtOC = '<a href="javascript:;" class="openclose"><span>afficher ou masquer</span></a>'
	var allUL = $('div#plansite ul li ul');
		allUL.css("display","none");
		allUL.each(function(){
			var li = $(this).parents("li:first");
				li.addClass("toggle");
			var a = li.find('a:first');
			a.before(txtOC);		
		}); 
		
	/* TEST SVN

	$('div#plansite ul li ul').css("display","none");
	$('div#plansite ul li:has(ul)').each(function(){
		var li = $(this);
		$(this).addClass("toggle");
		var subUL = li.find('ul:first');
		var a = li.find('a:first');
		a.before(openclose);		
	}); 

	TEST SVN BIS
TEST SVN TER TEST SVN QUATUOR
	 */
	
	var allOC = $('div#plansite ul li a.openclose');
		allOC.each(function(){
			var OC = $(this);		
			var ul = OC.nextAll("ul");
				OC.click(function(){								 
					ul.slideToggle(500,function(){
						OC.toggleClass("on");
					});
				});
		});
	
	if( $('p#tous').length > 0 ) {
		$('p#tous a').click(function(){
			var a = $(this);
				if( a.is(":contains('afficher')") ) {
					allUL.css("display","block");
					allOC.addClass("on");
					a.text("Tout masquer");
				}else {
					allUL.css("display","none");
					allOC.removeClass("on");
					a.text("Tout afficher");
				}
			return false;
		});
	}
}
