/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \
|		
|		Copyright (c) 2009
|		Design + HTML/CSS/DOM JavaScript : Smart Agence
|		http://www.smartagence.com/
|
|
|		[ OPEN/CLOSE NAV PROVISOIRE ]
|		[ AJOUT DU TARGET BLANK SUR LES LIENS EXTERNES ]
|		[ Interaction menu principal (menu horizontal) ]
|		[ Gestion corps du texte article ]
|		[ Lancement impression ]
|		[ Miscellaneous ]
|		[ Ajout aux favoris ]
|		[ ToolBox ]
|		[ Roll over ]
|		[ Plan du site ]
|		[ VideoThumbGen ]
|		[ Equalize ]
|		[ Bloc ouvrant-fermant ]
|		[ Lancement scripts ]
|		
\ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */

var avenirlight={src:'lib/js/avenirlight.swf'};

sIFR.activate(avenirlight);
sIFR.replace(avenirlight, {
	selector: 'h1 span',
	css: '.sIFR-root {background-color:transparent;leading:0;display: block; color: #eb6909;}',
	transparent:true ,
	tuneHeight : -8
});
sIFR.replace(avenirlight, {
	selector: '.rowB h2',
	css: '.sIFR-root {background-color:transparent;leading:0;color: #eb6909}',
	transparent:true ,
	tuneHeight : -6
});
sIFR.replace(avenirlight, {
	selector: '.HomeTabs h2',
	css: '.sIFR-root {background-color:transparent;leading:0;color: #717376}',
	transparent:true ,
	tuneHeight : -7
});
sIFR.replace(avenirlight, {
	selector: '#SsRubTitle',
	css: '.sIFR-root {background-color:transparent;leading:0;color: #ffffff}',
	transparent:true ,
	tuneHeight : 0
});
sIFR.replace(avenirlight, {
	selector: '.moreInfos h2',
	css: '.sIFR-root {background-color:transparent;leading:0;color: #a74299;}',
	transparent:true ,
	tuneHeight : -6
});

/* - - - - - - - - - - - - - - - - - - - - - [ OPEN/CLOSE NAV PROVISOIRE ] */
function navProv() {
	$('#navProvForm').hide();
	$('.navProvOC a').click(function() {	
		if($(this).html()=='+') {
			$(this).html('-');
			$('#navProvForm').show();
		} else {
			$(this).html('+');
			$('#navProvForm').hide();
		}
		return false;
	});
}

/* - - - - - - - - - - - - - - - - - - - - - [ AJOUT DU TARGET BLANK SUR LES LIENS EXTERNES ] */
  
(function($) { 
	$('a[href*=http://][href!='+location.hostname+']').attr("target","_blank");
})(jQuery);

/* - - - - - - - - - - - - - - - - - - - - - [ Champs focus sur input recherche ] */

(function($) {
    $.fn.toggleFocus = function() {
        return this.each( function() {
            var input =  $(this);
			if( input.length > 0 ) {
				var id_input = input.attr("id");
				var form = input.parents("form");
				var label = form.find("label").attr("for",id_input);				
				var old_val = label.text() || "";
				label.css("display","none");
				input.val(old_val);
				
				var news_val = "";
				input.focus(function() {
					news_val = input.val() ;
					if ( old_val == news_val ) {
						input.val("");
					}
				});
				input.blur(function() {
					if (input.val() != "" ){
						news_val = input.val();
					} else {
						news_val = old_val ;
					}
				   input.val(news_val);
				});
			}
        });
    };
})(jQuery);

/* ______________________[ 02 | Interactivité du menu principal (menu horizontal) ]________________________ */
/* A special thanks goes to Eric Shepherd for his ALA article about “Hybrid CSS Dropdowns”: http://www.alistapart.com/articles/hybrid/ 
and to Patrick Griffiths and Dan Webb for their htmldog.com article “Sons of Suckerfish”: http://www.htmldog.com/articles/suckerfish/ */

function SmartHover(ele) {
	if(typeof ele != "string") {
		return;
	}	
	var navRoot = $("#"+ele+" ul");	
	if ( navRoot.length >0 ) {
		var kids = navRoot.find("li:has('ul')");
		var uls = navRoot.find("li:has('ul') ul");
		var kidsa = navRoot.find("li:has('ul') a");
		kids.each(function(){
			var li = $(this);
			var afocus = li.find("a:first");
			var ul = li.find("ul");
			li.mouseenter(function(){
				kids.removeClass('over')
				li.addClass('over');
				uls.hide();
				ul.stop(true, true).slideDown(300).find('*');
				return false;
			}).mouseleave(function(){
				li.removeClass('over');					
				uls.hide();
				return false;
			});
			afocus.focus(function(){
				li.trigger("mouseenter");
				return false;
			});
		});
		
	}
}



/* - - - - - - - - - - - - - - - - - - - - - [ Gestion corps du texte article ] */
function SmartSize(args) {
	var cadre = $("#"+args);	
	if( cadre.length > 0 ) {
	/*
		var ftz = cadre.css("fontSize");
		var ftzNum = parseFloat(ftz.substring(0,ftz.length-2));
	*/
		var ftzNum = 12;
		$("#Tplus").click(function(){
			ftzNum = ftzNum+1;			
			cadre.css("fontSize", ftzNum+"px");		
		 });		
		$("#Tmoins").click(function(){		
			ftzNum = ftzNum-1;		
			cadre.css("fontSize", ftzNum+"px");			
		});	
	}	
}

/* - - - - - - - - - - - - - - - - - - - - - [ Lancement impression ] */
function DirectPrint() {
	if (window.print) self.print();
}

/* - - - - - - - - - - - - - - - - - - - - - [ Miscellaneous ] */
function OpenPopup(url,nom,option) {
	window.open(url,nom,option);
}

/* - - - - - - - - - - - - - - - - - - - - - [ Ajout aux favoris ] */
function bookmarksite() {
	var title = document.title;
	var url = document.location.href;
	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);
	}
}

/* - - - - - - - - - - - - - - - - - - - - - [ ToolBox ] */
function AddToolButton(targets) {	
	if( typeof targets == "string" ) {
		return;
	}	
	var toolbox = $("#"+targets.idWrap);
	var linkId = targets.linkId || "";
	var imgSrc = targets.imgSrc || "";
	var imgAlt = targets.imgAlt || "";	
	var linkHref = targets.linkHref || "";
	var ele = targets.insertBefore || "";

	if(!linkHref) {
		linkHref = "javascript:;";
	}
	if( toolbox.length > 0 ) {
		var ul = toolbox.find("ul");
		if( ul.length == 0 ) {			
			toolbox.html("<ul></ul>"); 
			ul = toolbox.find("ul");
		}
		var li = '<li><a href="'+linkHref+'" id="'+linkId+'" title="'+imgAlt+'"><img src="'+imgSrc+'" alt="'+imgAlt+'"/></a></li>';
		
		if( ele !="" && $("#"+ele).length > 0) {	
			var li_frere = $("#"+ele).parents("li:first");
			$(li).insertBefore(li_frere);
		}else {	
			$(li).appendTo(ul);
		}
	}	
}

function setroll(toolbox) {
	/*Roll over*/
	if( typeof toolbox != "string" ) {
		return;
	}	
	var ul = $("#"+toolbox).find("ul");
	ul.find("li a").hover(
		function(){			
			roll($(this).find("img"));
		},
		function(){
			roll($(this).find("img"));
		}
	);
}


/* - - - - - - - - - - - - - - - - - - - - - [ Roll over ] */
function roll(o) {
	var src,ftype,newsrc;
	src=o.attr("src");
	ftype=src.substring(src.lastIndexOf('.'), src.length);
	if(/_over/.test(src)) {
		newsrc=src.replace('_over','');
	} else {
		newsrc=src.replace(ftype, '_over'+ftype);
	}
	o.attr("src",newsrc);
}

/* - - - - - - - - - - - - - - - - - - - - - [ VideoThumbGen ] */
function videoThumb() {
	if($("#ColContenu .videos .contenu .inner .inner2 .txtVisu .blocVisu img").length>0 ) {
		var imgPreview=$("#ColContenu .videos .contenu .inner .inner2 .txtVisu .blocVisu img");
		imgPreview.each(function(){
			var tmpImgSrc=$(this).attr('src');
			$(this).parents(".blocVisu").css('background-image','url('+tmpImgSrc+')');
			$(this).attr("src","img/play.png");
		});
	}
}

/* - - - - - - - - - - - - - - - - - - - - - [ Equalize ] */
/**
 *
 * Copyright (c) 2007 Tom Deater (http://www.tomdeater.com)
 * Licensed under the MIT License:
 * http://www.opensource.org/licenses/mit-license.php
 * 
 */
 
(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,
			reset = $.browser.msie ? "1%" : "auto";
		return this
			.css({"height" : reset})
			.each(function() {
				height = Math.max(height, this.offsetHeight);
				ht = "auto";
				minH = Math.max(height, this.offsetHeight);
				if (jQuery.browser.msie &&parseInt(jQuery.browser.version)<=6) {
				 ht = Math.max(height, this.offsetHeight);
				}
			})
			.css({"height" : ht, "minHeight":minH})
			.each(function() {
				var h = this.offsetHeight;
				if (h > height) {
					$(this).css({"height" : height - (h - height)});
			};
		});
	};
})(jQuery);

/* - - - - - - - - - - - - - - - - - - - - - [ Bloc ouvrant-fermant ] */

(function($){	
	$.fn.openclose = function(options) {
		var defaults = {
			labels : new Array("Lire la suite","Masquer la suite")
		};
		var options = $.extend(defaults, options);
		return this.each(function() {
			var global = $(this);
			var labels = options.labels;
			var globalcontent = $(this).find(".inner2:first");
			var globaltitle = $(this).find("h2, .eqH3 p:not(.date)");
			global.addClass("close").find(".inner2:first").hide();
			globaltitle.wrapInner('<span class="togglebut"><a href="javascript:;"></a></span>');
			globaltitle.find("a").append('<span class="label">… '+labels[0]+'</span>');
			global.find(".togglebut a").click(function() {
				var toggle=$(this);
				globalcontent.slideToggle("fast", function() {
					global.toggleClass("close");
					toggleLabel=toggle.find(".label");
					toggleLabel.html()=='<span class="label">… '+labels[1]+'</span>'?toggleLabel.html('<span class="label">… '+labels[0]+'</span>'):toggleLabel.html('<span class="label">… '+labels[1]+'</span>');
				});
			});
		});
	};	
})(jQuery);


/* ONGLETS */
(function($) {
  $.fn.tabulations = function() {
    return this.each( function() {
        var onglet =  $(this).find('li');
        var ongleta = onglet.find('a');
        var changement = function (ele, slide){
          onglet.each(function(){
            $(this).removeClass("selected");
            $('#'+$(this).find('a').attr("href").split('#')[1]).hide();
          });
          ele.addClass("selected");
          $(slide).show();
        }
        ongleta.click(function(){
          var volet = '#'+$(this).attr("href").split('#')[1];
          var voletp = $(this).parents("li");
          changement(voletp, volet);
          return false;
        });
    });
  };              
})(jQuery);

/* - - - - - - - - - - - - - - - - - - - - - [ CARTE ] */
function carteSurvol () {
	$("#Map area").mouseenter(function () {	
		$(".AreaSurvol").remove();
	  $(this).parents("#Map").prepend("<div class='AreaSurvol' id='piece"+$("#carte_de_france area").index(this)+"'><a href='"+$(this).attr("href")+"' class='over'>"+$(this).attr("alt")+"</a></div>");
   });
	 $("#Map img").mouseleave(function () {						   	
	  	$(".AreaSurvol").remove();
	 });
};

/* - - - - - - - - - - - - - - - - - - - - - [ Lancement scripts ] */
jQuery(document).ready(function($){
	navProv();
	videoThumb();
	/* togglefocus */	
	if( $("#mot_cle").length > 0 ) {
		 $("#mot_cle").toggleFocus();
	}
	
	/* toolBox */	
	if( $("#toolBox").length > 0 ) {
	  AddToolButton({idWrap:"toolBox",linkId:"favoris",linkHref:"javascript:bookmarksite();",imgSrc:"img/toolbox/favoris.gif",imgAlt:"Ajouter aux favoris",insertBefore:"ami"});
	  AddToolButton({idWrap:"toolBox",linkId:"Tmoins",imgSrc:"img/toolbox/Tmoins.gif",imgAlt:"Réduire la taille du texte",insertBefore:"favoris"});
		AddToolButton({idWrap:"toolBox",linkId:"Tplus",imgSrc:"img/toolbox/Tplus.gif",imgAlt:"Agrandir la taille du texte",insertBefore:"Tmoins"});
		AddToolButton({idWrap:"toolBox",linkId:"print",linkHref:"javascript:DirectPrint();",imgSrc:"img/toolbox/print.gif",imgAlt:"Imprimer la page"});
		setroll("toolBox");
		SmartSize("ColContenu");
	}

	if($("#NavigationPrincipale").length > 0) {
		SmartHover("NavigationPrincipale");
	}
	
	if( $(".openclose").length > 0) {	
		//si autre langage en anglais : passer en parametre une table pour labels			
		if( $("html").attr("lang") == "en" ) {
			var tab = new Array("Open","Close","Display all","Hide all");
			$(".openclose").openclose({labels : tab});			
		}else {
			//par defaut : les labels en francais
			$(".openclose").openclose();
      		/*if($("#ColContenu .openclose").hasClass(".open")){
				$(".openclose.open .togglebut:first a").click();
			}
			else {
				$(".openclose .togglebut:first a").click();
			}*/
		}			
	}
	
	/* ********************************* TABS */
	if( $(".HomeTabs").length > 0 ){
		$('.HomeTabs .onglets').tabulations();
		$('.HomeTabs .onglets li a:first').click();
	}
	
	/*  ___ [ Equalizer ] __*/	
	if( $(".rowB .box .inner").length > 0 ) {
		$(".rowB .box .inner").equalizeCols()
	}
	
  /*  ___ [ Carte survolée ] __*/	
	if( $("#Map").length > 0 ) {
		carteSurvol();
	}
	
	/*  ___ [ Carte survolée ] __*/	
	if( $(".tablesort").length > 0 ) {
		$(".tablesort thead th").each(function(count){$(this).addClass("cell"+count).html("<span>"+$(this).html()+"</span>")});
			// extend the default setting to always include the zebra widget. 
		$.tablesorter.defaults.widgets = ['zebra']; 
		// extend the default setting to always sort on the first column 
		//$.tablesorter.defaults.sortList = [[0,0]]; 
		// call the tablesorter plugin 
		$("table").tablesorter({ 
			headers: {2: {sorter: false}, 3: {sorter: false}} 
		}).tablesorterPager({container: $("#pager")}); 
	}
	
	$('.hautdepage').localScroll();
	$('#NavigationPrincipale li ul').bgiframe();
	
});
