/**
* Gestion des evenements sur les pages abonnement (tracking GA / Rollovers images / infobulles)
* Ce fichier n'est insere que dans abo_offre_pagelayout.tpl	
**/
Shadowbox.init({
    // let's skip the automatic setup because we don't have any
    // properly configured link elements on the page
    skipSetup: false,
    overlayOpacity: 0.12,
    
    // include the html player because we want to display some html content
    players: ["html"]
});

/**
 JQuery document ready
*/

$(document).ready(function () {
	abonnementMapManager.init();
	eventGAManager.init();
});

/* Abonnement */
var abonnementMapManager = (function() {
var maps, abo, savoir, img;

function _init() {
	maps    = $('#offresCentre map');
	abo     = $('.map_abo', maps);
	savoir  = $('.map_abo', maps);
	img     = $('.mapped');
	//console.log(abo);
	abo.each(function(i) {
		$(this).mouseenter(function(e) {
			$(img[i]).attr('src', $(img[i]).attr('src').replace('_off', '_on'));
		});
		$(this).mouseleave(function(e) {
			$(img[i]).attr('src', $(img[i]).attr('src').replace('_on', '_off'));
		});
	});

//		$('.background_map.privilege').click(function(e){
//			e.preventDefault();
//			
//			$(this).parent().append('<form action="/WebloggiaUFC/verifierDroitCouplage.do" style="display: none;" class="hidden_form"></form>');
//			$('hidden_form').submit();
//
//		});

	var hide = false;
	var pos=$('#infoBulle2').position();
	/* Abo popin */
	$('#presentationAbo').mouseenter(function() {
		pos=$(this).position();
		$('#infoBulle2').css("left",pos.left);
		$('#infoBulle2').css("top",pos.top+60);
		$('#infoBulle2').fadeIn();
		hide = false;
		setInterval(function() { if(hide) { $('#infoBulle2').fadeOut(); clearInterval(self.interval); } }, 250);
	});
	$('#presentationAbo').mouseleave(function() {
		hide = true;
		$('#infoBulle2').mouseenter(function() {
			hide = false;
		});
	});
	$('#infoBulle2').mouseleave(function() {
		hide = true;
		$('#presentationAbo').mouseenter(function() {
			hide = false;
		});
	});
	
	$('#4sij2').click(function(){ 
		pos=$(this).position();
		$('#infoBulle2').css("left",pos.left);
		$('#infoBulle2').css("top",pos.top+15);
		$('#infoBulle2').fadeIn();
		hide=false;
	});

	
	$('body').click(function(e){
		var span = $('#infoBulle2').siblings('span')[0];
		if (e.target != span) {
			$('#infoBulle2').hide();
		}
	});
}

return ({init:_init});
})();

/* Tracking des evenements GA */
var eventGAManager = (function() {
function _init() {
	$('#logo').click(function(){
		pageTracker._trackEvent(window.location.pathname, 'Abo - Header - Logo QC');
	});
	$('#retour_site').click(function(){
		pageTracker._trackEvent(window.location.pathname, 'Abo - Header - Lien retour QC');
	});
	$('#retour').click(function(){
		pageTracker._trackEvent(window.location.pathname, 'Abo - Header - Lien retour Offres');
	});
	$('#lien-nous-contacter').click(function(e){
		pageTracker._trackEvent(window.location.pathname, 'Abo - Footer - Nous contacter');
	});
	$('#lien-donnees-personnelles').click(function(e){
		pageTracker._trackEvent(window.location.pathname, 'Abo - Footer - Donnees personnelles');
	});
	$('#lien-conditions-generales-d-abonnement').click(function(e){
		pageTracker._trackEvent(window.location.pathname, 'Abo - Footer - CGU');
	});
	$('#lien-questions-frequentes').click(function(e){
		pageTracker._trackEvent(window.location.pathname, 'Abo - Footer - Questions frequentes');
	});
	$('#map_abo_int').click(function(e){
		pageTracker._trackEvent(window.location.pathname, 'Abo - Page 3 offres - CTA Integral');
	});
	$('#map_savoir_int').click(function(e){
		pageTracker._trackEvent(window.location.pathname, 'Abo - Page 3 offres - En savoir plus Integral');
	});
	$('#map_abo_lib').click(function(e){
		pageTracker._trackEvent(window.location.pathname, 'Abo - Page 3 offres - CTA Liberte');
	});
	$('#map_savoir_lib').click(function(e){
		pageTracker._trackEvent(window.location.pathname, 'Abo - Page 3 offres - En savoir plus Liberte');
	});
	$('#map_abo_cpl').click(function(e){
		pageTracker._trackEvent(window.location.pathname, 'Abo - Page 3 offres - CTA Privilege');
	});
	
	// offres liees
	$('#INT5400_lie_LIB450').click(function(e){
		pageTracker._trackEvent(window.location.pathname, 'Abo - Page Integral - Lien Liberte');
	});
	$('#INT5400_lie_CPL2700').click(function(e){
		pageTracker._trackEvent(window.location.pathname, 'Abo - Page Integral - Lien Privilege');
	});
	$('#LIB450_lie_INT5400').click(function(e){
		pageTracker._trackEvent(window.location.pathname, 'Abo - Page Liberte - Lien Integral');
	});
	$('#LIB450_lie_CPL2700').click(function(e){
		pageTracker._trackEvent(window.location.pathname, 'Abo - Page Liberte - Lien Privilege');
	});
	
	//CTA
	//$('#cta_CPL2700').click(function(e){
	//	pageTracker._trackEvent(window.location.pathname, 'Abo - Page Privilege - CTA Privilege');
	//});
	$('#cta_LIB450').click(function(e){
		pageTracker._trackEvent(window.location.pathname, 'Abo - Page Liberte - CTA Liberte');
	});
	$('#bgcta_LIB450').click(function(e){
		pageTracker._trackEvent(window.location.pathname, 'Abo - Page Liberte - CTA Liberte');
	});	
	$('#cta_INT5400').click(function(e){
		pageTracker._trackEvent(window.location.pathname, 'Abo - Page Integral - CTA Integral');
	});
	$('#bgcta_INT5400').click(function(e){
		pageTracker._trackEvent(window.location.pathname, 'Abo - Page Integral - CTA Integral');
	});
	$('#lnk_abopapier').click(function(e){
		pageTracker._trackEvent(window.location.pathname, 'Abo - Page Privilege - Popin numero abonne');
	});
	$(".4sij").click(function(e){
		pageTracker._trackEvent(window.location.pathname, 'Abo - Page Integral - Popin questions juridiques');
	});
	$("#presentationAbo").mouseenter(function(e){
		pageTracker._trackEvent(window.location.pathname, 'Abo - Page Integral - Popin questions juridiques');
	});
}
return ({init:_init});
})();

