var global_chemin_url = "http://www.ain-tourisme.com/";
var global_chemin_url_images = "http://www.ain-tourisme.com/";

// ******************************** Pour la gestion des infos bulles ******************************** //
if ((navigator.appName == "Netscape")&&(navigator.appVersion.substring(0,4)>=4))
	{isNav="net";}
if (navigator.appName == "Microsoft Internet Explorer")
	{isNav="ie";}
function popLayer(a,b)
{
	var desc = "";
	couleur_fond = "";

	desc += "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" bgcolor=\""+couleur_fond+"\"><tr><td align=\"center\"><a id=\"texte\">";
	desc += a;
	desc += "</a></td></tr></table>";
	if (isNav=="net")
	{
		var NS6_tmp = (!document.all && document.getElementById) ? 1 : 0;
		if (NS6_tmp)
		{
			document.captureEvents(Event.MOUSEMOVE);
			document.onmousemove = handlerMM;
			document.getElementById('alt_txt').innerHTML = desc;
			var taille_layer = document.getElementById('alt').offsetWidth;
			document.getElementById('alt').style.top=y+20;
			document.getElementById('alt').style.left=x+25;
			if ((document.body.clientWidth+document.body.scrollLeft)<(document.getElementById('alt').offsetLeft+taille_layer))
			{
				document.getElementById('alt').style.left=document.body.clientWidth+document.body.scrollLeft-taille_layer;
			}
			document.getElementById('alt').style.visibility = "visible";
		}
		else
		{
			document.captureEvents(Event.MOUSEMOVE);
			document.onmousemove = handlerMM;
			document.alt_txt.document.write(desc);
			document.alt.document.close();
			document.alt.left=x-5;
			document.alt.top=y-25;
			document.alt.visibility = "show";
		}
	}
	else if (isNav=="ie")
	{
		handlerMM();
		alt_txt.innerHTML=desc;
		var taille_layer = alt.offsetWidth;
		alt.style.pixelLeft=x-5;
		alt.style.pixelTop=y-20;
		if ((document.body.clientWidth+document.body.scrollLeft)<(alt.offsetLeft+taille_layer))
		{
			alt.style.pixelLeft=document.body.clientWidth+document.body.scrollLeft-taille_layer;
		}


		alt.style.visibility = "visible";
	}
}
function hideLayer(a)
{
	var NS6_tmp = (!document.all && document.getElementById) ? 1 : 0;
	if (isNav=="net")
	{
		if (NS6_tmp)
		{
			document.getElementById('alt').style.visibility = "hidden";document.getElementById('alt').style.left=0;document.getElementById('alt').style.top=0;
		}
		else
		{
			document.layers['alt'].visibility = "hide";document.alt.left=0;document.alt.top=0;
		}
	}
	if (isNav=="ie")
	{
		alt.style.visibility = "hidden";alt.style.pixelLeft=0;alt.style.pixelTop=0;
	}
}
function handlerMM(e)
{
	if (isNav=="net")
	{
		x = e.pageX+25;
		y = e.pageY+25;
	}
	if (isNav=="ie")
	{
		x = event.x+document.documentElement.scrollLeft+25;
		y = event.y+document.documentElement.scrollTop+25;
	}
}
if (isNav=="net")
{
	document.captureEvents(Event.MOUSEMOVE);
	document.onmousemove = handlerMM;
}

// ****************************** Fin pour la gestion des infos bulles ****************************** //



	function dcd_m(val)
	{
		var l_val = val.length;
		var code = "";
		var result = "";

		for(i=0; i<l_val; i+=3)
		{
			code = val.substr(i, 3)-3;
			result += String.fromCharCode(code);
		}

		return result;
	}


// ******************************** Pour la gestion des flash ******************************** //


// Variables globales
// Version majeure de Flash requise
var requiredMajorVersion = 9;
// Version mineure de Flash requise
var requiredMinorVersion = 0;
// Révision de Flash requise
var requiredRevision = 0;
// Version de javascript prise en charge
var jsVersion = 1.0;

var msg_deja_affiche = false;

var isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
var isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;
var isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false;

function EvalJs(html){
	$(".script",html).each(function(ind,obj){
		eval($(this).text());
	});
}

function aff_bal(ch)
{
	document.write(ch);
}

function insert_flash(p_src,p_name,p_width,p_height,p_id,p_class,wmode) {

	if (!wmode) wmode = '';

	if (p_src.indexOf(".flv")>=0){
		var hasRightVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);
		if(hasRightVersion) {  // if we've detected an acceptable version
			// embed the flash movie

			AC_FL_RunContent(
				'codebase', 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,45,0',
				'width', p_width,
				'height', p_height,
				'src', 'PlayerVideo',
				'quality', 'high',
				'pluginspage', 'http://www.macromedia.com/go/getflashplayer',
				'align', 'middle',
				'play', 'false',
				'loop', 'false',
				'scale', 'showall',
				'wmode', 'window',
				'devicefont', 'false',
				'id', 'PlayerVideo',
				'bgcolor', '#ffffff',
				'name', 'PlayerVideo',
				'menu', 'true',
				'allowScriptAccess','sameDomain',
				'allowFullScreen','true',
				'movie', 'PlayerVideo',
				'salign', '',
				'flashvars', 'nomflv='+p_src
				); //end AC code
		}
		else{
			// flash is too old or we can't detect the plugin
			var alternateContent = 'Alternate HTML content should be placed here.'
				+ 'This content requires the Adobe Flash Player.'
				+ '<a href=http://www.macromedia.com/go/getflash/>Get Flash</a>';
			document.write(alternateContent);  // insert non-flash content
		}
	}
	else{
		var hasRightVersion = DetectFlashVer2(requiredMajorVersion, requiredMinorVersion, requiredRevision);
		if(!hasRightVersion) {  // si nous avons détecté une version acceptable
			if (!msg_deja_affiche)
			{
				msg_deja_affiche = true;

				var alternateContent = 'Pour visualiser correctement cette page vous avez besoin du Flash&nbsp;Player&nbsp;'+requiredMajorVersion+'.'
				+ '<br /><a href="http://www.macromedia.com/go/getflash/" class="text-normal-lien" target="_blank">T&eacute;l&eacute;charger Flash&nbsp;Player</a><br />';
				document.write(alternateContent);  // Insérer contenu non-Flash
			}
		}
		if (p_src.match(new RegExp('Main.swf', 'gi'))) {
			var flashvars = 'dataPath=/lib/carto3d/loresdata&cameraRecordingSpeed=100&cameraRecording=';
		}
		else {
			var flashvars = '';
		}
		//document.write('<embed src="' + p_src + '" name="' + p_name + '" id="' + p_id + '" width="' + p_width + '" height="' + p_height + '" wmode="transparent" quality="high"  align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
		var display_embed = true;
		if ($.browser.msie) {
			var class_ie = 'id="'+p_id+'" class="'+p_class+'"';
		}
		else {
			var class_ie = 'class="'+p_class+'"';
		}
		if ($.browser.safari) {
			display_embed = false;
		}
		var ch = '<object '+class_ie+' name="'+p_name+'" width="'+p_width+'" height="'+p_height+'" align="middle" type="application/x-shockwave-flash" data="'+p_src+'">'+
	   	 		 '<param name="movie" value="'+p_src+'" />'+
				 '<param name="quality" value="high" />'+
	         	 '<param name="bgcolor" value="#ffffff" />'+
	         	 '<param name="allowscriptaccess" value="sameDomain" />'+
	         	 '<param name="allowfullscreen" value="true" />'+
	         	 '<param name="wmode" value="'+wmode+'" />'+
	         	 '<param name="flashvars" value="'+flashvars+'" />'+
	         	 '<param name="autostart" value="true" />'+
	         	 '<param name="loop" value="true" />'+
	         	 '<param name="volume" value="0" />'+
	         	 '<param name="controls" value="smallconsole" />';
		if (display_embed) {
			ch+= '<embed src="'+p_src+'" name="'+p_name+'" width="'+p_width+'" height="'+p_height+'" flashvars="'+flashvars+'" allowscriptaccess="sameDomain" allowfullscreen="true" wmode="'+wmode+'" autostart="true" loop="true" volume="0" controls="smallconsole" />';
		}
        ch+= '</object>';
        document.write(ch);
	}
}


// Programme d'assistance JavaScript requis pour détecter les informations de version du plug-in Flash Player
function JSGetSwfVer2(i){
	// Version NS/Opera >= 3 rechercher le plug-in Flash dans le tableau des plug-ins
	if (navigator.plugins != null && navigator.plugins.length > 0) {
		if (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]) {
			var swVer2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
      		var flashDescription = navigator.plugins["Shockwave Flash" + swVer2].description;
			descArray = flashDescription.split(" ");
			tempArrayMajor = descArray[2].split(".");
			versionMajor = tempArrayMajor[0];
			versionMinor = tempArrayMajor[1];
			if ( descArray[3] != "" ) {
				tempArrayMinor = descArray[3].split("r");
			} else {
				tempArrayMinor = descArray[4].split("r");
			}
      		versionRevision = tempArrayMinor[1] > 0 ? tempArrayMinor[1] : 0;
            flashVer = versionMajor + "." + versionMinor + "." + versionRevision;
      	} else {
			flashVer = -1;
		}
	}
	// MSN/WebTV 2.6 prend en charge Flash 4
	else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.6") != -1) flashVer = 4;
	// WebTV 2.5 prend en charge Flash 3
	else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.5") != -1) flashVer = 3;
	// La version antérieure de WebTV prend Flash 2 en charge
	else if (navigator.userAgent.toLowerCase().indexOf("webtv") != -1) flashVer = 2;
	// Détection impossible dans tous les autres cas
	else {

		flashVer = -1;
	}
	return flashVer;
}
// Si elle est appelée sans paramètres,
// cette fonction renvoie une valeur en virgule flottante indiquant la version Flash Player ou 0.0
// ex : Flash Player 7r14 renvoie 7.14
// Si appelé avec reqMajorVer, reqMinorVer, reqRevision renvoie true si cette version ou une version ultérieure est disponible
function DetectFlashVer2(reqMajorVer, reqMinorVer, reqRevision)
{
 	reqVer = parseFloat(reqMajorVer + "." + reqRevision);
   	// Examiner les versions pour détecter la plus récente
	for (i=25;i>0;i--) {
		if (isIE && isWin && !isOpera) {
			versionStr = VBGetSwfVer(i);
		} else {
			versionStr = JSGetSwfVer2(i);
		}
		if (versionStr == -1 ) {
			return false;
		} else if (versionStr != 0) {
			if(isIE && isWin && !isOpera) {
				tempArray         = versionStr.split(" ");
				tempString        = tempArray[1];
				versionArray      = tempString .split(",");
			} else {
				versionArray      = versionStr.split(".");
			}
			versionMajor      = versionArray[0];
			versionMinor      = versionArray[1];
			versionRevision   = versionArray[2];

			versionString     = versionMajor + "." + versionRevision;   // 7.0r24 == 7.24
			versionNum        = parseFloat(versionString);
        	// est la révision.principale >= révision.principale demandée ET la version mineure >= mineure demandée
        	if ( (versionMajor > reqMajorVer) && (versionNum >= reqVer) ) {
				return true;
			} else {
				return ((versionNum >= reqVer && versionMinor >= reqMinorVer) ? true : false );
			}
		}
	}
	return (reqVer ? false : 0.0);
}



// ****************************** Fin pour la gestion des flash ****************************** //



// ******************************* Pour la gestion des formulaires ****************************//

function valider_moteur_recherche(){
	var f = document.form_moteur_recherche;
	var mot_recherche = f.query.value;
	wysistat_tag_mot_cle_moteur(mot_recherche);
	return true;
}

function valider_moteur_recherche_2(){
	var f = document.form_moteur_recherche_2;
	var mot_recherche = f.query.value;
	wysistat_tag_mot_cle_moteur(mot_recherche);
	return true;
}

function wysistat_tag_mot_cle_moteur(mot_recherche) {
	if (valeur==1){stat('cdt01','','','recherche;'+mot_recherche);}
}

// ***************************** Fin pour la gestion des formulaires **************************//


// ajouter aux favoris
function add_to_favoris(){
	var titre = "Andra, agence nationale pour la gestion des déchets radioactifs";
	var url = document.location.href;
	if(navigator.appName != 'Microsoft Internet Explorer' ){
		window.sidebar.addPanel(titre,url,"");
	}
	else{
		window.external.AddFavorite(url,titre);
	}
}


function now(){
	return +new Date;
}

function chargeCss(nom){
 	var headID = document.getElementsByTagName("head")[0];
	var newCss = document.createElement('link');
	newCss.type = 'text/css';
	newCss.href = nom+'?'+now();
	newCss.media = 'screen';
	newCss.rel = 'stylesheet';
	headID.appendChild(newCss);
}

function ouvreFermeCarto(){
	var mon_div = $('#search');
	if (mon_div.hasClass('hide')){
		mon_div.removeClass('hide');
	}
	else{
		mon_div.addClass('hide');
	}
}

function redirection_flash(url) {
	if (url) {
    	window.open(url);
    }
    else{
    	display_carto_3d();
    }
}

function CalculWidthEcran(){
	var width_ecran;

	if(self.innerWidth!=undefined){
		width_ecran = self.innerWidth;
		width_ecran = width_ecran-20;
	}
	else{
		if(document.documentElement) {
			width_ecran = document.documentElement.clientWidth;
		}
	}
	if (width_ecran>1254){
		width_ecran = 1254;
	}
	if (width_ecran<980){
		width_ecran = 980;
	}
	return width_ecran;
}


function changerTailleEcran(){
	var width_ecran = CalculWidthEcran();
	var marge = (1254-width_ecran)/2;

	$('#workspace_total').css('width',width_ecran);
	$('#backgroundspace').css('margin-left','-'+marge+'px');
	$('#backgroundspace').css('width',width_ecran+marge);
}


function changerFondImage(){
	var width_ecran = CalculWidthEcran();
	$('#slideshow').cycle({
        timeout: 3000,
		speed:5000,
        pager:'#nav'
    });

	$('.lecture_pause').click(function(){
		if ($('.playpauseButton a').hasClass('pause')){
			$('.playpauseButton a').removeClass('pause');
			$('.lecture_pause').text('Lecture');
			$('#slideshow').cycle('pause');
		}
		else{
			$('.playpauseButton a').addClass('pause');
			$('.lecture_pause').text('Pause');
			$('#slideshow').cycle('resume');
		}
	});

	$('#nav a').click(function(){
		$('.playpauseButton a').removeClass('pause');
		$('.lecture_pause').text('Lecture');
		$('#slideshow').cycle('pause');
	});

}



function findWidgetParent(child) {
	var parent = child;
	do {
		parent = $(parent).parent();
	}
	while(parent && !($(parent).get(0).className.match(new RegExp('widget_drag', 'gi'))));

	return parent;
}

function give_widget_id_with_link(widget_link) {
	var findme = 'widget_id_';
    var myRegExp = new RegExp(findme+'([^ ]+)', 'gi');

	//var widget_link_id = $(widget_link).attr('class').match(new RegExp('widget_id_([^ ])', 'gi'));
    var widget_id = $(widget_link).attr('class').match(myRegExp);
    widget_id = (''+widget_id).replace(new RegExp(findme, 'gi'), '');

    return widget_id;
}

function get_widget_carnet_content(){
	var ajax_file = 'http://www.ain-tourisme.com/module/carto/proxy.php';
	var post_data = {
        action:'getCarnetList'
	};
	$.post(ajax_file,post_data, function(widget_content){
		$(".widget_carnet_content_ajout").html("<p>"+widget_content+"</p>");
		$(".to_carnet_list_link").get(0).href = "/module/carto/index.php?display=carnet";
		$(".to_carnet_list_img").get(0).href = "/module/carto/index.php?display=carnet";
	});
}

function initWidgetPosition(){

	//var ajax_file = 'module/widget/ajax.php?id=widget_1_1&act=initWidgetPosition';
	var ajax_file = 'http://www.ain-tourisme.com/module/widget/ajax.php?id=widget_1_1&act=initPosition';
	var post_data = {};
	var widget_name = '';
	var widget_left = '';
	var widget_top = '';
	var widget_stat = '';
	$.getJSON(ajax_file, post_data, function(json){
		if(json.total>0){

			for(i=0;i<json.total;i++){
				widget_name = json.results[i].widget_name;
				widget_stat = json.results[i].state;

				if(widget_stat == 1){
					$("#"+widget_name).show();

					if(widget_name == 'carnet'){
						get_widget_carnet_content();
					}
				}
				else{
					$("#"+widget_name).hide();
				}

				if(json.iscookie){
					if(json.results[i].coord_x){
						widget_left = json.results[i].coord_x;
						$("#"+widget_name).css('left',widget_left);
					}
					if(json.results[i].coord_y){
						widget_top = json.results[i].coord_y;
						$("#"+widget_name).css('top',widget_top);
					}
				}
			}
		}
	});
}


//requete ajax pour mémoriser la position
function savePosition(widget_name,position_x,position_y,widget_state){
	//var ajax_file = 'index.php?id=widget_1_1&act=updatePosition';
	var ajax_file = 'http://www.ain-tourisme.com/module/widget/ajax.php?id=widget_1_1&act=updatePosition';
	var post_data = {
                widget_name:widget_name,
                widget_coord_x:position_x,
                widget_coord_y:position_y,
                widget_state:widget_state
			};
	$.post(ajax_file,post_data);
}




function update_form_sondage_action() {
	// submit du form en ajax
	$('.form_sondage').submit(function() {
		var _this = this;
		var data = $(this).serialize()+'&ajax=1';
		$.ajax({
			'type': $(this).attr('method'),
			'url': $(this).attr('action'),
			'dataType': 'html',
			'data': data,
			'success' : function(data) {
				$(_this).parent().html($('.divcontent', $(data)).html());
				update_form_sondage_action();
			}
		});
		return false;
	});
}
function update_form_sondage(){

	if ($('.form_sondage').length) {
		$.ajax({
			'type': $('.form_sondage:eq(0)').attr('method'),
			'url': $('.form_sondage:eq(0)').attr('action'),
			'dataType': 'html',
			'data': {'ajax' : 1},
			'success' : function(data) {
				var c = $('.divcontent', $(data)).html();
				if (!c.match(new RegExp('.form_sondage','gi'))) {
					$('.widget_avis_content:eq(0)').html(c);
					update_form_sondage_action();
				}
			}
		});
	}
}


function update_form_meteo_action() {
	// submit du form en ajax
	$('.form_meteo').submit(function() {
		var _this = this;
		var data = $(this).serialize()+'&ajax=1';
		$.ajax({
			'type': $(this).attr('method'),
			'url': $(this).attr('action'),
			'dataType': 'html',
			'data': data,
			'success' : function(data) {
				$('.meteo_workspace').html($('.meteo_workspace:last', $(data)).html());
				update_form_meteo_action();
			}
		});
		return false;
	});
}
function update_form_meteo(){

	if ($('.form_meteo').length) {
		$.ajax({
			'type': $('.form_meteo:eq(0)').attr('method'),
			'url': $('.form_meteo:eq(0)').attr('action'),
			'dataType': 'html',
			'data': {'ajax' : 1},
			'success' : function(data) {
				var c = $('.meteo_workspace:last', $(data)).html();
				$('.meteo_workspace:eq(0)').html(c);
				update_form_meteo_action();
			}
		});
	}
}



var run_agenda = -1;

function update_form_agenda_action() {
	// submit du form en ajax
	$('.form_agenda').submit(function() {
		var _this = this;
		var data = $(this).serialize()+'&ajax=1';
		$.ajax({
			'type': $(this).attr('method'),
			'url': $(this).attr('action'),
			'dataType': 'html',
			'data': data,
			'success' : function(data) {
				$('.agenda_workspace').html($('.agenda_workspace:last', $(data)).html());
				initAgenda();
				update_form_agenda_action();
			}
		});
		return false;
	});
}
function update_form_agenda(){

	if ($('.form_agenda').length) {
		$.ajax({
			'type': $('.form_agenda:eq(0)').attr('method'),
			'url': $('.form_agenda:eq(0)').attr('action'),
			'dataType': 'html',
			'data': {'ajax' : 1},
			'success' : function(data) {
				var c = $('.agenda_workspace:last', $(data)).html();
				$('.agenda_workspace:eq(0)').html(c);
				initAgenda();
				update_form_agenda_action();
			}
		});
	}
}

function affiche_param_agenda(){
	var mon_div = document.getElementById('param_agenda');
	mon_div.style.display='block';
}


function initAgenda(){
	//Speed of the slideshow
	var speed_agenda = 6000;
	var width = 195;
	var height = 100;


	$('#mask-gallery-agenda, #gallery-agenda li').width(width-10).height(height);
	$('#gallery-agenda').width((width) * ($('#gallery-agenda li').length+1));

	clearInterval(run_agenda);
	run_agenda = setInterval(function(){newsscoller_agenda(0)}, speed_agenda);

	$('#gallery-agenda li:first').addClass('selected');

	$('#btn-next-agenda').click(function () {
		newsscoller_agenda(0);
		return false;
	});
	$('#btn-prev-agenda').click(function () {
		newsscoller_agenda(1);
		return false;
	});
	$('#slider-agenda').hover(
		function() {
			clearInterval(run_agenda);
		},
		function() {
			run_agenda = setInterval(function(){newsscoller_agenda(0)}, speed_agenda);
		}
	);
}

function newsscoller_agenda(prev) {
	var current_image = $('#gallery-agenda li.selected').length ? $('#gallery-agenda li.selected') : $('#gallery-agenda li:first');

	if (prev) {
		var next_image = (current_image.prev().length) ? current_image.prev() : $('#gallery-agenda li:last');
	}
	else {
		var next_image = (current_image.next().length) ? current_image.next() : $('#gallery-agenda li:first');
	}
	$('#gallery-agenda li, #control-agenda a').removeClass('selected');
	next_image.addClass('selected');
	$('#mask-gallery-agenda').scrollTo(next_image, 800);
}



var comment_run = -1;


function update_form_commentaire(){
	if ($('.commentaire_workspace').length) {
		$.ajax({
			'type': 'GET',
			'url': 'http://www.ain-tourisme.com/module/commentaire/ajax_widget.php',
			'dataType': 'html',
			'data': {'ajax' : 1},
			'success' : function(data) {
				$('.commentaire_workspace').html(data);
				initCommentaire();
			}
		});
	}

}

function initCommentaire(){
	//Speed of the slideshow
	var comment_speed = 6000;
	var width = 220;
	var height = 170;

	$('#comment-mask-gallery, #comment-gallery li').width(width-10).height(height);
	$('#comment-gallery').width((width) * ($('#comment-gallery li').length+1));

	clearInterval(comment_run);
	comment_run = setInterval(function(){commentaire_newsscoller(0)}, comment_speed);

	$('#comment-gallery li:first, #control a:first').addClass('selected');

	$('#comment-btn-next').click(function () {
		commentaire_newsscoller(0);
		return false;
	});

	$('#comment-btn-prev').click(function () {
		commentaire_newsscoller(1);
		return false;
	});

	$('#comment-slider').hover(
		function() {
			clearInterval(comment_run);
		},
		function() {
			comment_run = setInterval(function(){commentaire_newsscoller(0)}, comment_speed);
		}
	);
}


function commentaire_newsscoller(prev) {

	var current_image = $('#comment-gallery li.selected').length ? $('#comment-gallery li.selected') : $('#comment-gallery li:first');

	if (prev) {
		var next_image = (current_image.prev().length) ? current_image.prev() : $('#comment-gallery li:last');
	}
	else {
		var next_image = (current_image.next().length) ? current_image.next() : $('#comment-gallery li:first');
	}

	$('#comment-gallery li').removeClass('selected');
	next_image.addClass('selected');
	$('#comment-mask-gallery').scrollTo(next_image, 800);
}


tagcloud_timer = -1;
function tagcloud_show() {
	tagcloud_stop_hide_tempo();
	$('#tagcloud').show();
	$('.search_engine_bck').css('background', 'url(http://www.ain-tourisme.com/download/site-principal/image/charte/ete/recherche/fond-moteur-over.png) no-repeat');
}
function tagcloud_hide_with_tempo() {
	tagcloud_stop_hide_tempo();
	// close layer in x s
	tagcloud_timer = setTimeout('tagcloud_hide()', 1000);
}
function tagcloud_hide() {
	$('#tagcloud').hide();
	$('.search_engine_bck').css('background', 'url(http://www.ain-tourisme.com/download/site-principal/image/charte/ete/recherche/fond-moteur.png) no-repeat');
	tagcloud_timer = -1;
}
function tagcloud_stop_hide_tempo() {
	//if (tagcloud_timer>=0)
	clearTimeout(tagcloud_timer);
}


function getFlashMovie() {
	var obj = $('.carto3d');
	return obj;
}
function addLabel(x,y,label,color,url,icon,pole_phare) {
	var flashMovie = getFlashMovie();
	$(flashMovie).each(function(){
		if (pole_phare) {
			if (!($(this).attr('class').match('carto3d_display_pole_phare'))) {
				return;
			}
		}
		this.addLabel(x,y,label,color,url,icon);
	});
}
function clearLabels() {
	var flashMovie = getFlashMovie();
	$(flashMovie).each(function(){
		this.clearLabels();
	});
}
function lookAt(x,y,z,distance) {
	var flashMovie = getFlashMovie();
	$(flashMovie).each(function(){
		this.lookAt(x,y,z,distance);
	});
}
var global_json_data = {};
function survoler_init_data(json_data) {
	//$.extend(global_json_data, json_data);
	global_json_data = json_data;
}
function initMap() {
	var flashMovie = getFlashMovie();
	if (!$(flashMovie).length) {
		return false;
	}
	clearLabels();
			lookAt('337.314423324', '371.120822944', null, 50);
		addLabel('431.535676555', '617.894915527', '<font face="arial">AMBERIEU EN BUGEY</font>', '0xffffff', '', '', 0);
addLabel('149.780134062', '266.788658214', '<font face="arial">BAGE LA VILLE</font>', '0xffffff', '', '', 0);
addLabel('739.944275423', '457.021350089', '<font face="arial">BELLEGARDE SUR VALSERINE</font>', '0xffffff', '', '', 0);
addLabel('595.516478826', '496.20548028', '<font face="arial">BRENOD</font>', '0xffffff', '', '', 0);
addLabel('401.076370086', '405.50721498', '<font face="arial">CEYZERIAT</font>', '0xffffff', '', '', 0);
addLabel('306.07926166', '573.369122172', '<font face="arial">CHALAMONT</font>', '0xffffff', '', '', 0);
addLabel('658.4986075', '657.81677666', '<font face="arial">CHAMPAGNE EN VALROMEY</font>', '0xffffff', '', '', 0);
addLabel('415.42285647', '191.37804295', '<font face="arial">COLIGNY</font>', '0xffffff', '', '', 0);
addLabel('794.539559186', '421.659771141', '<font face="arial">COLLONGES</font>', '0xffffff', '', '', 0);
addLabel('934.756915909', '299.935169093', '<font face="arial">FERNEY VOLTAIRE</font>', '0xffffff', '', '', 0);
addLabel('897.38406982', '219.579892741', '<font face="arial">GEX</font>', '0xffffff', '', '', 0);
addLabel('555.90774611', '349.995086881', '<font face="arial">IZERNORE</font>', '0xffffff', '', '', 0);
addLabel('433.394867141', '667.108904759', '<font face="arial">LAGNIEU</font>', '0xffffff', '', '', 0);
addLabel('563.122667657', '809.748292557', '<font face="arial">LHUIS</font>', '0xffffff', '', '', 0);
addLabel('332.085866441', '670.973414835', '<font face="arial">MEXIMIEUX</font>', '0xffffff', '', '', 0);
addLabel('131.556754893', '743.744881958', '<font face="arial">LE MAS RILLIER</font>', '0xffffff', '', '', 0);
addLabel('232.444390848', '723.862255129', '<font face="arial">MONTLUEL</font>', '0xffffff', '', '', 0);
addLabel('272.099784178', '246.066952262', '<font face="arial">MONTREVEL EN BRESSE</font>', '0xffffff', '', '', 0);
addLabel('322.073577452', '392.07644367', '<font face="arial">PERONNAS</font>', '0xffffff', '', '', 0);
addLabel('460.233105219', '485.331330438', '<font face="arial">PONCIN</font>', '0xffffff', '', '', 0);
addLabel('416.591661885', '519.905386043', '<font face="arial">PONT D\'AIN</font>', '0xffffff', '', '', 0);
addLabel('106.66035746', '317.509680234', '<font face="arial">PONT DE VEYLE</font>', '0xffffff', '', '', 0);
addLabel('72.1334490485', '647.138650969', '<font face="arial">REYRIEUX</font>', '0xffffff', '', '', 0);
addLabel('487.763766129', '615.66499823', '<font face="arial">SAINT RAMBERT EN BUGEY</font>', '0xffffff', '', '', 0);
addLabel('234.073927928', '116.019167883', '<font face="arial">SAINT TRIVIER DE COURTES</font>', '0xffffff', '', '', 0);
addLabel('124.172834783', '514.032476881', '<font face="arial">SAINT TRIVIER SUR MOIGNANS</font>', '0xffffff', '', '', 0);
addLabel('226.587334495', '1561.88904436', '<font face="arial">SEYSSEL</font>', '0xffffff', '', '', 0);
addLabel('53.7845380345', '417.779468426', '<font face="arial">THOISSEY</font>', '0xffffff', '', '', 0);
addLabel('441.495846767', '288.92577101', '<font face="arial">PRESSIAT</font>', '0xffffff', '', '', 0);
addLabel('204.946297129', '576.986556288', '<font face="arial">VILLARS LES DOMBES</font>', '0xffffff', '', '', 0);
addLabel('330.903085149', '326.036551054', '<font face="arial">VIRIAT</font>', '0xffffff', '', '', 0);
addLabel('638.033985971', '707.996331773', '<font face="arial">VIRIEU LE GRAND</font>', '0xffffff', '', '', 0);
addLabel('894.568117092', '318.668724286', '<font face="arial">CERN<br><font size="-6">Saint-Genis-Pouilly</font></font>', '0xff9900', '/module/carto/index.php?offre=sitraPCU479988', '/download/site-principal/image/vignette_carto3D/CERN-vignette.jpg', 1);
addLabel('44.8311466697', '641.021222315', '<font face="arial">Cité de Trévoux<br><font size="-6">Trévoux</font></font>', '0xff9900', '/module/carto/index.php?offre=sitraPCU345909', '/download/site-principal/image/vignette_carto3D/Ville_Trevoux-vignette.jpg', 1);
addLabel('318.074853702', '668.586653349', '<font face="arial">Cité médiévale de Pérouges<br><font size="-6">Pérouges</font></font>', '0xff9900', '/module/carto/index.php?offre=sitraPCU138549', '/download/site-principal/image/vignette_carto3D/Cite_medievale_Perouges-vignette.jpg', 1);
addLabel('160.663433792', '460.821436714', '<font face="arial">Cité médiévale de Châtillon-sur-Chalaronne<br><font size="-6">Châtillon-sur-Chalaronne</font></font>', '0xff9900', '/module/carto/index.php?offre=sitraPCU384538', '/download/site-principal/image/vignette_carto3D/Cite_medievale_ChatillonsurChalaronne-vignette.jpg', 1);
addLabel('789.75971375', '434.398910488', '<font face="arial">Fort l\'Ecluse<br><font size="-6">Léaz</font></font>', '0xff9900', '/module/carto/index.php?offre=01AASOR100341', '/download/site-principal/image/vignette_carto3D/Fort_l-ecluse-vignette.jpg', 1);
addLabel('515.179713849', '473.826523998', '<font face="arial">Grottes du Cerdon<br><font size="-6">Labalme</font></font>', '0xff9900', '/module/carto/index.php?offre=01NASOR100081', '/download/site-principal/image/vignette_carto3D/Grottes_du_Cerdon-vignette.jpg', 1);
addLabel('274.148174415', '241.528736731', '<font face="arial">La Plaine Tonique<br><font size="-6">Montrevel-en-Bresse</font></font>', '0xff9900', '/module/carto/index.php?offre=sitraLOI333442', '/download/site-principal/image/vignette_carto3D/La_Plaine_Tonique-vignette.jpg', 1);
addLabel('655.104404323', '342.486558243', '<font face="arial">Lac Genin<br><font size="-6">Charix</font></font>', '0xff9900', '/module/carto/index.php?offre=sitraPAN108097', '/download/site-principal/image/vignette_carto3D/Lac_Genin-vignette.jpg', 1);
addLabel('824.559999954', '274.565208625', '<font face="arial">Le Crêt de la neige<br><font size="-6">Lélex</font></font>', '0xff9900', '/module/carto/index.php?offre=sitraPAN106368', '/download/site-principal/image/vignette_carto3D/Cret_de_la_neige-vignette.jpg', 1);
addLabel('346.168506038', '377.174339055', '<font face="arial">Monastère royal de Brou<br><font size="-6">Bourg-en-Bresse</font></font>', '0xff9900', '/module/carto/index.php?offre=sitraPCU317047', '/download/site-principal/image/vignette_carto3D/Monastere_Royal_de_Brou-vignette.jpg', 1);
addLabel('449.687424425', '241.567402376', '<font face="arial">Mont Myon<br><font size="-6">Pressiat</font></font>', '0xff9900', '/module/carto/index.php?offre=01BOSOR100046', '/download/site-principal/image/vignette_carto3D/Mont_Myon-vignette.jpg', 1);
addLabel('173.304483941', '298.151449312', '<font face="arial">Musée Départemental de la Bresse - Domaine des Planons<br><font size="-6">Saint-Cyr-sur-Menthon</font></font>', '0xff9900', '/module/carto/index.php?offre=01PVSOR100001', '/download/site-principal/image/vignette_carto3D/Domaine-des-Planons-vignette.jpg', 1);
addLabel('212.88885122', '584.699541181', '<font face="arial">Parc des Oiseaux<br><font size="-6">Villars-les-Dombes</font></font>', '0xff9900', '/module/carto/index.php?offre=01VISOR100015', '/download/site-principal/image/vignette_carto3D/Parc_des_oiseaux-vignette.jpg', 1);
addLabel('672.660737172', '462.228010077', '<font face="arial">Plateau de Retord<br><font size="-6">Le Grand-Abergement</font></font>', '0xff9900', '/module/carto/index.php?offre=sitraPan420306', '/download/site-principal/image/vignette_carto3D/Plateau_de_Retord-vignette.jpg', 1);
addLabel('75.1374318714', '588.976102732', '<font face="arial">Ville d\'Ars-sur-Formans<br><font size="-6">Ars-sur-Formans</font></font>', '0xff9900', '/module/carto/index.php?offre=sitraPCU479981', '/download/site-principal/image/vignette_carto3D/Ville-Ars-sur_Formans-vignette.jpg', 1);
addLabel('600.859079787', '584.763109799', '<font face="arial">Ville d\'Hauteville-Lompnès<br><font size="-6">Hauteville-Lompnes</font></font>', '0xff9900', '/module/carto/index.php?offre=sitraPCU479982', '/download/site-principal/image/vignette_carto3D/Ville_Hauteville_Lompnes-vignette.jpg', 1);
addLabel('625.293957326', '306.807139328', '<font face="arial">Ville d\'Oyonnax<br><font size="-6">Oyonnax</font></font>', '0xff9900', '/module/carto/index.php?offre=sitraPCU479979', '/download/site-principal/image/vignette_carto3D/Ville_Oyonnax-vignette.jpg', 1);
addLabel('666.368023147', '795.201365168', '<font face="arial">Ville de Belley<br><font size="-6">Belley</font></font>', '0xff9900', '/module/carto/index.php?offre=sitraPCU479977', '/download/site-principal/image/vignette_carto3D/Ville_Belley-vignette.jpg', 1);
addLabel('337.314423324', '371.120822944', '<font face="arial">Ville de Bourg-en-Bresse<br><font size="-6">Bourg-en-Bresse</font></font>', '0xff9900', '/module/carto/index.php?offre=sitraPCU503389', '/download/site-principal/image/vignette_carto3D/Ville_Bourg_en_Bresse-vignette.jpg', 1);
addLabel('944.330156814', '194.852984016', '<font face="arial">Ville de Divonne-les-Bains<br><font size="-6">Divonne-les-Bains</font></font>', '0xff9900', '/module/carto/index.php?offre=sitraPCU420290', '/download/site-principal/image/vignette_carto3D/Ville_Divonne_les_Bains-vignette.jpg', 1);
addLabel('596.8975972', '412.245339734', '<font face="arial">Ville de Nantua<br><font size="-6">Nantua</font></font>', '0xff9900', '/module/carto/index.php?offre=sitraPCU479978', '/download/site-principal/image/vignette_carto3D/Ville_Nantua-vignette.jpg', 1);
addLabel('137.942051511', '154.778466257', '<font face="arial">Ville de Pont-de-Vaux<br><font size="-6">Pont-de-Vaux</font></font>', '0xff9900', '/module/carto/index.php?offre=sitraPCU479983', '/download/site-principal/image/vignette_carto3D/Ville_Pont_de_Vaux-vignette.jpg', 1);
addLabel('816.391258425', '252.053718937', '<font face="arial">Station Monts Jura<br><font size="-6">Lélex</font></font>', '0xff9900', '/module/carto/index.php?offre=sitraGEO269668', '/download/site-principal/image/vignette_carto3D/Station_Monts_Jura-vignette.jpg', 1);
addLabel('710.487851262', '667.268693619', '<font face="arial">Le grand colombier<br><font size="-6">Virieu-le-Petit</font></font>', '0xff9900', '/module/carto/index.php?offre=01AASOR100294', '/download/site-principal/image/vignette_carto3D/Le_Grand_Colombier-vignette.jpg', 1);
	if (global_json_data) {
		var default_color = '0xffffff';
		var compt = 1;
		for (var i in global_json_data) {
			var bgcolor = (global_json_data[i]['bgcolor']) ? global_json_data[i]['bgcolor'] : default_color;
			addLabel(global_json_data[i]['x'], global_json_data[i]['y'], global_json_data[i]['label'], '0xffffff', null, null, 0);
			setTimeout("lookAt('"+global_json_data[i]['x']+"', '"+global_json_data[i]['y']+"', null, 50)", compt*3);

			compt++;
		}
	}
}

function display_carto_3d() {
	var flash_w = 890;
	var flash_h = 560;
	if (!$('#suvoler_animation_accueil').length > 0) {
		var flashvars = 'dataPath=/lib/carto3d/hiresdata&cameraRecordingSpeed=100&cameraRecording=';
		var display_embed = true;
		if ($.browser.msie) {
			var class_ie = 'id="carto3d" class="carto3d carto3d_display_pole_phare"';
		}
		else {
			var class_ie = 'class="carto3d carto3d_display_pole_phare"';
		}
		if ($.browser.safari) {
			display_embed = false;
		}
		
		var flash = '<div id="suvoler_animation_accueil">'+
		     '<div class="header"><img class="close" src="http://www.ain-tourisme.com/download/site-principal/image/charte/ete/survoler/survoler-close.png" alt="Fermer" /></div>'+
		     '<div class="center">'+
		     '<h1>Survolez l\'Ain en 3D</h1>'+
			 '<div class="content">'+
			 '<object '+class_ie+' width="'+flash_w+'" height="'+flash_h+'" align="middle" data="/lib/carto3d/Main.swf" type="application/x-shockwave-flash">'+
			 '<param value="/lib/carto3d/Main.swf" name="movie" />'+
			 '<param value="high" name="quality" />'+
			 '<param value="#ffffff" name="bgcolor" />'+
			 '<param value="sameDomain" name="allowscriptaccess" />'+
			 '<param value="true" name="allowfullscreen" />'+
			 //'<param value="transparent" name="wmode" />'+
			 '<param value="'+flashvars+'" name="flashvars" />';
			 
		if (display_embed) {
			flash+= '<embed height="'+flash_h+'" width="'+flash_w+'" controls="smallconsole" loop="true" volume="0" autostart="true" '+
			 //'wmode="transparent" '+
			 'allowfullscreen="true" allowscriptaccess="sameDomain" flashvars="dataPath=/lib/carto3d" src="/lib/carto3d/Main.swf" />';
		}
		flash+= '</object>'+
			 '</div>'+
			 '</div>'+
		     '<div class="footer"></div>'+
			 '</div>';
		
		$('body').append(flash);

		var w = CalculWidthEcran();
		var pos_layer = (w-flash_w) / 2;
		$('#suvoler_animation_accueil').css('left', pos_layer+'px');
		$('#suvoler_animation_accueil .close').click(function() {
			$('#suvoler_animation_accueil').remove();
		}).mouseover(function() {
			$(this).css('cursor','pointer');
		});
		$('#suvoler_animation_accueil').show();
		if (valeur==1){stat('cdt01','','','carto3D;Ouverture');}
	}
}

function paste_flash_survoler_3d(flash_w, flash_h){
	if ($('.paste_flash_survoler_3d').length > 0) {
		var flashvars = 'dataPath=/lib/carto3d/loresdata&cameraRecordingSpeed=100&cameraRecording=';
		var display_embed = true;
		if ($.browser.msie) {
			var class_ie = 'id="carto3d" class="carto3d carto3d_display_pole_phare"';
		}
		else {
			var class_ie = 'class="carto3d carto3d_display_pole_phare"';
		}
		if ($.browser.safari) {
			display_embed = false;
		}
		
		var ch = '<object '+class_ie+' width="'+flash_w+'" height="'+flash_h+'" align="middle" data="/lib/carto3d/Main.swf" type="application/x-shockwave-flash">'+
			 '<param value="/lib/carto3d/Main.swf" name="movie" />'+
			 '<param value="high" name="quality" />'+
			 '<param value="#ffffff" name="bgcolor" />'+
			 '<param value="sameDomain" name="allowscriptaccess" />'+
			 '<param value="true" name="allowfullscreen" />'+
			 //'<param value="transparent" name="wmode" />'+
			 '<param value="'+flashvars+'" name="flashvars" />';
		if (display_embed) {
			ch+= '<embed height="'+flash_h+'" width="'+flash_w+'" controls="smallconsole" loop="true" volume="0" autostart="true" '+
			        //'wmode="transparent" '+
			        'allowfullscreen="true" allowscriptaccess="sameDomain" flashvars="dataPath=/lib/carto3d" src="/lib/carto3d/Main.swf" />';
		}
		ch+= '</object>';
		$('.paste_flash_survoler_3d').html(ch);

	}
}



// **************** Diaporama ******************** //
function anim_diaporama(sel) {
	if (!sel) sel = '.galleria';
	// anim diaporama
	$(sel).galleria({
		history   : true, // activates the history object for bookmarking, back-button etc.
		clickNext : true, // helper for making the image clickable
		insert    : '#main_image', // the containing selector for our main image
		onImage   : function(image,caption,thumb) { // let's add some image effects for demonstration purposes
			
			// fade in the image & caption
			if(! ($.browser.mozilla && navigator.appVersion.indexOf("Win")!=-1) ) { // FF/Win fades large images terribly slow
				image.css('display','none').fadeIn(1000);
			}
			caption.css('display','none').fadeIn(1000);
			
			// fetch the thumbnail container
			var _li = thumb.parents('li');
			
			// fade out inactive thumbnail
			_li.siblings().children('img.selected').fadeTo(500,0.3);
			
			// fade in active thumbnail
			thumb.fadeTo('fast',1).addClass('selected');
			
			// add a title for the clickable image
			image.attr('title','Next image >>');
		},
		onThumb : function(thumb) { // thumbnail effects goes here
			
			// fetch the thumbnail container
			var _li = thumb.parents('li');
			
			// if thumbnail is active, fade all the way.
			var _fadeTo = _li.is('.active') ? '1' : '0.3';
			
			// fade in the thumbnail when finnished loading
			thumb.css({display:'none',opacity:_fadeTo}).fadeIn(1500);
			
			// hover effects
			thumb.hover(
				function() { thumb.fadeTo('fast',1); },
				function() { _li.not('.active').children('img').fadeTo('fast',0.3); } // don't fade out if the parent is active
			)
		}
	});

	//var w = CalculWidthEcran();
	//var pos_layer = (w-galleria_w) / 2;
	//$('.diaporama_modal').css('left', pos_layer+'px');
	$('.diaporama_modal .close').click(function(){
		$('.diaporama_modal').remove();
	}).mouseover(function(){
		$(this).css('cursor','pointer');
	});
	//$('.diaporama_modal').show();
}

$(document).ready(
	function(){
		if($.browser.msie==true && $.browser.version<7) {
		    DD_belatedPNG.fix('.pngfix');
		    superfish('.hoverfix');
	    }
		changerTailleEcran();
		changerFondImage();
		var zindex_tmp = 10;

		$(window).resize(
			function(){
				changerTailleEcran();
			}
		);
		/* menus */
		$('li.deplie_menu').mouseenter(
			function (){
				$(this).children('.deplie_menu2').removeClass('nonemenu');
				$(this).children('.deplie_menu2').addClass('staticmenu');
				//$(this).children('.deplie_menu2').css('display','block');
			}
		);
		$('li.deplie_menu').click(
			function (){
				if ($(this).children('.deplie_menu2').attr('class').match(new RegExp('staticmenu','gi'))){
					$(this).trigger('mouseleave');
				}
				else{
					$(this).trigger('mouseenter');

				}

			}
		);
		$('li.deplie_menu').mouseleave(
			function (){
				$(this).children('.deplie_menu2').removeClass('staticmenu');
				$(this).children('.deplie_menu2').addClass('nonemenu');
			}
		);

		$('.widget_link').mouseenter(
			function(){
			    var widget_id = give_widget_id_with_link(this);
				//$(this).attr('href', '#'+widget_id).css('cursor', 'pointer');
				$(this).removeAttr('href').css('cursor', 'pointer');
			}
		);

		/* widget : click */
		$('.widget_link').click(
			function(){
				var widget_id = give_widget_id_with_link(this);

			    if ($('#'+widget_id).length) {
				    $('#'+widget_id).css('display','block');

					if (valeur==1){stat('cdt01','','','widget;'+widget_id);}

					var position_x = $('.'+widget_id).css("left");
					var position_y = $('.'+widget_id).css("top");

					savePosition(widget_id,position_x,position_y,1);

					if(widget_id == 'carnet'){
						get_widget_carnet_content();
					}
				}
			}
		);


		initWidgetPosition();

		$('.design_select').sSelect({'ddMinHeight': 200, 'containerMinHeight':22});
		$('#direct_acces').change(function(){
			var v = $(this).val();
			if (v.length > 0) {
				if (!v.match(new RegExp('http', 'gi'))) {
					v = global_chemin_url_images+v;
				}
				window.open(v, '_self');
			}
		});

		/* widget : drag */
		$('.widget_drag').draggable({'handle':'.drag_widget', 'cursor':'move',
			start : function(){
				$(this).css("z-index","1000");
			},
			stop: function (){
				zindex_tmp = zindex_tmp+1;
				$(this).css("z-index",zindex_tmp);

				var position_x = $(this).css("left");
				var position_y = $(this).css("top");
				var widget_name = $(this).attr('id');

				savePosition(widget_name,position_x,position_y,1);
			}
		});

		/* widget : fermer */
		$('.close_widget').click(
			function(){
				var parent = findWidgetParent(this);
				$(parent).css('display','none');

				var position_x = $(parent).css("left");
				var position_y = $(parent).css("top");
				var widget_name = $(parent).attr('id');

				savePosition(widget_name,position_x,position_y,0);
			}
		);



				update_form_sondage_action();
		update_form_sondage();

		update_form_meteo_action();
		update_form_meteo();

		initAgenda();
		update_form_agenda_action();
		update_form_agenda();


		initCommentaire();
		update_form_commentaire();

		
		// survoler
		$('.widget_survoler_link').click(function() {
			display_carto_3d();

		}).mouseover(function() {
			$(this).css('cursor','pointer');
		});

		// diaporama
		$('.diaporama').each(function(i, ui) {
			var img = $(ui);
			var ajax_file = '/module/jqueryvirtualtour/getImageSize.php';
			var post_data = {
                'url' : $(img).attr('src').replace('_diaporama', '')
			};
			$.post(ajax_file,post_data,function(data){
				data = ''+data;
				var arr_data = data.split('|');
				var width=arr_data[0];
				var height=arr_data[1];
				$(img).attr({'src':$(img).attr('src').replace('_diaporama',''),'height': height,'width':width});

				// exec diaporama on the image => with the lib you'll found
				$(img).panorama({
					'auto_start': 0,
					'start_position': 0
				});
			});

		});

		

		/* tag cloud */
		$('.tagcloud_word').each(function(i, ui) {
			$(ui).click(function(){
				var word = $(this).text();
				$('.query').val(word);
				$('#query_form').submit();
			})
		});

		$('.search_engine_tagcloud').mouseover(function() {
			tagcloud_show();
		}).mouseout(function() {
			tagcloud_hide_with_tempo();
		});

		$('.active_tagcloud').focus(function() {
			tagcloud_show();
		}).blur(function() {
			tagcloud_hide_with_tempo();
		});

		$('#tagcloud').mouseenter(function() {
			tagcloud_stop_hide_tempo();
		});
		$('#tagcloud').mouseleave(function() {
			tagcloud_hide_with_tempo();
		});

				
		$('.print').click(function(e) {
			e.preventDefault();
			IDfr.printer('#contenu_imprimable',function(){
				$('iframe[name=printer]').contents().find('.divimpressionhaut').remove();
			});
		});


		(function($){

			var
			window = this,
			undefined,
			_IDfr = window.IDfr,
			tmp = function(){}
			IDfr = window.IDfr = new tmp;

			IDfr = IDfr.prototype = {

				printer : function(printable,callback) {
					var html = $(printable).html();
					// on supprime les flashs
					html = html.replace(new RegExp("insert_flash", "gi"), '//insert_flash');
					html = html.replace(new RegExp("<script([^>]*)>(.*)</script>", "gi"), '');

					$('iframe[name=printer]').contents().find('#divframeimpression').html(html);
					if(typeof callback == 'function') {
						callback();
					}
					window.frames["printer"].focus();
					window.frames["printer"].print();
				}
			};

		})(jQuery);




		
		// ***** brochure
		$('#contact_img_1, #contact_img_2, #contact_img_3').mouseover(function() {
			$(this).attr('src', $(this).attr('src').replace(new RegExp('vignette', ''), 'vignette-over'));
		}).mouseout(function() {
			$(this).attr('src', $(this).attr('src').replace(new RegExp('-over', 'gi'), ''));
		});
		
		
		// diaporama
		anim_diaporama();
		
		// action on diaporama link
		$('.diaporamaLink').click(function(event) {
			event.preventDefault();
			var _div = $('#diaporamaDiv');
			if (!_div.size() > 0) {
				_div = $(document.createElement('div'));
				_div.attr('id', 'diaporamaDiv');
				$('#workspace .divcontent:first').before(_div);
			}
			var href = $(this).attr('href');
			href+= (href.match(/\?/i)) ? '&ajax=1' : '?ajax=1';
			_div.load(href+' .contentDiaporama', function(response, status, xhr) {
				if (status == "error") {
					_div.html('Erreur lors du chargement du diaporama');
				}
				else {
					anim_diaporama($('.galleria', _div));
				}
			});
		});
		
		
		// carousel for photosdumoment module
		if(typeof jQuery.fn.jcarousel == 'function') { 
			$('.carousel').addClass('jcarousel-skin-classic').jcarousel();
		}
		$('#image').css({'visibility' : 'visible', 'display':''});
		$('.action_click_photosdumoment').css('cursor', 'pointer').click(function(){
			var imgs = $('#photosdumomentpreview img');
			if (imgs.size() == 1) {
				var img = imgs.get(0);
				$(img).attr('src', $(this).attr('src'));
				$(img).css('cursor', 'pointer').unbind('click').click(function(){
					var imgTmp = new Image();
					imgTmp.src = $(this).attr('src');
					var w = (imgTmp.width) ? imgTmp.width : 800;
					var h = (imgTmp.height) ? imgTmp.height : 600;
					window.open($(this).attr('src'), '_blank', 'width='+w+'px, height='+h+'px');
				});
			}
		});
		if ($('.action_click_photosdumoment').size() > 0) {
			$('.action_click_photosdumoment:first').trigger('click');
		}
	}
);

