$(document).ready(function(){
    
        //Change to this URL once the empowerkit twitter account has some tweets flagged as favorites -> http://api.twitter.com/1/favorites/empowerkit.json
        
	 		
		$('#feature-phrases').innerfade({speed:2000,timeout:10000,type:'sequence'});

		$('#feature-people').innerfade({speed:2000,timeout:10000,type:'sequence'});

		$('#feature-website').innerfade({speed:2000,timeout:10000,type:'sequence'});
		
		$('#feature-people-mlm').innerfade({speed:2000,timeout:20000,type:'sequence'});

		$('#feature-website-mlm').innerfade({speed:2000,timeout:10000,type:'sequence'});
		
		$('#footer-questions').innerfade({speed: 2000,timeout:10000,type:'sequence'});
		
		$('#consumer').innerfade({speed: 2000,timeout:10000,type:'sequence'});
		
		$('#seller').innerfade({speed: 1500,timeout:2000,type:'sequence'});
		
		$('#costumer').innerfade({speed: 2000,timeout:9000,type:'sequence'});
		
		$('.footer-wrapper ul li:nth-child(5n)').click(function(e){
		    $(this).find('p').is(':visible')  ? $(this).find('p').hide() : $(this).find('p').show();
		});
    	
        	/* The following code is executed once the DOM is loaded */

        	// Calling the jQuery plugin and splitting the
        	// #holder UL into pages of 3 LIs each:
        	
        if($('#list1')){

        	$('#list1').sweetPages({perPage:12});

        	// The default behaviour of the plugin is to insert the 
        	// page links in the ul, but we need them in the main container:

        	var controls = $('.swControls:eq(0)').detach();
        	controls.appendTo('.tab_container2 #tab1');
    	}
    	
    	if($('#list2')){

        	$('#list2').sweetPages({perPage:12});

        	// The default behaviour of the plugin is to insert the 
        	// page links in the ul, but we need them in the main container:

        	var controls2 = $('.swControls:eq(1)').detach();
        	controls2.appendTo('.tab_container2 #tab2');
    	}

		
		$("#mlmVideo").tubeplayer({
			width: 780, // the width of the player
			height: 520, // the height of the player
			allowFullScreen: "true", // true by default, allow user to go full screen
			initialVideo: "7Faq-S39x8k", // the video that is loaded into the player
			playerID: "youtube-player", // the ID of the embedded youtube player
			preferredQuality: "default",// preferred quality: default, small, medium, large, hd720
			onPlay: function(id){}, // after the play method is called
			onPause: function(){}, // after the pause method is called
			onStop: function(){}, // after the player is stopped
			onSeek: function(time){}, // after the video has been seeked to a defined point
			onMute: function(){}, // after the player is muted
			onUnMute: function(){}, // after the player is unmuted
			onPlayerEnded: function(){
			    $(".close").trigger('click');
			    setTimeout(function(){
                    $("li.try-button a").trigger('click');
                },600);
			}
		});
		
		$("#franVideo").tubeplayer({
			width: 780, // the width of the player
			height: 520, // the height of the player
			allowFullScreen: "true", // true by default, allow user to go full screen
			initialVideo: "TfW-2awWVYA", // the video that is loaded into the player
			playerID: "youtube-player", // the ID of the embedded youtube player
			preferredQuality: "default",// preferred quality: default, small, medium, large, hd720
			onPlay: function(id){}, // after the play method is called
			onPause: function(){}, // after the pause method is called
			onStop: function(){}, // after the player is stopped
			onSeek: function(time){}, // after the video has been seeked to a defined point
			onMute: function(){}, // after the player is muted
			onUnMute: function(){}, // after the player is unmuted
			onPlayerEnded: function(){
			     $(".close").trigger('click');
    			setTimeout(function(){
                    $("li.try-button a").trigger('click');
                },600);
			}
		});
		
		function showData(data){
        	var html = data.currentTime;
        	if(html >= 42){
        	    $('.tryOverlay').slideDown("slow");
        	    clearInterval(window.period);
        	}
        }
        
        $('a.instant').click(function(){
            $('.tryOverlay').hide();
            setTimeout(function(){
                window.period = setInterval(function(){
                 if ($('#apple').is(':visible')){
                    showData($('.apple_overlay > div').tubeplayer('data'));
                }
                }, 1000);
            }, 30000);
            
        })
        
        $('.apple_overlay .tryOverlay .hide').click(function(){$(this).parent().slideUp("slow")});
        		
    	$('.website_overlay .instant').click(function(){
	        $(this).siblings('.close').trigger('click');
	        setTimeout(function(){
                $(".feature-text-button a").trigger('click');
            },600);
	    });
	    
	    $('.tryOverlay .try').click(function(){
	        $(this).parent().siblings('.close').trigger('click');
	        setTimeout(function(){
                $("li.try-button a").trigger('click');
            },600);
	    });
		
		$(".feature-text-button a").click(function(){
		    //$('#apple').children('div').tubeplayer("play");
		});
		
		$('.call-girl-parent').mouseover(function(){habla_window.expand()});
		
		//if(e.target.tagName != "a"){ $('.search_results').removeClass('visible'); }
		
		$(document).click(function(e){
		    var pricingBubble = $('.pricing > .pricing-bubble-container'),
		        contactBubble = $('.contact-bubble-parent > .contact-bubble'),
		        tt = $('.link-tt');
		        $target = $(e.target);
            if( !$target.is("li.pricing > a") ) {
  		        pricingBubble.hide();
            };
            if( !$target.is("li.contact-bubble-parent > a") ) {
  		        contactBubble.hide();
            };
            
            if(!$target.is('.link-tt')){
                tt.children('span').hide();
            }
            
            !$target.closest('#subdomain, #subdomain-form, .dd-arrow, .domains, #distributors').length && $('.domains').hide();
		});

		$(document).ready(function(){
			$('#slider1').bxSlider({
                auto: true,
                pause: 5000         
            });
		});
		
		/*$('.facts-button').click(function () {
			$(".facts-list").is(":hidden") && $(".facts-list").slideDown();
             var destination = $(this).offset().top;
             $("html:not(:animated),body:not(:animated)").animate({ scrollTop: destination-69}, 850 );
             return false;
		});*/
		
		$(".tab_content").hide();
		
		$("ul.tabs li:first").addClass("active").show();
		
		$(".tab_content:first").show();  

		$("ul.tabs li").click(function()  {  
			$("ul.tabs li").removeClass("active");  
				$(this).addClass("active");  
			$(".tab_content").hide();  

			var activeTab = $(this).find("a").attr("href");  
				$(activeTab).fadeIn();  
			return false;  
		});

		$("ul.tabs2 li").click(function()  {  
			$("ul.tabs2 li").removeClass("active");  
				$(this).addClass("active");  
			$(".tab_content2").hide();  

			var activeTab = $(this).find("a").attr("href");
			  $(activeTab).css('visibility','visible');
				$(activeTab).fadeIn();  
			return false;  
		});

        $("a[rel=#apple]").overlay({
            mask: '#000', 
            onBeforeClose: function(){
                $('#apple').children('div').tubeplayer("stop");
            }
        });
        
        //$("a[rel=#website1], a[rel=#website2], a[rel=#website3], a[rel=#website1_fb], a[rel=#website2_fb], a[rel=#website3_fb]").overlay({mask: '#000', effect: 'apple'});
		
		$('.hello').clone().appendTo('.goodbye');
		
		$('#apple a.close').click(function(){
			$(this).siblings('div').tubeplayer("stop");
		    return false;
		});
		         
        var distributor = !$('#try').length,
            tryForms = distributor ? $('#try-form-distributor').add('#try-form-distributor-short') :  $('#try-form'),
            eBookForm = $('#e-book'),
            tryFormsFields = tryForms.find('input[type=text]').add('#password').add('#password_short'),
            eBookFields = eBookForm.find('input[type=text]'),
            inputSubdomain = $("#subdomain"),
            inputRelative = inputSubdomain.parent(),
            linkDistributor = $('a[rel=#try-distributor-short]'),
            linkOverlay = distributor ? $("a[rel=#try-distributor]") : $("a[rel=#try]"),
            linkTemp = linkOverlay.add("a[rel=#try-distributor-short-temp]"),
            production = true;
        linkTemp.click(function(e){
            inputRelative.siblings().filter('a').hide().end().filter('.error').remove();
            var inputValue = $.trim(inputSubdomain.val()) == "",
                subdomainForm = $('#subdomain-form'),
                lan_es = $('body.es').length;
            if($(this).attr('rel') == '#try-distributor-short-temp'){
                inputSubdomain.removeClass('error error-invalid error-empty error-words error-letters');    
                (inputValue && inputSubdomain.addClass('error error-invalid error-empty')) ||
                (inputSubdomain.val() != inputSubdomain.val().replace(/[^\w]/g, '') && inputSubdomain.addClass('error error-invalid')) ||
                (/\b(?:http|mail|www|ftp|login|admin)\b/.test(inputSubdomain.val()) && inputSubdomain.addClass('error error-invalid error-words')) ||  
                (inputSubdomain.val().length && inputSubdomain.val().length < 3 && inputSubdomain.addClass('error error-invalid error-letters'));
                if(inputSubdomain.hasClass('error')){
                    var errorMsg = false;
                    if(inputSubdomain.hasClass('error-words')){
                        errorMsg = lan_es ? "Subdominio errÃ³neo, Tu nombre es una palabra reservada" : "Invalid URL, your company name is a reserved word, please use another name.";
                    }
                    else if(inputSubdomain.hasClass('error-letters')){
                        errorMsg = lan_es ? "Subdominio errÃ³neo, por favor utiliza mas de 3 letras" : "Invalid URL, please use more than 3 letters.";
                    }
                    else if (inputValue){
                        errorMsg = lan_es ? "Campo requerido" : "Required field";
                    }
                    else {
                        errorMsg = lan_es ? "Subdominio errÃ³neo" : "Invalid URL";
                    }
                    inputRelative.siblings('.button-submit').after('<span class="error">' + errorMsg + '</span>');
                    e.preventDefault();
                    return false;
                }
                else{
                    var dataString = production ? (distributor ? "http://default-0-461.profilepages.com/api/v1/breezi_sites/create?" : "http://default-0-461.profilepages.com/api/v1/installations/create?") : (distributor ? "http://default-0-1.breezhub.com/api/v1/breezi_sites/create?" : "http://default-0-461.profilepages.com/api/v1/installations/create?");
                    dataString += inputSubdomain.attr('name') == 'subdomain' ? "subdomain=" + inputSubdomain.val() : "name=" + inputSubdomain.val() + "&domain_pool_name=" + $('#domain').val()
                    dataString += "&authentication_token=f6e192d7d3d93ec8f7c45bd61013619d&callback=?";
                    $.getJSON(dataString, function(data){
                        if(inputSubdomain.attr('name') == 'subdomain' ? data.errors.subdomain : (data.errors.domain_pool_name || data.errors.name)){
                            inputSubdomain.addClass('error') && inputRelative.parent().append('<span class="error">Subdomain has already been taken</span>');
                            e.preventDefault();
                            return false;
                        }
                        else{
                            $('#subdomain-distributor').val(inputSubdomain.val());
                            $('#subdomain-form-field').addClass('hide-subdomain');
                            subdomainForm.val(inputSubdomain.val());
                            $('#domain-form').val($('#domain').val());
                            inputSubdomain.attr('name') == 'subdomain' ? linkDistributor.trigger('click') :  linkOverlay.eq(0).trigger('click');
                        }
                    });
                
                    return false;
                }
            }
            tryForms.find('.errors').html('').css('display', 'none');
            tryForms.find('.error').removeClass('error').filter('span').remove();
            tryForms.find('.success').remove();
            tryForms.find('.ghostwriter_input').find('span:eq(0)').html('');
            tryFormsFields.not('#subdomain-form').each(function(){
             $(this).val() != $(this).attr('placeholder') && $(this).val('');
            });
            var formChildren = tryForms.children();
            formChildren.filter('.errors').hide();            
            formChildren.filter(':not(.errors)').css('display', 'block');
            $('.try-bg').show();
            $('.try-overlay-wrapper > .close').show();
        });

        linkOverlay.click(function(){
            var subdomain_form_field = $('#subdomain-form-field');
            if(subdomain_form_field.hasClass('hide-subdomain')){
                subdomain_form_field.removeClass('hide-subdomain').hide()
                $('.with-subdomain').show().siblings().hide();
            }
            else {
                var domain = $('.domains').eq(0).children().eq(0).find('span:last').text();
                subdomain_form_field.show().find('.ghostwriter_input').css('visibility', 'hidden').end().find('#domain-form').val(domain);
                $('.without-subdomain').show().siblings().hide();
                $('#subdomain-form').val('');
            }
        }).overlay({
            mask: '#000',
            onBeforeClose: function(){
                var tryOverlayWrapper = $('.try-overlay-wrapper').eq(0);
                if(tryOverlayWrapper.is(':visible') && !tryOverlayWrapper.find('.close').is(':visible')){
        	        return false;
        	    }
            }
        });
        linkDistributor.length && linkDistributor.overlay({mask: '#000'});

        $('#try-form-distributor-short').find('.button-submit a').unbind('click').click(function(e){
            $('#try-form-distributor-short').trigger('submit');
            e.preventDefault();            
            return false;
        });
        
        $.browser.msie && tryFormsFields.not('.input-short').css('line-height', '2.5');
        
        tryForms.add(eBookForm).submit(function(e){
           e.preventDefault();
           var errors = $('.errors').html('').css('display', 'none'),
               input = false,
               form = $(this),
               fields = form.hasClass('e-book') ? eBookFields : $(this).find('input:not(:submit)'),
               lan_es = $('body.es').length,
               distributor = /try-form-distributor/.test(form.attr('id')),
               formChildren = form.children();
           fields.each(function(){
             input = $(this).removeClass('error empty error-password error-invalid error-email error-words error-letters error-empty');
             
             if(input.attr('name') == 'name' || input.attr('name') == 'subdomain'){
                (input.val() != input.val().replace(/[^\w]/g, '') && input.addClass('error error-invalid')) ||
                (/\b(?:http|mail|www|ftp|login|admin)\b/.test(input.val()) && input.addClass('error error-invalid error-words')) ||  
                (input.val().length && input.val().length < 3 && input.addClass('error error-invalid error-letters'));
              } else if(input.attr('name') == 'password'){
                  input.val().length && input.val().length < 6 && input.addClass('error error-password');
              }
             $.trim(input.val()) == '' ? input.addClass('error empty') : /email|contact_email/.test(input.attr('name')) && !/^([a-z0-9_\.\-\+]+)@([\da-z\.\-]+)\.([a-z\.]{2,6})$/i.test(input.val()) && input.addClass('error error-email');
           });
           
           var elementsWithErrors = form.find('.error'),
               inputsWithErrors = elementsWithErrors.filter('input');
           
           if(inputsWithErrors.length){//error-invalid error-letters
                errors.length && errors.append(lan_es ? '<p>Favor de rellenar los campos requeridos</p>' : '<p>Required fields are not filled in</p>').css('display', 'block');
                var errorMsg = false;
                elementsWithErrors.filter('span').remove();
                if(inputsWithErrors.filter('.error-invalid').length){
                    if(inputsWithErrors.filter('.error-words').length){
                        errorMsg = lan_es ? "Subdominio errÃ³neo, Tu nombre es una palabra reservada" : "Invalid URL, your company name is a reserved word, please use another name";
                    }
                    else if(inputsWithErrors.filter('.error-letters').length){
                        errorMsg = lan_es ? "Subdominio errÃ³neo, por favor utiliza mas de 3 letras" : "Invalid URL, please use more than 3 letters";
                    }
                    else {
                        errorMsg = lan_es ? "Subdominio errÃ³neo" : "Invalid URL";
                    }
                    errors.length && errors.show().append("<p>" + errorMsg + "</p>");
                }
                if(inputsWithErrors.filter('.error-email').length){
                    errors.show().append("<p>" + (lan_es ? "DirecciÃ³n de e-mail errÃ³nea" : "Invalid email address") + "</p>");
                }
                inputsWithErrors.filter('.error-password').length && errors.length && errors.show().append("<p>" + (lan_es ? "La contraseña debe contener al menos 6 caracteres" : "The password must be at least 6 characters long") + "</p>");
                return false;
            }            
            var sendingMessage = distributor ?
                (lan_es ? "<b>Impresionante!</b> Redireccionando a tu sitio ahora<span class='dot' id='dot1'>.</span><span class='dot' id='dot2'>.</span><span class='dot' id='dot3'>.</span>" : "<b>Awesome!</b> We're creating your site now! Please be patient and DO NOT close this!<span class='dot' id='dot1'>.</span><span class='dot' id='dot2'>.</span><span class='dot' id='dot3'>.</span>") :
                (lan_es ? 'Trabajando duro... Esto tomará cerca de 1 Minuto!' : 'Working Hard... This Will Take About 1 Minute!');
           	form.children().css('display', 'none').end().append("<span class='success'><span class='sending'>" + sendingMessage + "</span></span>");
            $('.try-bg').hide();
            $('.try-overlay-wrapper > .close').hide();
            var dataString = $(this).serialize();                                                          
            dataString += '&last_referer=' + encodeURIComponent(window.location.href);
            dataString += form.hasClass('e-book') ? '&ebook=true' : '';           
            dataString += '&authentication_token=f6e192d7d3d93ec8f7c45bd61013619d&callback=?';
            if(production && !distributor){
                dataString = 'installation_type=Empowerkit&' + dataString; 
            }
            var apiURL = production ? (distributor ? "http://default-0-461.profilepages.com/api/v1/breezi_sites/create?" : "http://default-0-461.profilepages.com/api/v1/installations/create?") : (distributor ? "http://default-0-1.breezhub.com/api/v1/breezi_sites/create?" : "http://default-0-1.breezhub.com/api/v1/installations/create?");
            distributor && showDots();
            $.getJSON(apiURL + dataString, function(data){
               var successMsg = form.find('.success');
               if (data.result == 'success' || data.errors.raise){
                   if(!distributor){
                       successMsg.html(lan_es.length ? "¬°Genial! Tu sitio ha sido creado ahora mismo! Recibiras la informaci√≥n de acceso en tu correo electr√≥nico. Redireccionando<span class='dot' id='dot1'>.</span><span class='dot' id='dot2'>.</span><span class='dot' id='dot3'>.</span>" : "Awesome! Your site is being created right now!<br/>You'll get your access information in your email. Redirecting<span class='dot' id='dot1'>.</span><span class='dot' id='dot2'>.</span><span class='dot' id='dot3'>.</span>");
                       showDots();
                   }
                   $.getJSON("/wp-content/themes/beta/" + (distributor ? "send-distributor-form" : "store-address-2k11") + ".php?" + dataString, function(data1){
                       window.location = data.access_url;
                   });
                       
               }
               else{
                   successMsg.remove(); 
                   elementsWithErrors.filter('span').remove();
                   data.errors.email && $("#email, #contact_email, #contact_email_short").addClass('error') && errors.show().append('<p>' + data.errors.email + '</p>');
                   data.errors.subdomain && $("input[name=subdomain]").addClass('error') && errors.show().append('<p>' + data.errors.subdomain + '</p>');
                   form.children().css('display', 'block');
               }
           });
           return false;  
        });
        
        function showDots(){
            setTimeout(function(){$('#dot1').show();}, 1000);
            setTimeout(function(){$('#dot2').show();}, 2000);
            setTimeout(function(){$('#dot3').show();}, 3000);
        }
        
        tryFormsFields.add(eBookFields).add(inputSubdomain).attr('autocomplete', 'off').focus(function(){
            $(this).removeClass('error');
        });
        
        window.olark||(function(k){var g=window,j=document,a=g.location.protocol=="https:"?"https:":"http:",i=k.name,b="load",h="addEventListener";(function(){g[i]=function(){(c.s=c.s||[]).push(arguments)};var c=g[i]._={},f=k.methods.length;while(f--){(function(l){g[i][l]=function(){g[i]("call",l,arguments)}})(k.methods[f])}c.l=k.loader;c.i=arguments.callee;c.p={0:+new Date};c.P=function(l){c.p[l]=new Date-c.p[0]};function e(){c.P(b);g[i](b)}g[h]?g[h](b,e,false):g.attachEvent("on"+b,e);c.P(1);var d=j.createElement("script");m=document.getElementsByTagName("script")[0];d.type="text/javascript";d.async=true;d.src=a+"//"+c.l;m.parentNode.insertBefore(d,m);c.P(2)})()})({loader:(function(a){return "static.olark.com/jsclient/loader1.js?ts="+(a?a[1]:(+new Date))})(document.cookie.match(/olarkld=([0-9]+)/)),name:"olark",methods:["configure","extend","declare","identify"]}); olark.identify('3501-602-10-4481');
        
        setTimeout(function(){
            $('div.like-facebook').append('<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.facebook.com%2Fpages%2FEmpowerkit%2F118422541506479&amp;layout=button_count&amp;show_faces=false&amp;width=77&amp;action=like&amp;font=lucida+grande&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" style="border:none; margin-top:-3px; overflow:hidden; width:83px; height:21px;" allowtransparency="true"></iframe>')
        },3000);
        
        

            var categorie_tabs = $('.nav-categories > .categories > ul > li > a'),
                post_list_categories = $('.posts-by-categories li + li');
                
            post_list_categories.hide();
            categorie_tabs.click(function(e){
                var category = ".cat" + $(this).attr('id');
                categorie_tabs.removeClass('selected');
                $(this).addClass('selected');
                $(category).show().siblings().hide();
                e.preventDefault();
            });
            
            var tabs_list = $('.tabs-list > li > a'),
                concepts_list_elements = $('.concepts-list li + li');
                
            concepts_list_elements.hide();
            tabs_list.click(function(e){
                var category = "#cat" + $(this).attr('id');
                tabs_list.removeClass('selected');
                $(this).addClass('selected');
                $(category).show().siblings().hide();
				        e.preventDefault();
            }).eq(0).addClass('selected');
            
            $('input:text').placeholder();
            $('#password_short').placeholder();
            
			$('.grouped-posts').find('strong').click(function(){
				if($(this).hasClass('behind')){
					$(this).removeClass('behind').parent().css('position', 'relative').siblings('li').css('position','absolute').children('strong').addClass('behind');
					}
			
			});
			
			
			$('.favorite-blogs').length && $('.favorite-blogs').find('a').pageSlide();
			
			$('#solution > .evolution-wrap > ul > li > strong').hover(
			    function () {
			        $(this).find('div').show();
                  }, 
                  function () {
                    $(this).find('div').hide();
                  }
			    );
            
			$('#languages').hover(
            function () {
              $(this).animate({
                  width: "116px"
                }, 200 );
            },
            function () {
              $(this).animate({
                  width: "26px"
                }, 200 );
            });
      $('#languages > li > a').click(function(){
        !$(this).hasClass('active') && $('#languages > li > a').removeClass('active') && $(this).addClass('active');
      });
      
      $('.contact-bubble-parent > a').click(function(ev){
        var that = $(this).siblings('.contact-bubble');
        that.click(function(e){
          e.stopPropagation();
        });
        that.toggle();
        ev.preventDefault();
      });
      
      $('.pricing > a').click(function(ev){
        var that = $(this).siblings('.pricing-bubble-container');
        that.click(function(e){
          e.stopPropagation();
        });
        that.toggle();
        ev.preventDefault();
      });
      
      $('.blog-categories-parent').hover(
        function(){
          $(this).find('.blog-categories').show();
        },
        function(){
          $(document).click(function(){
            $('.blog-categories').hide();
        });
        
        $('.blog-categories').click(function(e){
          e.stopPropagation();
        })
          
        }).mouseenter(function(){
          $('.pricing > .pricing-bubble-container:visible').hide();
  		    $('.contact-bubble-parent > .contact-bubble:visible').hide();
        });
        
        $('.closer').click(function(){
          $(this).parent().hide();
        });
        
        $('.ribbon > a').click(function(){
          $(this).parent().parent().hide();
        });
    
        inputSubdomain.add('#subdomain-form').each(function(){
            var inputSubdomain = $(this),
                inputGhost = inputSubdomain.siblings('.ghostwriter_input'),
                inputGhostDomains = inputSubdomain.siblings('.domains'),
                inputGhostSubdomains = inputGhostDomains.find('.subdomain'),
                inputGhostSpans = inputGhost.find('span'),
                inputGhostSubdomain = inputGhostSpans.eq(0),
                inputGhostDomain = inputGhostSpans.eq(1),
                inputArrow = inputSubdomain.siblings('.dd-arrow'),
                link_tt = inputSubdomain.parent().siblings('.link-tt');

            inputSubdomain.add(inputArrow).click(function(e){
                $('.domains').not(inputGhostDomains).hide();
                $.trim(inputSubdomain.val()) && ($(this).is('input') ? e.pageX > inputGhostDomain.offset().left : true) && inputGhostDomains.toggle();        
            }).keyup(function(){
                inputGhostSubdomain.add(inputGhostSubdomains).text(inputSubdomain.val());
                if($.trim($(this).val()) == ''){
                    inputGhost.css('visibility', 'hidden');
                    link_tt.add(inputArrow).css('display', 'none');
                    inputArrow.length && inputArrow.css('right', '3px');                
                }else{
                    inputGhost.css('visibility', 'visible');
                    link_tt.add(inputArrow).css('display', 'inline');
                    inputArrow.length && inputArrow.css('right', '2px');
                }
            });
            inputGhostDomains.children().click(function(){
                inputGhostDomain.text('.' + $(this).children('.domain').text());
                inputGhostDomains.hide();
                $('#domain').add('#domain-form').val($(this).children('.domain').text());
            });
        });
    
    var timeOutID = false;
    $('.link-tt').click(function(e){
        clearTimeout(timeOutID);
        e.preventDefault();
        var tooltip = $(this).children().show();
        timeOutID = setTimeout(function(){
            tooltip.hide();
        }, 6000);
        return false;
    });

	if(/#mlm-demo/.test(window.location.href)){
	    $("#apple").overlay({ mask: {color: '#000', loadSpeed: 200}, load: true});
	}
	else if(/#fran-demo/.test(window.location.href)){
        $("#apple").overlay({ mask: {color: '#000', loadSpeed: 200}, load: true});
	}
	else if(/#try/.test(window.location.href)){
        $("li.try-button a").trigger('click');
	}

    var distributorsField = $('#distributors'),
        distributorsOpts = distributorsField.siblings('.domains');
	distributorsField.add(distributorsField.siblings('.dd-arrow')).click(function(){
	    $('.domains').not(distributorsOpts).hide();
        distributorsOpts.toggle();
	});
	
	distributorsOpts.children().click(function(){
	    $(this).parent().hide();
	    distributorsField.val($(this).text());
	});

    $('.download-overlay').overlay({
        mask: '#000',
        loadSpeed: 200,
        load: false
    });
    $('.download-form-trigger').click(function(){
        $('.download-overlay').data("overlay").load();
    });

    $('.download-overlay').overlay({
        mask: '#000',
        loadSpeed: 200,
        load: false
    });


    $('.custom-cta').click(function(){
        $('.cta-overlay').data("overlay").load();
    });

    $('.cta-overlay').overlay({
        mask: '#000',
        loadSpeed: 200,
        load: false
    });
});

