/* ------------------------------------------------------------------------

Title:      Pearson Free Agent JavaScript (behavior) file
Filename:   main.js
Method:     <link>
Author:     Bob Prokop | bobprokop@yahoo.com
Updated:    January 2010
Notes:      ...		

------------------------------------------------------------------------- */
$(document).ready(function() {

    //--- generic replace function ---//
    $.fn.replaceWith = function(html) {
        return this.after(html).remove();
    };

    //--- preload images files ---//
    //$.preloadCssImages();

    /* FAQ expand */
    if (document.getElementById('faq')) {
        // open~close single question //
        $('#faq dt').click(function() {
            $(this).toggleClass('open');
            $(this).next().slideToggle('fast');
        });
        // open~close all questions //
        var isToggled = false;
        $('#toggle-faq').click(function() {

            if (isToggled == false) {
                $(this).addClass('open');
                $(this).html('Hide all');
                isToggled = true;
                $('#faq dt').addClass('open');
                $('#faq dt').next().show('fast');
            }
            else {
                $(this).removeClass('open');
                $(this).html('Show all');
                isToggled = false;
                $('#faq dt').removeClass('open');
                $('#faq dt').next().hide('fast');
            }
            return false;
        });
    }

    // need to bind the smooth scroll function to any existing or newly created hrefs w/matching rel value //
    $('a[rel=anchor]').live("click", function() {
        var full_url = this.href;
        var parts = full_url.split("#");
        var trgt = parts[1];
        var target_offset = $("#" + trgt).offset();
        var target_top = target_offset.top;
        $('html, body').animate({ scrollTop: target_top }, 500);
        return false;
    });

    //--- movie gallery slider carousel ---//    
    $(function() {
        $('#fp').cycle({
            fx: 'scrollVert',
            delay: -1000,
            speed: 250,
            timeout: 6000,
            pause: true,
            prev: '#prevproj',
            next: '#nextproj',
            before: onBeforeFP
        });
        function onBeforeFP() {
            $('#fp dl.notfirst').removeClass('notfirst');
        }
    });

    $('input.clearText').focus(function() {

        $(this).addClass('hover');
        if (this.value == this.defaultValue) {
            this.value = '';
        }
    });
    
    $('input.clearText').blur(function() {
        $(this).removeClass('hover');
        if (this.value == '') {
            this.value = this.defaultValue;
            $(this).removeClass('selected');
        }
        else {
            $(this).addClass('selected');
        }
    });

});

function hideOverlay() {
    $('#serverStatus').fadeOut();
}
function showOverlay() {
    $('#serverStatus').height(getheight()).width(getwidth()).show();

}
function getheight() {
    var e = Math.max(document.documentElement.scrollHeight, document.body.scrollHeight);
    var d = Math.max(document.documentElement.offsetHeight, document.body.offsetHeight);
    if (e < d) {
        return window.height() + "px"
    } else {
        return e + "px"
    }
}

function getwidth() {
    var e = Math.max(document.documentElement.scrollWidth, document.body.scrollWidth);
    var d = Math.max(document.documentElement.offsetWidth, document.body.offsetWidth);
    if (e < d) {
        return window.width() + "px"
    } else {
        return e + "px"
    }
} 