/*--FUNCTIONS.JS--*/
/*Développements spécifique au site*/

/*-----------  GREYBOX  -----------*/
//Config générale récurente
var greyBoxDefaultConfig = {
	/*--Valeurs ci-dessous requises--*/
	top: 50,												//=> Décalage en PX du haut du document
	duration: 0.6,											//=> Durée totale de l'affichage
	opacity: 0.6,											//=> Opacité du fond Overlay
	error: '<p class="error greybox">Page unaviable</p>'	//=> Message d'erreur d'un chargement AJAX
};
//Variable définissant la durée de la transition
var greyBoxEffectDuration = Math.round((greyBoxDefaultConfig.duration*1000)/2)/1000;
//Fonctions GREYBOX
var greyBoxDefaultConfig={top:50,duration:0.6,opacity:0.6,error:'<p class="error greybox">Page unaviable</p>'};var greyBoxEffectDuration=Math.round((greyBoxDefaultConfig.duration*1000)/2)/1000;function greyBoxShow(b,c,d,a){if(!$("overlay")){$$("body")[0].insert({bottom:'<div id="overlay" onclick="greyBoxHide();"></div>'});if(Prototype.Browser.IE6=Prototype.Browser.IE&&parseInt(navigator.userAgent.substring(navigator.userAgent.indexOf("MSIE")+5))==6){new Event.observe(window,"scroll",function(){$("overlay").setStyle({top:$$("body")[0].cumulativeScrollOffset().top+"px"})})}}if(!$("greyBox")){$$("body")[0].insert({bottom:'<div id="greyBox"><div class="content" id="greyBoxContent"></div><div onclick="greyBoxHide();" class="close"></div></div>'})}if(typeof(a)!="undefined"){if(typeof(a.duration)=="undefined"){greyBoxEffectDuration=Math.round((greyBoxDefaultConfig.duration*1000)/2)/1000}else{greyBoxEffectDuration=Math.round((a.duration*1000)/2)/1000}if(typeof(a.top)=="undefined"){a.top=greyBoxDefaultConfig.top}if(typeof(a.opacity)=="undefined"){a.opacity=greyBoxDefaultConfig.opacity}if(typeof(a.height)=="undefined"&&typeof(greyBoxDefaultConfig.height)!="undefined"){a.height=greyBoxDefaultConfig.height}if(typeof(a.closeText)=="undefined"&&typeof(greyBoxDefaultConfig.closeText)!="undefined"){a.closeText=greyBoxDefaultConfig.closeText}if(typeof(a.title)=="undefined"&&typeof(greyBoxDefaultConfig.title)!="undefined"){a.title='<h1 class="title greybox">'+greyBoxDefaultConfig.title+"</h1>"}else{if(typeof(a.title)=="undefined"&&typeof(greyBoxDefaultConfig.title)=="undefined"){a.title=""}else{a.title='<h1 class="title greybox">'+a.title+"</h1>"}}if(typeof(a.error)=="undefined"&&typeof(greyBoxDefaultConfig.error)!="undefined"){a.error=greyBoxDefaultConfig.error}if(typeof(a.background)=="undefined"&&typeof(greyBoxDefaultConfig.background)!="undefined"){a.background=greyBoxDefaultConfig.background}if(typeof(a.style)=="undefined"&&typeof(greyBoxDefaultConfig.style)!="undefined"){a.style=greyBoxDefaultConfig.style}if(typeof(a.className)=="undefined"&&typeof(greyBoxDefaultConfig.className)!="undefined"){a.className=greyBoxDefaultConfig.className}if(typeof(a.loading)=="undefined"&&typeof(greyBoxDefaultConfig.loading)!="undefined"){a.loading=greyBoxDefaultConfig.loading}if(typeof(a.data)=="undefined"&&typeof(greyBoxDefaultConfig.data)!="undefined"){a.data=greyBoxDefaultConfig.data}if(typeof(a.customFunction)=="undefined"&&typeof(greyBoxDefaultConfig.customFunction)!="undefined"){a.customFunction=greyBoxDefaultConfig.customFunction}}else{greyBoxEffectDuration=Math.round((greyBoxDefaultConfig.duration*1000)/2)/1000;a=greyBoxDefaultConfig;a.title=""}$("overlay").removeAttribute("style");$$("#greyBox .close")[0].innerHTML="";$("greyBox").writeAttribute("class","");$("greyBox").removeAttribute("class");$("greyBoxContent").removeAttribute("style");if(typeof(a.height)!="undefined"&&d!="iframe"&&d!="youtube"&&d!="dailymotion"){$("greyBoxContent").setStyle({overflow:"auto",height:a.height+"px"})}if(typeof(a.closeText)!="undefined"){$$("#greyBox .close")[0].innerHTML=a.closeText}if(typeof(a.background)!="undefined"){$("overlay").setStyle({background:a.background})}if(typeof(a.style)!="undefined"){$("greyBoxContent").writeAttribute("style",a.style)}if(typeof(a.className)!="undefined"){$("greyBox").addClassName(a.className)}$("greyBoxContent").innerHTML='<div id="greyBoxLoader"></div>';if(typeof(a.loading)!="undefined"){$("greyBoxLoader").innerHTML=a.loading}$("greyBox").setStyle({width:c+"px",left:"-"+(Math.ceil(c/2))+"px"});if(typeof(a.customFunction)=="undefined"){switch(d){case"html":var e=function(){$("greyBoxLoader").remove();$("greyBoxContent").innerHTML=a.title+b};greyBoxDisplay(e,a.opacity,a.top);break;case"get":var e=function(){new Ajax.Updater("greyBoxContent",b,{evalScripts:true,insertion:Insertion.Bottom,onSuccess:function(f){$("greyBoxLoader").remove();$("greyBoxContent").insert({top:a.title})},onFailure:function(f){f.responseText="";$("greyBoxContent").innerHTML=a.title+a.error}})};greyBoxDisplay(e,a.opacity,a.top);break;case"post":var e=function(){new Ajax.Updater("greyBoxContent",b,{parameters:a.data,evalScripts:true,insertion:Insertion.Bottom,onSuccess:function(f){$("greyBoxLoader").remove();$("greyBoxContent").insert({top:a.title})},onFailure:function(f){f.responseText="";$("greyBoxContent").innerHTML=a.title+a.error}})};greyBoxDisplay(e,a.opacity,a.top);break;case"iframe":var e=function(){var f=400;if(typeof(a.height)!="undefined"){f=a.height}$("greyBoxContent").innerHTML=a.title+'<iframe src="'+b+'" border="0" frameborder="0" width="100%" height="'+f+'" allowTransparency="true"></iframe>'};greyBoxDisplay(e,a.opacity,a.top);break;case"youtube":var e=function(){var f=400;if(typeof(a.height)!="undefined"){f=a.height}$("greyBoxContent").innerHTML=a.title+'<object width="100%" height="'+f+'" style="display:block"><param name="movie" value="http://www.youtube.com/v/'+b+'&hl=fr_FR&fs=1&rel=0&color1=0x006699&color2=0x54abd6"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="sameDomain"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/'+b+'&hl=fr_FR&fs=1&rel=0&color1=0x006699&color2=0x54abd6" type="application/x-shockwave-flash" allowscriptaccess="sameDomain" allowfullscreen="true" width="100%" height="'+f+'"></embed></object>'};greyBoxDisplay(e,a.opacity,a.top);break;case"dailymotion":var e=function(){var f=400;if(typeof(a.height)!="undefined"){f=a.height}$("greyBoxContent").innerHTML=a.title+'<object width="100%" height="'+f+'" style="display:block"><param name="movie" value="http://www.dailymotion.com/swf/video/'+b+'"></param><param name="allowFullScreen" value="true"></param><param name="allowScriptAccess" value="sameDomain"></param><embed type="application/x-shockwave-flash" src="http://www.dailymotion.com/swf/video/'+b+'" width="100%" height="'+f+'" allowfullscreen="true" allowscriptaccess="sameDomain"></embed></object>'};greyBoxDisplay(e,a.opacity,a.top);break;case"image":var e=function(){$("greyBoxContent").innerHTML=$("greyBoxContent").innerHTML+'<img src="'+b+'" alt="" style="display:none;" id="greyBoxImage" />';new Event.observe("greyBoxImage","load",function(){$("greyBoxImage").setOpacity(0);$("greyBoxImage").setStyle({display:"block"});$("greyBoxLoader").remove();$("greyBoxContent").insert({top:a.title});new Effect.Opacity("greyBoxImage",{duration:0.5,from:0,to:1,afterSetup:function(){$("greyBoxContent").setStyle({width:Math.floor($("greyBoxImage").getDimensions().width)+"px"});$("greyBox").setStyle({width:"auto"});$("greyBox").setStyle({left:"-"+(Math.ceil($("greyBoxContent").getDimensions().width/2))+"px"})}})})};greyBoxDisplay(e,a.opacity,a.top);break;default:break}}else{greyBoxDisplay(a.customFunction,a.opacity,a.top)}return false}function greyBoxDisplay(c,a,b){if($("greyBox").readAttribute("status")!="running"){$("greyBox").writeAttribute("status","running");$("greyBox").setStyle({top:($$("body")[0].cumulativeScrollOffset().top+b)+"px"});if(Prototype.Browser.IE6=Prototype.Browser.IE&&parseInt(navigator.userAgent.substring(navigator.userAgent.indexOf("MSIE")+5))==6){$("overlay").setStyle({position:"absolute",height:document.viewport.getHeight()+"px",top:$$("body")[0].cumulativeScrollOffset().top+"px"});$("greyBoxLoader").setStyle({height:"200px"})}$("overlay").setOpacity(0);$("overlay").setStyle({display:"block"});$$("object:not(.keep-visible), embed").each(function(d){d.setStyle({visibility:"hidden"})});if(Prototype.Browser.IE6=Prototype.Browser.IE&&parseInt(navigator.userAgent.substring(navigator.userAgent.indexOf("MSIE")+5))==6){$$("select").each(function(d){d.setStyle({visibility:"hidden"})})}new Effect.Opacity("overlay",{duration:greyBoxEffectDuration,from:0,to:a,afterFinish:function(){$("greyBox").setOpacity(0);$("greyBox").setStyle({display:"block"});new Effect.Opacity("greyBox",{duration:greyBoxEffectDuration,from:0,to:1,afterFinish:function(){$("greyBox").writeAttribute("status","done");c()}})}})}}function greyBoxHide(){if($("greyBox").readAttribute("status")!="running"){$("greyBox").writeAttribute("status","running");new Effect.Opacity("greyBox",{duration:greyBoxEffectDuration,from:1,to:0,afterFinish:function(){$("greyBox").setOpacity(0);$("greyBox").setStyle({display:"none"});new Effect.Opacity("overlay",{duration:greyBoxEffectDuration,from:$("overlay").getOpacity(),to:0,afterFinish:function(){$("overlay").setOpacity(0);$("overlay").setStyle({display:"none"});$$("object:not(.keep-visible), embed").each(function(a){a.setStyle({visibility:"visible"})});if(Prototype.Browser.IE6=Prototype.Browser.IE&&parseInt(navigator.userAgent.substring(navigator.userAgent.indexOf("MSIE")+5))==6){$$("select").each(function(a){a.setStyle({visibility:"visible"})})}$("greyBox").writeAttribute("status","done")}})}})}};

/*-----------  CC COURT-CIRCUIT  -----------*/
function populateforms(){
	if($('sendlink')){
		//msg1, msg2 et msg3 sont des variables de langue instanciées à  l'appel de la box "Envoyer à  un ami"
		Event.observe('sendlink', 'submit', function(event){
			var result = checkForm(this, event,
				{
					offset:{
						top: -10
					},
					required:{
						elements: new Array('email_fromnom', 'email_toemail', 'email_txt'),
						message: msg1
					},
					email:{
						elements: new Array('email_toemail'),
						message: msg2
					}
				}
			);
			if(result && $('greyBox')){
				greyBoxHide();
				return true;
			}
			else{
				if(!$$('#sendlink p.error .global').length){
					$('sendlink').insert({
						top: '<p class="error text-center"><strong class="global">'+msg3+'</strong></p>'
					});
				}
				return false;
			}
		});
	}
}

/*-----------  CHECK FORM  -----------*/
/*--Function check Form--*/
function checkForm(b,a,e){if(typeof(e.offset)=="undefined"){e.offset={left:0,top:10}}else{if(typeof(e.offset.left)=="undefined"){e.offset.left=0}if(typeof(e.offset.top)=="undefined"){e.offset.top=10}}if(b.readAttribute("status")==null&&b.readAttribute("status")!="initialized"){b.writeAttribute("status","initialized");var c=new Array();if(typeof(e.required)!="undefined"){for(var j=0;j<e.required.elements.length;j++){c.push(e.required.elements[j])}}if(typeof(e.compare)!="undefined"){for(var j=0;j<e.compare.elements.length;j++){c.push(e.compare.elements[j][1])}}if(typeof(e.radio)!="undefined"){for(var j=0;j<e.radio.elements.length;j++){c.push(e.radio.elements[j])}}if(typeof(e.email)!="undefined"){for(var j=0;j<e.email.elements.length;j++){c.push(e.email.elements[j])}}if(typeof(e.date)!="undefined"){for(var j=0;j<e.date.elements.length;j++){c.push(e.date.elements[j])}}if(typeof(e.custom)!="undefined"){for(var j=0;j<e.custom.length;j++){c.push(e.custom[j].element)}}c=c.uniq();for(var j=0;j<c.length;j++){var k=$(c[j]);checkFormFeedback(k,{id:j,offset:e.offset,message:"",position:k.cumulativeOffset()})}}var m=0;if(typeof(e.email)!="undefined"){for(var j=0;j<e.email.elements.length;j++){var k=$(e.email.elements[j]);updateFeedback(k,e.offset.top,e.email.message);var d=/^[a-z0-9._-]+@[a-z0-9.-]{2,}[.][a-z]{2,3}$/;if(d.exec(k.getValue())==null){$(k).ancestors()[0].addClassName("error");m++}}}if(typeof(e.date)!="undefined"){for(var j=0;j<e.date.elements.length;j++){var k=$(e.date.elements[j]);updateFeedback(k,e.offset.top,e.date.message);var d=/^[0-9]{2}[/]{1}[0-9]{2}[/]{1}[0-9]{4}$/;if(d.exec(k.val())==null){$(k).ancestors()[0].addClassName("error");m++}}}if(typeof(e.compare)!="undefined"){for(var j=0;j<e.compare.elements.length;j++){var h=$(e.compare.elements[j][0]);var g=$(e.compare.elements[j][1]);updateFeedback(g,e.offset.top,e.compare.message);if(g.val()!=h.val()){$(g).addClass("error");m++}}}if(typeof(e.radio)!="undefined"){for(var j=0;j<e.radio.elements.length;j++){var k=$(e.radio.elements[j]);var f=0;$$('input[name="'+(k.readAttribute("name"))+'"]').each(function(i){if(i.checked){f++}});if(!f){k.ancestors()[0].addClassName("error");updateFeedback(k,e.offset.top,e.radio.message);m++}}}if(typeof(e.custom)!="undefined"){for(var j=0;j<e.custom.length;j++){var k=$(e.custom[j].element);updateFeedback(k,e.offset.top,e.custom[j].message);if(e.custom[j].reg.exec(k.getValue())==null){$(k).ancestors()[0].addClassName("error");m++}}}if(typeof(e.required)!="undefined"){for(var j=0;j<e.required.elements.length;j++){var k=$(e.required.elements[j]);var l=document.getElementById(e.required.elements[j]).defaultValue;if(k.tagName=="INPUT"){if(k.readAttribute("type")=="text"||k.readAttribute("type")=="password"){if(k.getValue()==""||k.getValue()==l){k.ancestors()[0].addClassName("error");updateFeedback(k,e.offset.top,e.required.message);m++}}else{if(k.readAttribute("type")=="checkbox"||k.readAttribute("type")=="radio"){if(!k.checked){k.ancestors()[0].addClassName("error");updateFeedback(k,e.offset.top,e.required.message);m++}}}}else{if(k.tagName=="SELECT"){var f=0;k.select("option").each(function(i){if(i.selected&&i.value!=""){f++}});if(!f){k.ancestors()[0].addClassName("error");updateFeedback(k,e.offset.top,e.required.message);m++}}else{if(k.tagName=="TEXTAREA"){if(k.getValue()==""||k.getValue()==l){k.ancestors()[0].addClassName("error");updateFeedback(k,e.offset.top,e.required.message);m++}}}}}}if(!m){return true}else{Event.stop(a);return false}}function updateFeedback(d,e,b){$$("#"+d.readAttribute("related_to")+" .message")[0].innerHTML=b;if(d.readAttribute("type")!="checkbox"&&d.readAttribute("type")!="radio"){if($(d.readAttribute("related_to")).measure("width")>d.measure("width")){var a=d.measure("width")-parseFloat($(d.readAttribute("related_to")).getStyle("paddingLeft"))-parseFloat($(d.readAttribute("related_to")).getStyle("paddingRight"));$(d.readAttribute("related_to")).setStyle({width:a+"px"})}else{$(d.readAttribute("related_to")).setStyle({width:"auto"})}}var c=Math.round(d.cumulativeOffset().top)-$(d.readAttribute("related_to")).getDimensions().height+e;$(d.readAttribute("related_to")).setStyle({top:c+"px"})}function checkFormFeedback(d,a){d.writeAttribute("related_to","checkFormFeedback_"+a.id);$$("body")[0].insert({bottom:'<div class="errorFeedback" id="checkFormFeedback_'+a.id+'" style="display:none;"><span class="message">'+a.message+'</span><span class="appendice"></span></div>'});$("checkFormFeedback_"+a.id).writeAttribute("form_element",d.readAttribute("id"));var c=Math.round(a.position.top)-$("checkFormFeedback_"+a.id).measure("width")+a.offset.top;$("checkFormFeedback_"+a.id).setStyle({top:c+"px"});var b=Math.round(a.position.left)+a.offset.left;$("checkFormFeedback_"+a.id).setStyle({left:b+"px"});if(d.tagName=="INPUT"&&(d.readAttribute("type")=="checkbox"||d.readAttribute("type")=="radio")){d.ancestors()[0].select("label").each(function(e){Event.observe(e,"mouseover",function(){if(this.ancestors()[0].hasClassName("error")){new Effect.Opacity($("checkFormFeedback_"+a.id),{duration:0.3,from:0,to:1,beforeSetup:function(){$("checkFormFeedback_"+a.id).setOpacity(0);$("checkFormFeedback_"+a.id).setStyle({display:"block"})}})}});Event.observe(e,"mouseout",function(){if(this.ancestors()[0].hasClassName("error")){new Effect.Opacity($("checkFormFeedback_"+a.id),{duration:0.3,from:1,to:0,afterFinish:function(){$("checkFormFeedback_"+a.id).setStyle({display:"none"});$("checkFormFeedback_"+a.id).setOpacity(0)}})}})})}else{Event.observe(d,"focus",function(){if($(this).ancestors()[0].hasClassName("error")){new Effect.Opacity($("checkFormFeedback_"+a.id),{duration:0.3,from:0,to:1,beforeSetup:function(){$("checkFormFeedback_"+a.id).setOpacity(0);$("checkFormFeedback_"+a.id).setStyle({display:"block"})}})}});Event.observe(d,"blur",function(){if($(this).ancestors()[0].hasClassName("error")){new Effect.Opacity($("checkFormFeedback_"+a.id),{duration:0.3,from:1,to:0,afterFinish:function(){$("checkFormFeedback_"+a.id).setStyle({display:"none"});$("checkFormFeedback_"+a.id).setOpacity(0)}})}})}if(d.tagName=="INPUT"&&d.readAttribute("type")=="radio"){Event.observe($$('input[name="'+d.readAttribute("name")+'"]')[0],"change",function(){if($(this).ancestors()[0].hasClassName("error")){new Effect.Opacity($("checkFormFeedback_"+a.id),{duration:0.3,from:1,to:0,afterFinish:function(){$("checkFormFeedback_"+a.id).setStyle({display:"none"});$("checkFormFeedback_"+a.id).setOpacity(0);var e=$("checkFormFeedback_"+a.id).readAttribute("form_element");$(e).ancestors()[0].removeClassName("error")}})}})}else{Event.observe(d,"change",function(){if($(this).ancestors()[0].hasClassName("error")){new Effect.Opacity($("checkFormFeedback_"+a.id),{duration:0.3,from:1,to:0,afterFinish:function(){$("checkFormFeedback_"+a.id).setStyle({display:"none"});$("checkFormFeedback_"+a.id).setOpacity(0);var e=$("checkFormFeedback_"+a.id).readAttribute("form_element");$(e).ancestors()[0].removeClassName("error")}})}})}};

/*-----------  CORRECTIONS POSITION FIXED IE6  -----------*/
function toolbar_bottom_ie6fix_math(divName){
	var offset = $$('body')[0].cumulativeScrollOffset().top + document.viewport.getDimensions().height - $(divName).getDimensions().height;
	return offset;
}
function toolbar_bottom_ie6fix(divName){
	if($(divName)){
		Event.observe(window,'load',function(){
			var offset = toolbar_bottom_ie6fix_math(divName);
			$(divName).setStyle({'position':'absolute','top':offset+'px'});
		});
		Event.observe(window,'resize',function(){
			var offset = toolbar_bottom_ie6fix_math(divName);
			$(divName).setStyle({'position':'absolute','top':offset+'px'});
		});
		Event.observe(window,'scroll',function(){
			var offset = toolbar_bottom_ie6fix_math(divName);
			$(divName).setStyle({'position':'absolute','top':offset+'px'});
		});
	}
}
function toolbar_top_ie6fix_math(divName){
	var offset = $$('body')[0].cumulativeScrollOffset().top;
	return offset;
}
function toolbar_top_ie6fix(divName){
	if($(divName)){
		Event.observe(window,'load',function(){
			var offset = toolbar_top_ie6fix_math(divName);
			$(divName).setStyle({'position':'absolute','top':offset+'px'});
		});
		Event.observe(window,'resize',function(){
			var offset = toolbar_top_ie6fix_math(divName);
			$(divName).setStyle({'position':'absolute','top':offset+'px'});
		});
		Event.observe(window,'scroll',function(){
			var offset = toolbar_top_ie6fix_math(divName);
			$(divName).setStyle({'position':'absolute','top':offset+'px'});
		});
	}
}

/*-----------  CAROUSEL  -----------*/
function diaporamaTrigger(b,a,g){var c=parseInt($("diapo").readAttribute("length"));var e=parseInt($("diapo").readAttribute("current_id"))+b;$("diapo").writeAttribute("current_id",e);if(b==1){if(e>=c){$("diapo").writeAttribute("current_id",0);e=0;var d=$$("#diapo li")[c-1]}else{var d=$$("#diapo li")[e-1]}}else{if(b==-1){if(e<0){$("diapo").writeAttribute("current_id",c-1);e=c-1;var d=$$("#diapo li")[0]}else{var d=$$("#diapo li")[e+1]}}}var f=$$("#diapo li")[e];new Effect.Opacity(d,{from:1,to:0,duration:g,afterFinish:function(){d.setStyle({display:"none"})}});new Effect.Opacity(f,{from:0,to:1,duration:g,afterSetup:function(){f.setStyle({display:"block"})}})}function diaporama_generator(b,e,d,c,a){$("diapo").writeAttribute("current_id",0);$("diapo").writeAttribute("length",$$("#diapo li").length);$$("#diapo .buttonLeft").each(function(f){Event.observe(f,"click",function(){if(!$("diapo").hasClassName("manual")){$("diapo").addClassName("manual")}diaporamaTrigger(-1,b,e)})});$$("#diapo .buttonRight").each(function(f){Event.observe(f,"click",function(){if(!$("diapo").hasClassName("manual")){$("diapo").addClassName("manual")}diaporamaTrigger(1,b,e)})});if(d){new PeriodicalExecuter(function(f){if($("diapo").hasClassName("manual")){$("diapo").removeClassName("manual")}},a);new PeriodicalExecuter(function(f){if(!$("diapo").hasClassName("manual")){diaporamaTrigger(1,b,e)}},c)}};

/*-----------  SCROLL  -----------*/
function reachScroll(target){
	var offset = target.cumulativeOffset().top - 126;
	window.scrollTo(0, offset);
	if(typeof(tactile) != 'undefined' && tactile){
		setTimeout(function(){
			toolbar_top_ie6fix('header');
			toolbar_bottom_ie6fix('toolbar');
		}, 100);
	}
}

/*-----------  LOAD PAGE  -----------*/
function loadNews(trigger, section){
	if($(section).writeAttribute('status') != 'loading'){
		$(section).writeAttribute('status', 'loading');
		var url = $(trigger).readAttribute('href');
		var target = $(trigger).ancestors()[0].previous();
		//reachScroll($(trigger).ancestors()[2]);
		Effect.ScrollTo($(trigger).ancestors()[2], {
			duration: 0.4,
			offset: -126,
			afterFinish: function(){
				new Effect.Opacity($(trigger).ancestors()[0].previous(), {
					from: 1,
					to: 0.5,
					duration: 0.5,
					beforeSetup: function(){
						target.addClassName('loading');
					},
					afterFinish: function(){
						new Ajax.Updater(target, url, {
							parameters: 'mode=ajax',
							insertion: 'after',
							evalScripts: true,
							onComplete: function(){
								$(trigger).setStyle({'display':'none'});
								$(trigger).next().setStyle({'display':'inline'});
								target.setStyle({'display':'none'});
							}
						});
					}
				});
			}
		});
	}
	return false;
}
function closeNews(trigger){
	//reachScroll($(trigger).ancestors()[2]);
	Effect.ScrollTo($(trigger).ancestors()[2], {
		duration: 0.4,
		offset: -126,
		afterFinish: function(){
			$(trigger).setStyle({'display':'none'});
			$(trigger).previous().setStyle({'display':'inline'});
			$(trigger).ancestors()[0].previous().previous().removeClassName('loading');
			$(trigger).ancestors()[0].previous().previous().setOpacity(1);
			$(trigger).ancestors()[0].previous().previous().setStyle({'display':'block'});
			$(trigger).ancestors()[0].previous().remove();
		}
	});
	return false;
}

/*-----------  LOAD PAGE  -----------*/
function loadPage(trigger, name, title){
	if($$('body')[0].readAttribute('status') != 'running'){
		$$('#mainMenu ul li').each(function(el){
			el.removeClassName('active');
		});
		$(trigger).ancestors()[0].addClassName('active');
		_gaq.push(['_trackPageview', '/' + name]);
		if(title){
			document.title=(title);
		}
		if(!$(name)){
			var url = $(trigger).readAttribute('href');
			$$('body')[0].writeAttribute('status', 'running');
			Effect.ScrollTo('community', {
				duration: 1,
				afterFinish: function(){
					new Ajax.Updater('content', url, {
						parameters: 'mode=ajax',
						insertion: 'bottom',
						evalScripts: true,
						onComplete: function(){
							$('currentLoader').remove();
							setTimeout(function(){
								reachScroll($(name));
							}, 100);
							$$('body')[0].writeAttribute('status', 'ok');
						}
					});
				}
			});
			$('content').insert({
				bottom: '<div class="loader" id="currentLoader"></div>'
			});
		}
		else{
			Effect.ScrollTo(name, {
				duration: 1,
				offset: -126,
				beforeSetup: function(){
					$$('body')[0].writeAttribute('status', 'running');
				},
				afterFinish: function(){
					$$('body')[0].writeAttribute('status', 'ok');
				}
			});
		}
	}
	return false;
}

/*-----------  OPEN MEDIA  -----------*/
function findMediaPlace(element){
	if(element && !element.hasClassName('last')){
		if(element.next()){
			return findMediaPlace(element.next());
		}
		else{
				return element;
		}
	}
	else{
		return element;
	}
}
function openMedia(trigger, file){
	if($$('body')[0].readAttribute('status') != 'running'){
		$$('#media .list li.special').each(function(el){
			el.remove();
		});
		var url = $(trigger).readAttribute('href');
		var li = $(trigger).ancestors()[0];
		$$('body')[0].writeAttribute('status', 'running');
		var liLast = findMediaPlace(li);
		liLast.insert({
			after: '<li class="special" id="gallerySpecialItem"></li>'
		});
		Effect.ScrollTo('gallerySpecialItem', {
			duration: 0.5,
			offset: -126,
			afterFinish: function(){
				new Effect.Morph('gallerySpecialItem', {
					style: 'height:680px;margin-bottom:10px;',
					duration: 0.5,
					afterFinish: function(){
						new Ajax.Updater('gallerySpecialItem', url, {
							parameters: 'mode=ajax&file=' + file,
							evalScripts: true,
							onComplete: function(){
								$$('body')[0].writeAttribute('status', 'ok');
							}
						});
					}
				});
			}
		});
	}
	return false;
}
function closeMedia(trigger){
	var li = $(trigger).ancestors()[0];
	Effect.SlideUp(li, {
		duration: 0.5,
		afterFinish: function(){
			li.remove();
		}
	})
	return false;
}


function fb_share(app_name, app_link, app_picture, app_caption, app_description, app_message){
	 FB.init({
		//appId  : '195018290522708',
		//appId  : '178157128912832',
		appId  : '151044964971967',
		status : true, // check login status
		cookie : true, // enable cookies to allow the server to access the session
		xfbml  : true  // parse XFBML
	});
	FB.ui(
	   {
		 method: 'feed',
		 name: app_name,
		 link: app_link,
		 picture: app_picture,
		 caption: app_caption,
		 description: app_description,
		 message: app_message
	   },
	   function(response) {
		 if (response && response.post_id) {
		   // alert(\'Post was published.\');
		 } else {
		   // alert(\'Post was not published.\');
		 }
	   }
	 );
	return false;
};
