(function($) {
	$.fn.infoBulle = function(objParams , urlSprite)
	{
		var _ibConteneur = $(this);
		
		
		var defaultParams =
		{
			listInfoBulle:[
							{label:'home' , txt:'Accueil' , link:'index.php' , ajax:true},
							{label:'facebook' , txt:'<a href="http://www.facebook.com/pages/Groupe-Bernard-Loiseau-Officiel/196456150399648" target="_blank" style="color:#DDA40E;">Suivez-nous</a> | <a href="http://www.facebook.com/share.php?u=http://www.bernard-loiseau.com" target="_blank" style="color:#DDA40E;">Partagez</a>' , link:'http://www.facebook.com/pages/Groupe-Bernard-Loiseau-Officiel/196456150399648' , ajax:false},
							{label:'twitter' , txt:'<a href="http://fr.twitter.com/BernardLoiseau" target="_blank" style="color:#DDA40E;">Suivez-nous</a> | <a href="http://twitter.com/home" target="_blank" style="color:#DDA40E;" onclick="javascript:pageTracker._trackPageview (\'/outbound/twitter.com\');">Partager</a>' , link:'http://fr.twitter.com/BernardLoiseau' , ajax:false},
							{label:'print' , txt:'Imprimez la page' , link:'javascript:window.print()' , ajax:false},
							{label:'dwlPdf' , txt:'Téléchargez la brochure' , link:'http://www.bernard-loiseau.com/print/' , ajax:false},
							{label:'book' , txt:'Réservez un séjour ou une table' , link:'reservation.php' , ajax:true},
							{label:'gift' , txt:'Offrez un coffret cadeau' , link:'http://bernard-loiseau.secretbox.fr' , ajax:false},
							{label:'up' , txt:'Haut de page' , link:'javascript:MoveBlock.hautDePage();' , ajax:false}
						],
			spritePath:'../images/habillage/general/sprites-icones-raccourcis.png'
		};
		
		var _params = $.extend(defaultParams, objParams);
		
		var listInfoBulleSource = [
					{label:'home' , defaultTxt:'Accueil' , index:0},
					{label:'facebook' , defaultTxt:'Devenez fan' , index:1},
					{label:'twitter' , defaultTxt:'Suivez-nous' , index:2},
					{label:'print' , defaultTxt:'Imprimez la page' , index:3},
					{label:'dwlPdf' , defaultTxt:'Téléchargez la brochure' , index:4},
					{label:'book' , defaultTxt:'Réservez un séjour ou une table' , index:5},
					{label:'gift' , defaultTxt:'Offrez un coffret cadeau' , index:6},
					{label:'up' , defaultTxt:'Haut de page' , index:7}
					];
		
		if(langue == 'uk')
		{
			_params.listInfoBulle = [
							{label:'home' , txt:'Home' , link:'index.php' , ajax:true},
							{label:'facebook' , txt:'<a href="http://www.facebook.com/pages/Groupe-Bernard-Loiseau-Officiel/196456150399648" target="_blank" style="color:#DDA40E;">Follow-us</a> | <a href="http://www.facebook.com/share.php?u=http://www.bernard-loiseau.com" target="_blank" style="color:#DDA40E;">Share</a>' , link:'http://www.facebook.com/pages/Groupe-Bernard-Loiseau-Officiel/196456150399648' , ajax:false},
							{label:'twitter' , txt:'<a href="http://fr.twitter.com/BernardLoiseau" target="_blank" style="color:#DDA40E;">Follow-us</a> | <a href="http://twitter.com/home" target="_blank" style="color:#DDA40E;" onclick="javascript:pageTracker._trackPageview (\'/outbound/twitter.com\');">Share</a>' , link:'http://fr.twitter.com/BernardLoiseau' , ajax:false},
							{label:'print' , txt:'Print' , link:'javascript:window.print()' , ajax:false},
							{label:'dwlPdf' , txt:'Download pdf brochure' , link:'http://www.bernard-loiseau.com/print/' , ajax:false},
							{label:'book' , txt:'Book a stay or a table' , link:'reservation.php' , ajax:true},
							{label:'gift' , txt:'Offer a gift package' , link:'http://bernard-loiseau.secretbox.fr' , ajax:false},
							{label:'up' , txt:'Top' , link:'javascript:MoveBlock.hautDePage();' , ajax:false}
						];
		}//fin if
		
		var InfoBulle = 
		{
			pictoHtml:'',
			infoBulleConteneurHtml:'',
			infoBulleHtml:'',
			create:function()
			{
				
				InfoBulle.html = '';
				
				for(var i = 0 ; i < _params.listInfoBulle.length ; i++)
				{	
					var indexOf = -1;
					
					for(var j = 0 ; j < listInfoBulleSource.length ; j++)
					{
						if(_params.listInfoBulle[i].label == listInfoBulleSource[j].label)
						{
							indexOf = listInfoBulleSource[j].index;
							
							$('#idPicto' + i).die('click');
						}//fin if
					}//fin for
					
					InfoBulleEventHandler.overOut('idPicto' + i , indexOf , i);
					InfoBulleEventHandler.click('idPicto' + i , i);
					
					InfoBulle.pictoHtml += '<div id="idPicto'+ i +'" style="position:relative; z-index:3; cursor:pointer; float:left; width:32px; height:32px; background:url(\''+ _params.spritePath +'\') '+ indexOf * -32 +'px 0px;"></div>';
					
				}//fin for
				
				InfoBulle.pictoHtml += '<div style="clear:left;"></div>';
				
				_ibConteneur.html(InfoBulle.pictoHtml);
				
				InfoBulle.infoBulleConteneurHtml = '';
				InfoBulle.infoBulleConteneurHtml += '<div id="idConteneurInfoBulleTemplate"></div>';
				
				_ibConteneur.append(InfoBulle.infoBulleConteneurHtml);
				
				
				$('#idConteneurInfoBulleTemplate').css(
				{
					position:'absolute',
					zIndex:2,
					marginTop:'-32px',
					width:'auto',
					height:'32px'
				});
			},
			addInfoBulle:function(index)
			{
				InfoBulle.infoBulleHtml = '';
				
				InfoBulle.infoBulleHtml += '<div id="idInfoBulle'+ index +'">';
				
				
					InfoBulle.infoBulleHtml += '<div id="idBordGauche" style="float:left;"></div>';
					
					InfoBulle.infoBulleHtml += '<div id="idCenter" style="float:left;">';
						
						if(_params.listInfoBulle[index].txt != null)
						{
							InfoBulle.infoBulleHtml += '<span>' + _params.listInfoBulle[index].txt + '</span>';
						}//fin if
						else
						{
							InfoBulle.infoBulleHtml += '<span>' + listInfoBulleSource[index].defaultTxt + '</span>';
						}//fin else
						
					InfoBulle.infoBulleHtml += '</div>';
					
					InfoBulle.infoBulleHtml += '<div id="idBordDroite" style="float:left;"></div>';
					
				
				InfoBulle.infoBulleHtml += '</div>';
				
				InfoBulle.infoBulleHtml += '<div style="clear:left"></div>';
				
				$('#idConteneurInfoBulleTemplate').html(InfoBulle.infoBulleHtml);
				
				
				$('#idBordGauche').css(
				{
					width:'15px',
					height:'30px',
					background:'url(\'../images/habillage/general/info-bulle-gauche.png\') no-repeat',
					position:'relative'
				});
				
				$('#idCenter').css(
				{
					width:$('#idInfoBulle' + index + ' span').width()  + 'px',
					height:'30px',
					textAlign:'center',
					background:'url(\'../images/habillage/general/info-bulle-centre.png\') center top no-repeat',
					position:'relative',
					paddingTop:'8px',
					color:'#FFFFFF',
					fontFamily:'CenturyGothicRegular',
					fontSize:'0.85em'
				});
				
				$('#idBordDroite').css(
				{
					width:'15px',
					height:'30px',
					background:'url(\'../images/habillage/general/info-bulle-droite.png\') no-repeat',
					position:'relative'
				});
				
				$('#idInfoBulle' + index).css(
				{
					width:$('#idBordGauche').width() + $('#idCenter').width() + $('#idBordDroite').width(),
					position:'relative',
					textAlign:'center',
					paddingTop:'4px',
					opacity:0
				});
				
				$j("#idInfoBulle" + index).offset(
				{
					left:$j("#idPicto" + index).offset().left - ($('#idInfoBulle' + index).width() - $j("#idPicto" + index).width()) / 2,
					top:$j("#idPicto" + index).offset().top - $j("#idPicto" + index).height()
				});
				
				$('#idInfoBulle' + index).stop(true , true);
				$('#idInfoBulle' + index).animate(
				{
					opacity:1
				} , 200 , 'linear');
				
			},
			removeInfoBulle:function(index)
			{
				$('#idInfoBulle' + index).stop(true , true);
				if(_params.listInfoBulle[index].label == 'facebook' || _params.listInfoBulle[index].label == 'twitter')
				{
					$('#idInfoBulle' + index).delay(2500).animate(
					{
						opacity:0
					} , 200 , 'linear' , function()
					{
						$('#idConteneurInfoBulleTemplate').empty();
					});
				}//fi if
				$('#idInfoBulle' + index).delay(500).animate(
				{
					opacity:0
				} , 200 , 'linear' , function()
				{
					$('#idConteneurInfoBulleTemplate').empty();
				});
			}
		}
		
		
		var InfoBulleEventHandler = 
		{
			overOut:function(id , indexSprite , index)
			{
				$('#' + id).live('mouseover' , function()
				{
					$(this).css({backgroundPosition:32 * (-indexSprite) + 'px 32px'});
					InfoBulle.addInfoBulle(index);
				}).live('mouseout' , function()
				{
					$(this).css({backgroundPosition:32 * (-indexSprite) + 'px 0px'});
					InfoBulle.removeInfoBulle(index);
				});
			},
			click:function(id , index)
			{
				$('#' + id).live('click' , function()
				{
					//console.log(document.getElementById('displayed'));
					//console.log(_params.listInfoBulle[index].link.substr(11));
					if(_params.listInfoBulle[index].link != null && !_params.listInfoBulle[index].ajax)
					{
						if(_params.listInfoBulle[index].link.substr(0 , 11) == 'javascript:')
						{
							eval(_params.listInfoBulle[index].link.substr(11 , _params.listInfoBulle[index].link.length) + ';');
						}//fin if
						else
						{
							window.open(_params.listInfoBulle[index].link);
						}//fin else
						
					}//fin if
					else if(_params.listInfoBulle[index].link != null && _params.listInfoBulle[index].ajax)
					{
						return chargePage(_params.listInfoBulle[index].link,0,false);
					}//fin if
				});
			}
		}
		
		$(document).ready(function()
		{
			InfoBulle.create();
		});
		
		return $(this);
	};
})(jQuery);
