appLeadacity.appStatus = "Initializing Leadacity.";

appLeadacity.overlay = {"active":"1","url":"https:\/\/www.facebook.com\/tabletmag","pageviews":"1","texts":{"1":"Smart content plus fan-exclusive sweepstakes and giveaways. Like Tablet on Facebook.","2":"Smart content plus fan-exclusive sweepstakes and giveaways."},"cookie_reset":"90","cookie_time":1437912229,"cookie_time_reset":1445688229,"style":{"module":{"border_color":"E65A1E","background_color":"FFFFFF"},"plugin":{"background_color":"EAEAEA"},"p":{"color":"404040","font_family":"&#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, sans-serif","font_style":"normal","font_weight":"normal","text_align":"left","text_decoration":"none"}},"type":"facebook"};

appLeadacity.campaign = {"active":"1","archived":"0","name":"Tablet Magazine - Global","campaigntexts":{"1":"","2":""},"campaigntext":"0","texts":["1","2"],"layouts":["1","2","3"],"urls":["+http:\/\/www.tabletmag.com\/*"],"id":1};

appLeadacity.getValues = {"id":"3"};

appLeadacity.loadScript(appLeadacity.servername + "/webroot/css/modules.css", "css", false);

appLeadacity.loadScript(appLeadacity.servername + "/webroot/js/app/lib.min.js", "js", false);


(function(){
    var _fb_root 		= document.getElementById('fb-root');
    var _body 			= document.getElementsByTagName('body')[0];
    var _firstDiv 		= document.body.childNodes[0];
    var _fbDiv 			= document.createElement('div');
    var _lcContent		= '<div id="lc-social-right-small" class="lc-module-container lc-module-right-small" data-attribute="right" data-attribute-init="-100%" data-attribute-end="0"><div id="lc-module-holder" class="lc-holder" style="border-color : #E65A1E!important; background-color : #FFFFFF!important;"><div class="lc-module-content"><p class="lc-module lc-module-small" style="color : #404040!important;font-family : &#39;Lucida Sans Unicode&#39;, &#39;Lucida Grande&#39;, sans-serif!important;font-style : normal!important;font-weight : normal!important;text-align : left!important;text-decoration : none!important;">Smart content plus fan-exclusive sweepstakes and giveaways. Like Tablet on Facebook.</p><div class="lc-border">...</div><div class="lc-social-container" style="background-color : #EAEAEA!important;"><div class="lc-social-holder lc_defaultvalue"><div class="fb-like" data-href="https://www.facebook.com/tabletmag" data-send="false" data-width="200" data-show-faces="false" data-font="lucida grande" data-layout="button_count"></div></div></div></div><div id="lc-module-close" class="lc-module-close lc-module-opt-out lc-transition" data-module="facebook"><img class="lc-module-close" src="//www.leadacity.net/webroot/images/global/icons/icon-nav-close.png" alt="" /></div></div></div>';
    var _lcContentID	= '#';
    var _delay			= 0;
    var _show			= 0;
    var _rendered		= false;
    var _resizeDelay	= null;
	var _campaignType	= null;
    var _lcCookieID		= '1439995927';
    var _lcTrackID		= '2015-08-19:3:1:1:1:1';
    	_fbDiv.id		= 'fb-root';
    	
            
    appLeadacity.setCookie('lc_trackID', _lcTrackID, 180);
    
        
    if(_fb_root == null)
    {
        (function(d, s, id) 
		{
		    var js, fjs = d.getElementsByTagName(s)[0];
		    if (d.getElementById(id)) return;
		    js = d.createElement(s); js.id = id;
		    js.src = "//connect.facebook.net/en_US/all.js#xfbml=1";
		    fjs.parentNode.insertBefore(js, fjs);
		}
		(document, 'script', 'facebook-jssdk'));
        
        if(!document.getElementById(_fbDiv.id)) _body.insertBefore(_fbDiv, _firstDiv);
    }
    
        
    var init					= function()
    {   
        console.log('Leadacity.init');
        
        var initFBCookies		= function()
        {
	        appLeadacity.setCookie('lc_fb_session', _lcTrackID, 1);
	        appLeadacity.setCookie('lc_fb_cookie', _lcCookieID, 360);
	        appLeadacity.setCookie('lc_fb_track_id', _lcTrackID, 360);
        }; 
        
        var initEmailCookies	= function()
        {
	        appLeadacity.setCookie('lc_em_session', _lcTrackID, 1);
	        appLeadacity.setCookie('lc_em_cookie', _lcCookieID, 360);
	        appLeadacity.setCookie('lc_em_track_id', _lcTrackID, 360);
        };
        
        var initPageCookies		= function()
        {
	        appLeadacity.setCookie('lc_pg_session', _lcTrackID, 1);
	        appLeadacity.setCookie('lc_pg_cookie', _lcCookieID, 360);
	        appLeadacity.setCookie('lc_pg_track_id', _lcTrackID, 360);
        };
               
        var initFB				= function()
        {
            FB.Event.subscribe('edge.create', function(response) 
            {
                LC(_lcContentID).removeClass('lc-module-off');
                
                var _get		= { lc_curr_module : 'facebook', lc_query_type : 'converted', 'lc_trackID' : _lcTrackID, lc_fb_converted : _lcTrackID, lc_profile_id : _lac['clientID'] };
                
                if(_campaignType)  _get.lc_campaign_type = _campaignType;
                
                appLeadacity.loadScript(appLeadacity.servername + '/update/app/script/' + appLeadacity.getVariableString(_get), "js", false);
                
                appLeadacity.setCookie('lc_fb_converted', _lcTrackID, 360);
                                
                LC('div.lc-module-opt-out').addClass('lc-module-exit').removeClass('lc-module-opt-out');
                
            });
            
            FB.Event.subscribe('xfbml.render', function(response) 
            {
                  _delay	= setTimeout(function()
                  {
                   	if(_rendered) return false;
                   	
                   	_rendered	= true;
                   	
                   	LC(window).trigger('resize');
                    LC(_lcContentID).removeClass('lc-module-off');
                    
                  }, 2000);
            });  
            
            LC(window).on('load resize', function()
			{
				if(FB && FB.XFBML)
				{
					clearTimeout(_resizeDelay);
		           
					_resizeDelay 	= setTimeout(function(e)
					{
						LC('div.lc-social-holder').each(function()
						{
							var _width	= LC(this).width();
							var _str	= 'data-width="' + _width + '"';
							var _html	= LC(this).html();
								_html	= _html.replace(/data-width=".*?"/, _str);
							
							LC(this).html(_html);
						});
						
						FB.XFBML.parse();
						
					}, 100);				
				}			
			});      
        };
        
        var initFBEvents			= function()
        {
	        LC('div.lc-module-opt-out').click(function()
	        {
	            appLeadacity.setCookie('lc_fb_opt_out', _lcTrackID, 180);
	            
	            LC(_lcContentID).addClass('lc-module-off');
	            
	            appLeadacity.loadScript(appLeadacity.servername + '/update/app/script/' + appLeadacity.getVariableString({ lc_curr_module : 'facebook', lc_query_type : 'rejected', 'lc_trackID' : _lcTrackID, lc_fb_opt_out : _lcTrackID, lc_profile_id : _lac['clientID'] }), "js", false);
	        });
        };
        
        var initEmailEvents			= function()
        {
	        _delay	= setTimeout(function()
	        {
	            LC(_lcContentID).removeClass('lc-module-off');
	            
	            LC('input.lc-email-submit').css({ opacity : 0.25 });
	            
	        },2000);
	       
	        LC('input.lc-email-input').focus(function()
	        {
	            if(this.value == this.defaultValue)
	            {
	                this.value = '';
	            }
	        }).blur(function()
	        {
	            if(this.value == '')
	            {
	                this.value = this.defaultValue;
	            }
	        });
	        
	        LC('input.lc-email-agree').click(function()
	        {
	            LC('.lc-module-init').hide();
	            LC('.lc-module-main').fadeIn(300);             
	        });
	        
	        LC('div.lc-module-opt-out, input.lc-email-disagree').click(function()
	        {	            
	            LC(_lcContentID).addClass('lc-module-off');
	            
	            if(this.className.indexOf('lc-module-opt-out') < 0) return false;
	            
	            appLeadacity.setCookie('lc_em_opt_out', _lcTrackID, 180);
	            
	            appLeadacity.loadScript(appLeadacity.servername + '/update/app/script/' + appLeadacity.getVariableString({ lc_curr_module : 'email', lc_query_type : 'rejected', 'lc_trackID' : _lcTrackID, lc_em_opt_out : _lcTrackID, lc_profile_id : _lac['clientID'] }), "js", false);
	        });
	        
	        LC('input.lc-email-input').keyup(function(e)
	        {
	        	if(e.which === 13)  LC('input.lc-email-submit').trigger('click');
	        	
	        	if(appLeadacity.validate(this.value, 'email'))
	        	{
		        	LC('input.lc-email-submit').get(0).ischanged = true;
		        	
		        	LC('input.lc-email-submit').css({ opacity : 1 });
	        	}
	        });
	        
	        LC('input.lc-email-submit').click(function(e)
	        {
	            if(!LC('input.lc-email-submit').get(0).ischanged) return false;
	            
	            var _lc_email 		= LC('input.lc-email-input').val();
	            var _lc_validate	= appLeadacity.validate(_lc_email, 'email');
	            
	            if(this.className.indexOf('lc-submitted') >= 0) 
	            {
		            LC('.lc-module-error').text('You have already submitted, thank you.').show();
		            return false;
	            }
	            
	            if(_lc_validate)
	            {
	            	LC('input.lc-email-submit').addClass('lc-submitted');
	            	
	            	LC('.lc-module-error').hide();
	            	LC('input.lc-email-input').removeClass('lc-error')
	            	
	            	appLeadacity.setCookie('lc_em_converted', _lcTrackID, 360);
	            	
	            	appLeadacity.loadScript(appLeadacity.servername + '/update/app/script/' + appLeadacity.getVariableString({ lc_curr_module : 'email', lc_query_type : 'converted', 'lc_trackID' : _lcTrackID, lc_em_converted : _lcTrackID, lc_profile_id : _lac['clientID'], em_email : _lc_email }), "js", false);
	            	
	            	LC('.lc-email-input, .lc-email-button').hide();
	            	
	            	if(LC('div.lc-module-content-end').length > 0) initFBOverlay();
	            	else initConfirmation();
		            
		            LC('div.lc-module-opt-out').addClass('lc-module-exit').removeClass('lc-module-opt-out');
	            }
	            else
	            {
	            	LC('.lc-module-error').text('Please enter a valid email address.').show();
	            	LC('input.lc-email-input').addClass('lc-error')
	            } 	            
	        });
	        
	        var initConfirmation	= function()
	        {
		        _show	= setTimeout(function()
	            {
	                LC('.lc-module-main, .lc-module-init').hide();
	                LC('.lc-module-end').fadeIn(300);
	                
	                clearTimeout(_show);
	            },800);
	        };
	        
	        var initFBOverlay		= function()
	        {
		        _show	= setTimeout(function()
	            {	
	                clearTimeout(_show);
	                
					initFBCookies();        
					initFB(); 	
					initFBEvents(); 
					
					LC('div.lc-module-content-init').hide();
					LC('div.lc-module-content-end').fadeIn(300);
					
					LC(window).resize();
					
	            },800);
	        };
        };
        
        var initPageEvents			= function()
        {
	        LC(_lcContentID).removeClass('lc-module-off').fadeIn(400);
	        
	        LC('div.lc-module-opt-out, div.lc-module-overlay-close').click(function()
	        {
	            appLeadacity.setCookie('lc_pg_opt_out', _lcTrackID, 180);
	            
	            LC(_lcContentID).fadeOut(1000);
	            
	            appLeadacity.loadScript(appLeadacity.servername + '/update/app/script/' + appLeadacity.getVariableString({ lc_curr_module : 'page', lc_query_type : 'rejected', 'lc_trackID' : _lcTrackID, lc_pg_opt_out : _lcTrackID, lc_profile_id : _lac['clientID'] }), "js", false);
	        });
	        
	        LC('#lc-module-convert').click(function()
	        {
	            appLeadacity.setCookie('lc_pg_convert', _lcTrackID, 360);
	            
	            LC(_lcContentID).fadeOut(1000);
	            
	            appLeadacity.loadScript(appLeadacity.servername + '/update/app/script/' + appLeadacity.getVariableString({ lc_curr_module : 'page', lc_query_type : 'converted', 'lc_trackID' : _lcTrackID, lc_pg_convert : _lcTrackID, lc_profile_id : _lac['clientID'] }), "js", false);
	        });
		
			LC('span.lc-page-overlay-image').click(function(e)
			{
				LC('div.lc-module-iframe').toggleClass('lc-visibility');
				
				var Index	= LC('span.lc-page-overlay-image').index(this);
				
				LC('iframe.lc-page-overlay-image').each(function(index, iframe)
				{
					if(Index === index) LC(iframe).attr('src', LC(iframe).attr('data-src'));
				});
			});
        };
        
	    LC(_body).append(_lcContent);
	    
	    _lcContentID += LC('.lc-module-container').attr('id');
	    
	    LC(_lcContentID).addClass('lc-module-overlay lc-animate lc-module-off');
	    	    
                
        /* !Facebook Module */
        
        initFBCookies();        
        initFB(); 	
        initFBEvents();	        	        
          
                
                
               
    }
    
    var loadTimer = setInterval(function()
    {
	    if(window.LC)
	    {
		    if(document.readyState === 'complete' || document.readyState === 'interactive') init();
		    else 
		    {
			    LC(window).on('load', function()
			 	{
				 	init();
			 	});
		    }
		    
		    clearInterval(loadTimer);
	    }
    }, 200); 
}());

appLeadacity.impression 		= 'Invalid impression data provided.';



appLeadacity.message = "<li>Application mode is on</li><li> Account ID: 3</li><li> Referer URL received</li><li> Profile data received, account active</li><li> Check type of current device</li><li> Current device is Desktop</li><li> Mobile display is set to on</li><li> Checking Account Conversion Limit</li><li> Account Conversion Limit is currently set to 0</li><li> Page Overlay Module mode is on</li><li> Checking page Module</li><li> Checking page PageViews</li><li> page PageViews is currently set to 1</li><li> page Module is currently inactive</li><li> Facebook Overlay Module mode is on</li><li> Checking facebook Module</li><li> Checking facebook PageViews</li><li> facebook PageViews is currently set to 1</li><li> Checking facebook module campaigns</li><li> facebook module campaigns: 1</li><li> Checking facebook module campaign 1</li><li> Tablet Magazine - Global is active</li><li> URL is active for facebook campaign 1</li><li> Checking facebook module Converted Cookie</li><li> Checking facebook module Active Session</li><li> Checking facebook module Active Cookie</li><li> Displaying: Tablet Magazine - Global</li><li>  Modules checked: 2</li><li> Refered URL: <span>http://www.tabletmag.com/jewish-life-and-religion/191907/defining-open-orthodoxy</span> </li>";

if(window.LC) LC('#leadacity-modules-message').html(appLeadacity.message); 

