(function ($) {
///////////////

function toggle_contact_form () {
    var me = $(this);
    var form = $('#contact-form');
    if (form.hasClass('visible')) {
        form.slideUp(500, function () {
            // make_full_height('#main-content', false);
        });
        form.removeClass('visible');
        me.removeClass('inactive');
    } else {
        form.slideDown(500, function () {
            // make_full_height('#main-content', true);
            $('html,body').animate({scrollTop: form.offset().top}, 200);
        });
        form.addClass('visible');
        me.addClass('inactive');
    }
    return false;
}


function self_label_focus () {
    var me = $(this);
    if (me.hasClass('default')) {
        me.removeClass('default');
        var def = me.val();
        me.val('');
        me.unbind('blur');
        me.blur(function () {
            if (!me.val()) {
                me.val(def);
                me.addClass('default');
            }
        });
    }
}

function max (x, y) {
    return (x > y) ? x : y;
}

function make_full_height (sel, force) {
    var el = $(sel);
    if (force) {el.css('height', '');}
    var targetHeight = max(document.body.scrollHeight, $(document.body).height());
    var newHeight = targetHeight - el.offset().top;
    if (el.length && (el.height() + el.offset().top) < targetHeight) {
        el.height(newHeight);
    }
}



$(function () {
    $('body#home #lifestyle-flash').flash({
        src: 'f/home.swf?v=2',
        width: 940,
        height: 390,
        wmode: 'opaque'
    });
    $('body#about #lifestyle-flash').flash({
        src: 'f/about.swf?v=1',
        width: 940,
        height: 390,
        wmode: 'opaque'
    });
    $('body#contact #lifestyle-flash').flash({
        src: 'f/contact.swf?v=1',
        width: 940,
        height: 390,
        wmode: 'opaque'
    });
    $('body#location #lifestyle-flash').flash({
        src: 'f/location.swf?v=2',
        width: 940,
        height: 390,
        wmode: 'opaque'
    });
    $('body#village #lifestyle-flash').flash({
        src: 'f/village.swf?v=1',
        width: 940,
        height: 390,
        wmode: 'opaque'
    });
    
    $('#sections-flash').flash({
        src: 'f/sections.swf?v=3',
        width: 938,
        height: 500
    });
    
    $('.self-label').focus(self_label_focus).addClass('default');
    
    $('.contact-form-link').click(toggle_contact_form);

    
    $.sifr({path: 'f/', font: 'precious', save: true, color: '#000', roY: '-3px'});
    $('#main-content h2').not('#architects h2').sifr({fontSize: '26px'});
		$('#pricing-subhead').sifr({fontSize: '26px', color: '#fff'});
    $('#architects #main-content h2').sifr({fontSize: '30px'});
    $('#main-content h3').sifr({fontSize: '19px'});
});

$(window).load(function () {
    make_full_height('#main-content', false);
});

$(window).resize(function () {
    make_full_height('#main-content', false);
});




///////////////
})($);
