jQuery(function(){

 $('#email').change(function() {
  $(this).setCursorPosition(0);
});


  jQuery('.pleaseworkcaptcha').click(function(){

    var $form = jQuery('#signup_email');
    var check = /^[\w\d._%+-]+@[\w\d.-]+\.[\w]{2,4}$/i.test($form.val());
    var captcha_form = jQuery('#waitlist-captcha').serialize();

    if(check){

        $.ajax({
            type: 'POST',
            url: "/login/ad_to_waitlist",
            data: captcha_form,
            error: function(){
                jQuery('.envelope').addClass('envelope2');
            },
            success: function(data){
                if(data == "true"){
                    jQuery('.envelope').addClass('envelope2');
                }else if(data == "wrong-captcha"){
                        jQuery('.captcha_question').html('<div style="color:red;font-weight:bold;">Wrong Captcha Entered</div>');
                        setTimeout("jQuery('.refresh_captcha').click();",8000);
                } else if(data == "false"){
                        jQuery('.captcha_question').html('<div style="color:red;font-weight:bold;">Already in waiting list</div>');
                        setTimeout("jQuery('.refresh_captcha').click();",10000);
                }else{
                    
                    jQuery('.invite_text').html('Already in waitling list');
                }
                parent.jQuery.fancybox.close();
            }

        });
    }else{
        jQuery('.captcha_question').html('<div style="color:red;font-weight:bold;">Please enter a valid email address</div>');
    }

  });

})


jQuery(function(){
    $("a.howitworksvideo").fancybox();

    $("a.opennewsitem").fancybox();
    jQuery('input').placeholder();
    jQuery('.invitebtn').click(function(){
        $('body').scrollTo( $('#signup_email'), 800 );
    });



    jQuery('#navigation li.links').click(function(){
														
        $openDropDown = jQuery(this).attr('alt');
						
        $activeDrop = $('#'+$openDropDown);
        if($activeDrop.is(':visible')){
            $activeDrop.hide();
        }else{
            $('.dropdown').hide();
            $activeDrop.show();
        }

    });

    jQuery('body').click(function(){
        $('.dropdown').hide();
    });



// Expanding functionality

     $('.p3readless').live('click',function(){
        var expand_n = $(this).attr('title');
        jQuery(this).addClass('p3readmore');
        jQuery(this).text('READ MORE');
        jQuery(this).removeClass('p3readless');
        $('#expand_'+expand_n).hide('slow');
        return false;
      });

      $('.p3readmore').live('click', function(){
        var expand_n = $(this).attr('title');
        jQuery(this).addClass('p3readless');
        jQuery(this).text('READ LESS');
        jQuery(this).removeClass('p3readmore');
        $('#expand_'+expand_n).show('slow');
        return false;
      });


$('.p3readlessbio').live('click',function(){
        var expand_n = $(this).attr('title');
        jQuery(this).addClass('p3readmorebio');
        jQuery(this).text('Read Bio');
        jQuery(this).removeClass('p3readlessbio');
        $('#expand_'+expand_n).hide('slow');
        return false;
      });

      $('.p3readmorebio').live('click', function(){
        var expand_n = $(this).attr('title');
        jQuery(this).addClass('p3readlessbio');
        jQuery(this).text('Less Bio');
        jQuery(this).removeClass('p3readmorebio');
        $('#expand_'+expand_n).show('slow');
        return false;
      });



				
});

new function($) {
  $.fn.setCursorPosition = function(pos) {
    if ($(this).get(0).setSelectionRange) {
      $(this).get(0).setSelectionRange(pos, pos);
    } else if ($(this).get(0).createTextRange) {
      var range = $(this).get(0).createTextRange();
      range.collapse(true);
      range.moveEnd('character', pos);
      range.moveStart('character', pos);
      range.select();
    }
  }
}(jQuery);

