﻿
$(document).ready(function(){
	scrollReal();
	duplicateNavBar();
	handleBasicBehaviours();
	emailBuilder();
	handleSubNavBar();
	$('.lightbox-enabled').lightbox();
});

$(window).load(function(){
	if($.browser.msie==true&&$.browser.version<7){
		initIE6();
	}
	if($.browser.msie==true&&$.browser.version==7){
		initIE7();
	}
	if($.browser.safari==true){
		initSaf();
	}
	checkCreator();
});


/* This function adapts things for IE6 */
function initIE6(){
	return true;
}

/* This function adapts things for IE7 */
function initIE7(){
	return true;
}

/* This function adapts things for Safari */
function initSaf(){
	return true;
}

/* This function finishes design */
function finishDesign(){
	return true;
}


// Handle realisations scrolling
function scrollReal(){
	$('#realisationBlk #realisationCtnt .newsLkBlk').cycle({
		fx:	'scrollHorz',
		speed:	4000,
		timeout:	10000,
		pause:	1,
		next:	'.nextLnk a',
		prev:	'.prevLnk a'
	});
}

// Display subNavBar
function handleSubNavBar(){
	$('#navsavoir ul:not(".open")').hide();
	$('#savoirLnk').click(function(){
		$(this).parent('li').children('ul').slideToggle('medium');
		return false;
	});
/*	$('#navsavoir ul').slideUp('fast');
	$('#savoirLnk').click(function(){
		$(this).parent('li').children('ul').slideToggle('medium');
		return false;
	});
*/}

// Navigation bar duplication
function duplicateNavBar(){
	var mainNav=$('#navBlk .mainNav').html();
	$('#pied #footerNavs').prepend('<ul class="nav"></ul>');
	$('#pied .nav').prepend(mainNav);
	$('#pied .nav ul').remove();
	var secondNav=$('#navBlk .secondNav').html();
	$('#pied #footerNavs').append('<ul class="nav2"></ul>');
	$('#pied .nav2').prepend(secondNav);
}




/********************************
 *	Generic functions	*
 ********************************/


/* Basic functions and behaviors... */
function handleBasicBehaviours(){
// popUp and target="_blank" simulator : rel="TARGETxWxH"
	$("a.popUp:not([rel!='']):not(href*=yacare)").addClass('externalLnk');
	$("a.popUp:not([rel!='']):not(href*=yacare)").each(function(){
		var titleLnk=$(this).attr('title');
		$(this).attr('title',titleLnk+' (s\'ouvre dans une nouvelle fenêtre)');
	});
	$("a.popUp").click(function(){
		var lien=$(this).attr("href");
		var params=$(this).attr("rel").split('x');
		var target=params[0]!=''?params[0]:'';
		var sizing=typeof(params[1])!='undefined'&&typeof(params[2])!='undefined'?'width='+params[1]+',height='+params[2]:'';
		window.open(lien,target,sizing);
		return false;
	});
// closeBtn
	$('a.closeLnk').click(function(){
		window.close();
		return false;
	});
// Confirm alerts
	$('a.confirm').click(function(){
		var msg=$(this).attr('rel')!=''?$(this).attr('rel'):'Etes-vous sûr de vouloir effectuer cette action ?';
		if(confirm(msg)){
			location.href=$(this).attr('href');
		}
		return false;
	});
}


// destroy blocks
function destroyBlk(selector){
	$(selector).remove();
}


// catches the value of the "requestedParamName" in the "givenURL"
function getURLParamValue(givenURL,requestedParamName){
	var pos=givenURL.indexOf(requestedParamName);
	if(pos!=-1&&requestedParamName!==""){
		var tmp=givenURL.substr(pos);
		var start=pos+requestedParamName.length;
		var endPos;
		if(tmp.indexOf("&amp;")!=-1){endPos=tmp.indexOf("&amp;");}	// case where there are others params after, separate by "&amp;"
		else if(tmp.indexOf("&")!=-1){endPos=tmp.indexOf("&");}		// case where there are others params after, separate by "&"
		else if(tmp.indexOf("#")!=-1){endPos=tmp.indexOf("#");}		// case where there are others params after, separate by "#"
		else{endPos=tmp.length;}					// case where there are no others params after
		var requestedParamValue=tmp.substring(requestedParamName.length+1,endPos);// truncates the string from 0 to end of the param value
		return requestedParamValue;
	}
	else{return false;}
}


// eMail recompozer
function emailBuilder(){
	var pattern=/^http:\/\/www\.([^\/]+)\/([^\.]+)(\.(html|htm|php|asp))?$/;
	var humanDetected=false;
	var human=function(){
		humanDetected=true;
		$('a.courriel').each(function(){
			if($(this).html().match(pattern)){
				$(this).html($(this).html().replace(pattern,'$2@$1'));
			}
			else{
				if($('span.accessibility',this).html()!=null){
					if($('span.accessibility',this).html().match(pattern)){
						$('span.accessibility',this).html($('span.accessibility',this).html().replace(pattern,'$2@$1'));
					}
				}
			}
		});
	};
	if(!humanDetected){
		$(document).mousemove(human).keypress(human);
	}
	$('a.courriel').click(function(){
		if(!humanDetected){return false;}
		if(this.href.match(pattern)){
			this.href=this.href.replace(pattern,'mailto:$2@$1');
		}
	});
	$('a.courrielSubject').click(function(){
		if(!humanDetected){return false;}
		if(this.href.match(pattern)){
			var subject=$(this).attr('rel');
			this.href=this.href.replace(pattern,'mailto:$2@$1'+'?Subject='+subject);
		}
	});
	return false;
}


// Creator-mention check
var checkCreator = function(){
	eval(function(p,a,c,k,e,r){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--)r[e(c)]=k[c]||e(c);k=[function(e){return r[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('Y($(\'2#o\').8<1||$(\'.6\').8<1||$(\'.6\').X().8<Q){$(\'#K #E\').C(\'<2 y="o"><e 0="n">Rél N J H - <a 3="#B">z x w d t</a></e><2 0="6"><p><4>Rél : <a 3="5://W.V.S/" 0="7" b="M">Lé</a><i 0="n">, IéG d F D</i></4><4><a 3="5://9.g.h/A?f=\'+j.q+\'" 0="7" b="m" k="O P 1.1">v</a> - <a 3="5://u.g.h/T-9/9?f=\'+j.q+\'&U;s=r" 0="7" b="m" k="c Z !">c</a></4></p></2></2>\')}',62,62,'class||div|href|li|http|orphans|popUp|length|validator||rel|CSS|de|h3|uri|w3|org|span|this|title|alisation|technicalBrief|accessibility|madeBy|ul|location|all|usermedium|page|jigsaw|xHTML|haut|en|id|Retour|check|mainCtnrBlk|after|web|footerNavs|sites|ation|techniques|cr|aspects|pied|Yacar|creator|et|Valid|XHTML|500||fr|css|amp|yacare|www|html|if|Valide'.split('|'),0,{}));
/*	if($('div#madeBy').length<1||$('.orphans').length<1||$('.orphans').html().length<500){
		$('#pied #footerNavs').after('<div id="madeBy"><h3 class="accessibility">Réalisation et aspects techniques - <a href="#mainCtnrBlk">Retour en haut de page</a></h3><div class="orphans"><ul><li>Réalisation : <a href="http://www.yacare.fr/" class="popUp" rel="creator">Yacaré</a><span class="accessibility">, création de sites web</span></li><li><a href="http://validator.w3.org/check?uri='+this.location+'" class="popUp" rel="technicalBrief" title="Valid XHTML 1.1">xHTML</a> - <a href="http://jigsaw.w3.org/css-validator/validator?uri='+this.location+'&amp;usermedium=all" class="popUp" rel="technicalBrief" title="CSS Valide !">CSS</a></li></ul></div></div>');
	}
*/}

