var windowHeight = $(window).height();


$(document).ready(function(){
    $('#contentHeading h2, h3.homeEntryTitle').each( function() { FLIR.replace(this); } );
    $('.services .toggleDesc').click(function(){
        var description = $(this).parents('.entry').find('.serviceDescription');
        $(this).find('span.sign').text(description.is(':visible')?'[+]':'[-]');
        description.slideToggle('fast');
        return false;
    });
    
    $('a.panelLink').colorbox({inline:true});
    /*
    $('.panelLink').click(function(){
        var pName = $(this).attr('rel');
        $('#popupForms .bottomPanel:visible:not(#'+pName+')').hide('fast');
        $('#popupForms #'+pName+'Panel').toggle('normal', function(){
            if ($(this).is(':visible')) {
                $(this).find('input:visible:first').focus();
            }
        });
        return false;
    });
    */
    
    $('.bottomPanel form').keyup(function(e){
        if (e.keyCode == 27) {
            $(this).parents('.bottomPanel').fadeOut('fast');
        }
    });
    
    $('.bottomPanel .closeButton').click(function(){
        $(this).parents('.bottomPanel').hide('normal');
        return false;
    });
    
    $('#popupForms #contactPanel form').validate({
        submitHandler : function(form) {
            $(form).ajaxSubmit({
                dataType : 'json',
                success  : function(data){
                    if (data) {
                        alert(data.message.replace('<br />', '\n'));
                    } else {
                        alert('Something happened, please reload the page and try again.');
                    }
                    $('#popupForms #contactPanel').hide('normal')
                        .find('form').each(function(){this.reset()});
                }
            });
            return false;        
        }
    });
    
});