var temps = 2000; //temps entre chaque rafraichissement du compteur de bulle
var largeur_fermer = 18;
var hauteur_fermer = 18;
var taille_font = 8;
var largeur_bloc = 430;
var hauteur_ligne = 20;
var commentaire_width = 430;

var myrules = {
	
	'.navig' : function(){
		//ok site,bubbles,geo  : mozilla, chrome, opera, safari
		//ko site,bubbles,geo  : ie6
		var version =(navigator.appVersion.split(';'))
		var version=version[1].substr(6,1);
		if(navigator.appName == 'Microsoft Internet Explorer' && (version=="6")){
			$('navigateur').update("Utiliser un autre navigateur");
			new Effect.Appear($('navigateur'));
		}else{
			new Effect.Appear($('moteur'));
			if($('affichage')){
				new Effect.Appear($('affichage'));
			}
		}
	},
	
	'.btn_ouverture_demos' : function(bouton_ouverture_demos)//menu click demos
	{
		bouton_ouverture_demos.onclick=function()
		{
			new Ajax.Request(urlaff, 
			{
				asynchronous: 'true',
				postBody: 'tpl=demos/menu',
				onComplete: function(xhr)
				{
					$('affichage_demos').update(xhr.responseText);
					new Effect.BlindDown($('affichage_demos'),{duration: 0.3});
					Behaviour.apply();
				}
			});
		}
	},	
	
	'.btn_ouverture' : function(bouton_ouverture)//menu
	{
		bouton_ouverture.onclick=function()
		{
			var tabs = bouton_ouverture.id.split("_");
			var dossier = tabs[0];
			var page = tabs[1];
			var tpl='tpl='+dossier+'/'+page;
			if(dossier=="demos"){
				var nomtpl = tabs[2];
				tpl='tpl='+dossier+'/'+page+'/'+nomtpl;
			}
			new Ajax.Request(urlaff, 
			{
				asynchronous: 'true',
				postBody: tpl,
				onComplete: function(xhr)
				{
					$('affichage').update(xhr.responseText);
					new Effect.Appear($('affichage'),{
						afterFinish:function(){
							if(nomtpl == 'geolocal')
								lancementgeo();
						}
					});
					if(dossier != 'demos' && $('affichage_demos'))
						new Effect.BlindUp($('affichage_demos'),{duration: 0.3});
					
					Behaviour.apply();
					datePickerController.create();
				}
			});
		}
	},
	
	'.selection' : function(image_selection)//partie site
	{
		var tabs = image_selection.id.split("_");
		var id = tabs[1];
		var nbr = tabs[3];
		
		image_selection.onclick=function()
		{	
			
			var tabs = image_selection.id.split("_");
			var imageid = tabs[1];
			var colonne = tabs[2];
			var nomimage = tabs[3];
			
			//commentaire hauteur du bloque
			var taille_txt = $('commentaire'+imageid).innerHTML.length;;
			var nbr_ligne = taille_txt * taille_font / largeur_bloc;
			var hauteur_bloc = Math.round(nbr_ligne * hauteur_ligne);
			hauteur_bloc = hauteur_bloc + 40;
			//mise en place du grisage de la page//
			($('grisage')).style.display = "block";
			//mise en place du recepteur image//
			var image_grande="media/img/domaine/grande_"+nomimage+".png";
			var ch_image = '<img src="'+image_grande+'" alt="" />';
			$('image_recepteur').update(ch_image);
			$('commentaire_recepteur').style.height = '0px';
			scrollTo(0,0);
			
			
			if(navigator.appName == 'Microsoft Internet Explorer'){
				
				new Effect.Appear($('image_recepteur'),{
					afterFinish:function(){
						var image_width = $('image_recepteur').getWidth();
						var commentaire_marge_left = $('image_recepteur').offsetLeft + image_width;
	
						if($('commentaire'+imageid).innerHTML){	
							//mise en place du commentaire//
							if(navigator.appName == 'Microsoft Internet Explorer'){
								commentaire_width = commentaire_width+2;
							}
							$('commentaire_recepteur').update($('commentaire'+imageid).innerHTML);
							$('commentaire_recepteur').style.top = $('image_recepteur').offsetTop;
							$('commentaire_recepteur').style.left = commentaire_marge_left;	
							$('commentaire_recepteur').style.height = hauteur_bloc+'px';
							$('commentaire_recepteur').style.width = commentaire_width;	
							$('commentaire_recepteur').style.paddingTop = '20px';
							$('commentaire_recepteur').style.color = '#FFF';
							
							new Effect.Appear($('commentaire_recepteur'),{
								afterFinish:function(){
									var marge_gauche_fermer = $('commentaire_recepteur').offsetLeft + commentaire_width + 8 ;
									$('commentaire_fermer').style.width =$('commentaire_recepteur').style.width ;	
									$('commentaire_fermer').style.left = $('commentaire_recepteur').offsetLeft;	
									$('commentaire_fermer').style.top = $('commentaire_recepteur').offsetTop;
									$('commentaire_fermer').style.height = hauteur_fermer+'px';
									$('commentaire_fermer').style.width = largeur_fermer+'px';
									$('commentaire_fermer').style.left = marge_gauche_fermer+'px';
									new Effect.Appear($('commentaire_fermer'));
								}
							});	
						}
					}
				});
				
			}else{
				
				new Effect.Grow($('image_recepteur'),{
					direction:'left',
					afterFinish:function(){
						var image_width = $('image_recepteur').getWidth();
						var commentaire_marge_left = $('image_recepteur').offsetLeft + image_width;
	
						if($('commentaire'+imageid).innerHTML){	
						//mise en place du commentaire//
							$('commentaire_recepteur').update($('commentaire'+imageid).innerHTML);
							$('commentaire_recepteur').clonePosition($('image_recepteur'));	
							$('commentaire_recepteur').style.color = '#000';
							$('commentaire_recepteur').style.display = 'block';
							$('commentaire_recepteur').style.width = commentaire_width +'px';
							$('commentaire_recepteur').style.height = '2px';
							$('commentaire_recepteur').style.paddingTop = '0px';
							
							new Effect.Morph($('commentaire_recepteur'), {
								style:"left: "+commentaire_marge_left+"px;height:2px;",
							  	duration: 0.8, 
							  	
								 afterFinish:function(){
									$('commentaire_recepteur').style.color = '#FFF';
									new Effect.Morph($('commentaire_recepteur'), {
									style:"padding-top:20px;height:"+hauteur_bloc+"px;",
								  	duration: 0.8,
								  	
									  	 afterFinish:function(){
									  	 	//mise en place du bouton fermer
									  	 	var marge_gauche_fermer = $('commentaire_recepteur').offsetLeft + commentaire_width + 8 ;
										  	$('commentaire_fermer').clonePosition($('commentaire_recepteur'));
											$('commentaire_fermer').style.display = 'block';
											$('commentaire_fermer').style.height = hauteur_fermer+'px';
											$('commentaire_fermer').style.width = largeur_fermer+'px';
											$('commentaire_fermer').style.left = marge_gauche_fermer+'px';
									  	 }
									});
								 }
							});
						}
					}
				});
			}
  		}
	},
	
	'.deselection' : function(image_deselection)//partie site
	{
		image_deselection.onclick=function()
		{				
			$('commentaire_fermer').style.display = "none";
			$('commentaire_recepteur').style.display = "none";
			$('image_recepteur').style.display = "none";
			$('grisage').style.display = "none";
  		}
	}
}
/*
 
function rafraichitcompt(){ //demos bubbles
	if($("nbcompteur")){
		var CHPOST = "&type=rafraichit";
		new Ajax.Request(urltask, 
		{
			asynchronous: 'true',
			postBody: 'tache=demos/bubbles/compteurbulle'+CHPOST,
			onComplete: function(xhr)
			{
				var result = xhr.responseText.substr(13);
				if(result) { $('nbcompteur').update(result); }
			}
		});
		setTimeout(function () { rafraichitcompt(); }, temps);
	}
}
 ,		
'.compteur' : function(compt)
{
	 setTimeout(function () { rafraichitcompt(); }, temps);
}
 
 */
// Enregistrement des regles definies ci dessus dans Behaviour
Behaviour.register(myrules);