$(document).ready(function() {
    //Select and show the first FAQ
    $('#answer1').css('display', 'block');
    $('.questionContainer a.question:first').addClass('active');

    //set up onClick event for FAQ navigation
    $('.questionContainer a.question').click(function() {
        //Hide all answers, then show only the one relating to the question selected
        $('.answerContainer').css('display', 'none');
        $($(this).attr("href")).css('display', 'block');

        //Remove active style from all questions, then add it to the one clicked
        $('.questionContainer a.question').removeClass(['active']);
        $(this).addClass('active');

        //Do not jump the page
        return false;
    });

    //Set height of all faq answer boxes
    $('.answerContainer').css('height', $('.faqContainer').height() - 40);

    //Set up onClick event for calculatorButton
    $('.calculatorButton').click(function() {
        _buildLightbox();

        $('#lightboxContent div').append('<iframe frameborder="0" scrolling="no" allowtransparency="true" src="calculator.aspx"></ifrmae>');

        $('iframe').css('height', '870px');
        $('iframe').css('width', '760px');

        $('#lightboxContentWrap').css('top', '610px');
        goToId('lightboxContentWrap');

        return false;
    });

});  

// ------------------------------------------------------------------------------------
function _buildLightbox() {
	$('body').append('<div id="lightboxOverlay"></div>');
	$('body').append('<div id="lightboxContentWrap"><div id="lightboxContent"><a class="close" href="javascript:_destroyLightbox()">Close</a><div></div></div></div>');
	$('#lightboxOverlay').click(function() {
		_destroyLightbox()
	});
	$('#lightboxContentWrap').click(function() {
		_destroyLightbox()
	});
};

// ------------------------------------------------------------------------------------
function _destroyLightbox() {
	$('#lightboxOverlay').remove();
	$('#lightboxContentWrap').remove();
};

// ------------------------------------------------------------------------------------
function goToIdOnReady(id) {
    $(document).ready(function(){    
        var target = $('#' + id)
        target = target.size() && target;
        if (target.size()) {
            var targetOffset = target.offset().top;
            $('html').animate({ scrollTop: targetOffset }, 0);
        };
    });
};
// ------------------------------------------------------------------------------------
function goToId(id) {
    var target = $('#' + id)
    target = target.size() && target;
    if (target.size()) {
        var targetOffset = target.offset().top;
        $('html').animate({ scrollTop: targetOffset }, 0);
    };
};
// ------------------------------------------------------------------------------------

Cufon.replace('.mainInner h2, .headerInner p, .calculator li, .headerInner .headerNav a span.tab', { fontFamily: 'futura-condensed' });

