$(document).ready(function()  
{  
    /* font substitution */
    Cufon.replace('h1, h2, #navigation', { fontFamily: 'gothambook', hover: true });
    Cufon.replace('div#quote h1, #footer', { fontFamily: 'gothamlight', hover: true });
    
    /* remember web address */
    var current_url = window.location.pathname;
    $('a[href='+current_url+']').addClass('active');
    
    $('.client-folder a').hover(function(){
        $(this).children('span.highlight').css({display: 'inline-block'});
        
    }, function(){
        $(this).children('span.highlight').hide();
    });
    var index = 0;  
    var images = $("#gallery img");  
    var thumbs = $("#thumbs img");
    var imgHeight = thumbs.attr("height");
    thumbs.slice(0,3).clone().appendTo("#thumbs");
    for (i=0; i<thumbs.length; i++)  
    {  
        $(thumbs[i]).addClass("thumb-"+i);  
        $(images[i]).addClass("image-"+i);  
    }  
  
    $("#next").click(function() {
        sift();
        return false;
    });
    show(index);  
    setInterval(sift, 8000);  
  
    function sift()  
    {
        var max_offset = thumbs.length - 1
        if (index < max_offset)
            index += 1;
        else
            index = 0;
        show(index);
    }  
  
    function show(num)  
    {  
        $(images).fadeOut(400);  
        $(".image-"+num).stop().fadeIn(400);  
        var scrollPos = (num + 1) * imgHeight;
        $("#thumbs").stop().animate({scrollTop: scrollPos}, 400);
    }
    
    $('#id_name, #id_email, #id_message').focus(function() {
        if (this.value == this.defaultValue)
            this.value = '';
        else
            this.select();
        $('#error-message').empty().hide();
    });
    
    $('#id_name, #id_email, #id_message').blur(function() {
        if ($.trim(this.value) == '')
            this.value = (this.defaultValue ? this.defaultValue : '');
    });
    
    $('#send').click(function() {
        $('#error-message').hide();
        var name = document.getElementById('id_name');
        var email = document.getElementById('id_email');
        var message = document.getElementById('id_message');
        var regex = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;
        
        if ($('#id_name').val() == '' || $('#id_name').val() == name.defaultValue) {
            $('#error-message').empty().append('Please let us know your name').show();
            return false;
        }
        
        else if ($('#id_email').val() == '' || $('#id_email').val() == email.defaultValue) {
            $('#error-message').empty().append('Please let us know your e-mail address').show();
            return false;
        }
        else if (!regex.test(email.value)) {
            $('#error-message').empty().append('Your e-mail address seems to be wrong').show();
            return false;
        }
        
        else if ($('#id_message').val() == '' || $('#id_message').val() == message.defaultValue) {
            $('#error-message').empty().append('What do you want to ask us about?').show();
            return false;
        }
        
        else {
            $('#send').addClass("disabled");
            $('#contact-form').submit();
        }
    });
});  

