// jQuery no conflict mode.
var $j = jQuery.noConflict();

function clickclear(thisfield, defaulttext)
{
    if (thisfield.value == defaulttext) {
        thisfield.value = "";
    }
}

function clickrecall(thisfield, defaulttext)
{
    if (thisfield.value == "") {
        thisfield.value = defaulttext;
    }
}

$j(document).ready(function() {
        
    // Client login click event.
    $j("#client-login").fancybox({
        'width'				: '60%',
        'height'			: '75%',
        'autoScale'     	: false,
        'transitionIn'		: 'none',
        'transitionOut'		: 'none',
        'type'				: 'iframe'
    });
    
    // Back to top click event.
    $j('a.top').click(function(){
        $j.scrollTo(0, 600);
        return false;
    });
    
    // Newsletter sign up button (in footer) click event.
    $j('a.newsletter-signup').click(function(){
        $j.scrollTo('#newsletter-signup-box', 600, {offset: {top:-30}});
        setTimeout(function() { $j('#newsletter-signup-box').glow('#333333', 600, 200); }, 600);
        return false;
    });
    
    // Load the tweets.
    $j.ajax({
        type: "GET",
        url: "http://twitter.com/statuses/user_timeline/263591218.json",
        dataType: 'jsonp',
        success: function(jsonData){
        $j('#lgtweetlist').html("");
            var i = 1;
            $j.each(jsonData, function(key, value) { 
                $j('#tweet').html(ify.clean(jsonData[key].text));
                if (i == 1){
                    return false;
                }
                i++;
            });
        }
    });
    
    $j('#recaptcha_widget_div').prepend('<div class="error">Ensure you have entered the two words below.</label>');
    
    // Move the ReCaptcha element to whichever form the user is focused on.
    $j("input, textarea").focus(function(){
        var parentForm = $j(this).parent('form');
        if ($j(parentForm).hasClass('active-form')){
            // Do nothing.
        }else{
            $j(parentForm).addClass('active-form');
            $j("#recaptcha_widget_div").appendTo('#' + parentForm.attr('id') + ' .captcha-wrapper');
        }
    });
    
    
    // Validate the footer contact form.
    $j("#contact-form-footer").validate();
    
    // Validate the arrange a review contact form.
    $j("#contact-form-review").validate();
    
    // Validate the "contact" contact form.
    $j("#contact-form-review").validate();
    
    
});
