// SIFR REPLACEMENTS
var sifrReplacements = function(){		
	// siFR 3
	var aldo = {
		src: '/swf/AldoSemiBold.swf'
	};
	sIFR.activate(aldo);

	sIFR.replace(aldo, {
		selector: '#contentRight h2',
		//tuneHeight: -6,
		wmode: 'transparent',
		selectable: 1,
		css: [ '.sIFR-root {font-size: 18;color: #FFFFFF; background-color : #FFFFFF;}' ]
	});
	sIFR.replace(aldo, {
		selector: '#contentLeft .projetHaut h2 ',
		//tuneHeight: -6,
		wmode: 'transparent',
		selectable: 1,
		css: [ '.sIFR-root {font-size: 18;color: #FFFFFF; background-color : #FFFFFF;}' ]
	});
	sIFR.replace(aldo, {
		selector: '.contentText h1',
		//tuneHeight: -6,
		wmode: 'transparent',
		selectable: 1,
		css: [ '.sIFR-root {font-size: 30; color: #DB4310; background-color : #FFFFFF}' ]
	});

	sIFR.replace(aldo, {
		selector: '.blocVideo h2 span.coinGauche',
		//tuneHeight: -6,
		wmode: 'transparent',
		selectable: 1,
		css: [ '.sIFR-root {font-size: 20; color: #ffffff; background-color : #F54306}' ]
	});
	
	sIFR.replace(aldo, {
		selector: '.jolimois h2',
		//tuneHeight: -6,
		wmode: 'transparent',
		selectable: 1,
		css: [ '.sIFR-root {font-size: 35; color: #1d4392;}' ]
	});
}
sifrReplacements();

$(document).ready(function(){
	
	//search field
	if($("input[class='searchText']")){ 
		$("input[class='searchText']").focus(function(){	
			if($(this).attr('value') == $(this).attr('title')){
				$(this).attr('value', '');
			}
		});
		$("input[class='searchText']").blur(function(){	
			if($(this).attr('value') == ''){
				$(this).attr('value', $(this).attr('title'));
			}
		});			
	}

	//search field
	if($("#contentLeft input[class='texte']")){ 
		$("#contentLeft input[class='texte']").focus(function(){	
			if($(this).attr('value') == $(this).attr('title')){
				$(this).attr('value', '');
			}
		});
		$("#contentLeft input[class='texte']").blur(function(){	
			if($(this).attr('value') == ''){
				$(this).attr('value', $(this).attr('title'));
			}
		});	
	}		

	
	/* Adrien le 27 mai - gestion du clear datepicker */
	var myInput  = $('input#dateContainer');
	
	var myLinkLabel = "Toutes les dates";

	
	myInput.attr("value",myInput.attr("title"));
	myInput.data("myInitValue",myInput.val());
	myInput.parent('form').css("position","relative");
	
	
	// récupérer les var dans l'url
	$.extend({
		getUrlVars: function() {
		var vars = {};
		var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) { vars[key] = value; });
		return vars;
		}
	});
	
	var  myDate;
	myDate = $.getUrlVars()['date'];
	
	// ajout du lien "effacer la date"
	var addDeleteLink = function(){
	
		if($('a.addLink').length === 0){ 
			$('<a />').addClass("addLink").attr("href","#").html(myLinkLabel).appendTo(myInput.parent('span.datepicker_wrap'));
			
			$('a.addLink').css({
				position:"absolute",
				top:"30px",
				left:"0px",
				color:"#fff",
				fontStyle:"normal"
			});
			$('a.addLink').hover(function(){
				$(this).css("text-decoration","underline");
			},function(){
				$(this).css("text-decoration","none");
			});
			
			
			$('a.addLink').click(function(){
				$(this).remove();
				myInput.val(myInput.data("myInitValue"));
				return false;
			}); 
		};
	}
	
	// ajoute le lien effacer si la valeur est pas celle par défaut
	var manageDeleteLink = function (){
		
		if(myInput.data("myInitValue") != myInput.val()){
			addDeleteLink();
		};
		
	};
	
	// gestion du link avec délai pour compatibilité avec blur+datepicker
	myInput.blur(function(){
		var myDelay = setTimeout(function(){
			manageDeleteLink();
		},500);
		
		
	});
	
	
	// si on a effacé le champ "à la main"
	myInput.change(function(){
		if(myInput.val() == ""){
			myInput.val(myInput.data("myInitValue"));
			$('a.addLink').remove();
		}
	});
	
	
	// clear l'input si format de date invalide avant submit
	$('form.jolimoisMai').submit(function(){
		var datePattern = /^([012][1-9]|3[0-1])\/(0?[1-9]|1[0-2])\/(\d{4})$/;
		if (myInput.val().match(datePattern) == null){
			myInput.val("");
		};
	
	});
	
	// remplace les %2F par des / pour la date
	if (myDate){
		var f1 = "%2F";
		var f2 = "/";
		myDate=myDate.replace(new RegExp(f1,"g"),f2) ;
		myInput.val(myDate);
		var myDelay = setTimeout(function(){
			addDeleteLink();
		},1000);
		
	};
	

});

	

