/* Declare a namespace for the site */
var Site = window.Site || {};

/* Create a closure to maintain scope of the '$'
   and remain compatible with other frameworks.  */


(function($) {
	
	var height = $(this).attr("innerHeight")-100;
	
	//same as $(document).ready();
	$(function() {
		
        // Quick hide extra content for testimonials
        $('.more').each(function() {
            $(this).wrapInner('<div class="more" style="display: none" />');
            
            $('<a class="open" href="#"><b>+</b>more...</a>').prependTo($(this));
        });

        $('a.open').live('click', function(event){ // Need live() b/c element non-existent @ doc.ready()
		    event.preventDefault();
		    $(this).siblings('.more').slideDown();
            $(this).addClass('close');
            $(this).removeClass('open');
            $(this).html('<b>-</b>close');
        });

        $('a.close').live('click', function(event){ // Need live() b/c element non-existent @ doc.ready()
		    event.preventDefault();
		    $(this).siblings('.more').slideUp();
            $(this).addClass('open');
            $(this).removeClass('close');
            $(this).html('<b>+</b>more...');
        });

	    // http://www.hagenburger.net/BLOG/HTML5-Input-Placeholder-Fix-With-jQuery.html
        $('[placeholder]').focus(function() {
          var input = $(this);
          if (input.val() == input.attr('placeholder')) {
            input.val('');
            input.removeClass('placeholder');
          }
        }).blur(function() {
          var input = $(this);
          if (input.val() == '') {
            input.addClass('placeholder');
            input.val(input.attr('placeholder'));
          }
        }).blur();
        
        $('[placeholder]').parents('form').submit(function() {
          $(this).find('[placeholder]').each(function() {
            var input = $(this);
            if (input.val() == input.attr('placeholder')) {
              input.val('');
            }
          })
        });

        // http://trevordavis.net/blog/ajax-forms-with-jquery/
        $("#signup #submit").click(function(){		
            $(".error").hide();
            var hasError = false;
            var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
            
            var emailFromVal = $("#email").val();
            if(emailFromVal == '') {
                $("label[for=email]").html('<b>Missing email.<'+'/b>');
                hasError = true;
            } else if(!emailReg.test(emailFromVal)) {	
                $("label[for=email]").html('<b>oops! email looks wrong<'+'/b>');
                hasError = true;
            }
                    
            var caught = $("#honey").val();
            if(caught !== '') {
                $("label[for=email]").html('<b>Something went wrong. Please <a href="">reload this page.</'+'a><'+'/b>');
                hasError = true;
            }
            
            if(hasError == false) {
                $(this).hide();
                // skip this $("#sendEmail li.buttons").append('<img src="/wp-content/themes/default/images/template/loading.gif" alt="Loading" id="loading" />');
                var signupform = $.loc.path+"_/signup.php";
                $.post(signupform,
                    { emailFrom: emailFromVal },
                        function(data){
                            $("#signup fieldset").fadeOut("fast", function() {				   
                                
                                $("#signup").html('<p><strong>Thank you</strong> for signing up to our newsletter!</p>');											
                            });
                        }
                     );
            }
            
            return false;
        });						   
    
        $("a[rel=definition]").click(function(e){
            e.preventDefault();
            return false;
        });						   

       $("a[rel=definition]").hover(
           function(){
                var def = $(this).attr('href');
                $(def).css('background','#ffc');
            },
           function(){
                var def = $(this).attr('href');
                $(def).css('background','none');
            }        
        );						   

 /*
        $('#surveylink').click(function (e, callback) {
            e.preventDefault();
            $('#survey').append('<div id="surveyframe" style="height: '+height+'px"><'+'/div>');
            $('#surveyframe').modal();
            $('#surveyframe').append('<iframe frameborder="0" height="'+height+'"><'+'/if'+'rame>');
            $('#surveyframe iframe').attr('src', 'http://www.surveygizmo.com/s3/iframe/365112/3591aed9e6a4');
            
            $('#surveyframe iframe').load(function() {
               callback(this); 
            });
            
              return false;
        });
*/
	});


	$(window).bind("load", function() {
	});
	
})(jQuery);


