(function () {
	/* ********** DEBUT CONFIG ********** */
	var INTE_CFG = {
			canal: 'LINKEO0001',
			// global selectors
			trigger: '.LnkWcbForm-trigger', // the trigger is the element that activates the container
			triggerTxt: '.bt-rappel-txt', 
			backgroundContainer: '.LnkWcbForm-background-container',
			popupContainer: '.LnkWcbForm-popup-container',
			popupContentContainer: '.LnkWcbForm-popup-content-container',
			popupFile: 'btn-pop/popup.htm',
			popupName: 'LnkWcbPopup', // This string parameter should not contain any blank space.
			popupWidth :'420',
			popupHeight :'400',
			popupCloser :'.LnkWcbForm-popup-closer',
			popupAttributes: 'top=320,left=240,width=420,height=400,' +
				'resizable=no,menubar=no,toolbar=no,location=no,status=no'
		},
	/* ********** FIN CONFIG ********** */
		$ = LnkWcb.jQuery,
		I;
	
	/**
	 * This helper function does the setup of the trigger button (aka "Le Bouton").
	 */
	function setupWcbTrigger() {
		try {
			I = LnkWcb.inteBtn = LnkWcb.inteBtn || {};
			 
			 
			/* Classic openning popup
			$(INTE_CFG.trigger).click(function () {
				I.POPUP_WIN = window.open(INTE_CFG.popupFile, INTE_CFG.popupName, INTE_CFG.popupAttributes);
			}); */
 			 /* LINKBOX INITIALISATION */
			$('body').append('<div class="LnkWcbForm-background-container"></div><div class="LnkWcbForm-popup-container"><div class="LnkWcbForm-popup-content-container"></div><div class="LnkWcbForm-popup-closer">X</div></div>');
			 /*  ACTIVATION SUR LE CLICK DU TRIGGER*/
			$(INTE_CFG.trigger).click(function () {
				 /* On centre le popup par rapport à la fenetre la fenetre*/
				var windowWidth = $(window).width();
				var windowHeight = $(window).height();
				var alignWidth = windowWidth/2-INTE_CFG.popupWidth/2;
				var alignHeight = windowHeight/2-INTE_CFG.popupHeight/2+$(document).scrollTop()+"px";
				$(INTE_CFG.popupContainer).css("left",alignWidth);
				$(INTE_CFG.popupContainer).css("top",alignHeight);
				/* On affiche le background et le contenu*/
				$(INTE_CFG.backgroundContainer).css({ "opacity": "0.8" });
				$(INTE_CFG.backgroundContainer).fadeIn("normal"); 
				$(INTE_CFG.popupContainer).fadeIn("normal");
				$(INTE_CFG.popupContentContainer).html('<iframe style="overflow-x:hidden;overflow-y:hidden;" allowtransparency="true" src="' + INTE_CFG.popupFile + '" scrolling="no" width="'+INTE_CFG.popupWidth+'" frameborder="0" height="'+INTE_CFG.popupHeight+'"></iframe>');
			});
			/* END LINKBOX INITIALISATION */
			 /*  LINKBOX CLOSING BUTTONS*/
			$(INTE_CFG.backgroundContainer).click(function () {
				$(INTE_CFG.backgroundContainer).css({ "opacity": "0" });
				$(INTE_CFG.backgroundContainer).fadeOut("normal"); 
				$(INTE_CFG.popupContainer).fadeOut("normal"); 
				
			});	
			$(INTE_CFG.popupCloser).click(function () {
				$(INTE_CFG.backgroundContainer).css({ "opacity": "0" });
				$(INTE_CFG.backgroundContainer).fadeOut("normal"); 
				$(INTE_CFG.popupContainer).fadeOut("normal"); 
				
			});	
			 /*  END LINKBOX CLOSING BUTTONS*/
			 
			 
			/* Suivi de la popup au scroll de la page */
			popupContainerYloc = parseInt($(INTE_CFG.popupContainer).css("top").substring(0,$(INTE_CFG.popupContainer).css("top").indexOf("px")));
			$(window).scroll(function () {
				popupContaineroffset = popupContainerYloc+180+$(document).scrollTop()+"px";
				$(INTE_CFG.popupContainer).animate({top:popupContaineroffset},{duration:500,queue:false});
			});
			/* Suivi de la popup au scroll de la page */
			/* END LINKBOX */
			
			
			/* ----- Création d'un bouton de base pour gérer uniquement l'apparition du bouton dans cette fenêtre ----- */
			I.bouton = new LnkWcb.Bouton({
				canal: INTE_CFG.canal
			});
		// Animation du bouton au survol de la souris
		$(INTE_CFG.trigger).mouseenter(function(){
			$(INTE_CFG.triggerTxt).animate(
					{ top: '-=30'}, {
					duration: 300, 
					queue: true	
			});
			
		});
		// Animation du texte du bouton 
		$(INTE_CFG.trigger).mouseleave(function(){
			$(INTE_CFG.triggerTxt).animate(
					{ top: '+=30'}, {
					duration: 300, 
					queue: true
			});
			$(INTE_CFG.triggerTxtOn).fadeOut();
			$(INTE_CFG.triggerTxtOff).fadeIn();
			
		});
		// OnClick
		I.bouton.onChannelState(function (etat, etatOuverture) { // masquer le bouton en canal inactif ou hors-limites
			if (!etat.estActif || !etat.peutRecevoirAppel) {
				$('.LnkWcbForm-trigger').hide();
				I.montrerBouton = false;
			}
			else { // saturé, fermé, férié ou ouvert
				
				$('.LnkWcbForm-trigger').show();
				I.montrerBouton = true;
			}
		});
		I.bouton.onChannelState(function (etat, etatOuverture) { // afficher un bouton différent en mode ouvert/fermé
			if (etatOuverture !== "OUVERT") {
				$('.LnkWcbForm-trigger').addClass("LnkWcbForm-trigger-femeture");
			}
			else {
				$('.LnkWcbForm-trigger').removeClass("LnkWcbForm-trigger-femeture");
			}
		});
		// FORMULAIRE WCB
		$('input[name="nom"],input[name="prenom"],input[name="email"],input[name="telephone"],input[name="societe"]').focus(function () {  
				$(this).val('');
		});
			I.bouton.estOuvert();
		}
		catch (exc) {
			LnkLog.log('LnkWcb.inteBtn', exc);
		}
	}

	try {
		$(setupWcbTrigger);
	} catch (ignoredExc) {
		// LnkLog.log('integration LnkWcbBouton', ignoredExc);
	}
})();


