$(document).ready(function () {
    jQuery.extend(jQuery.easing, {
        ease: function (x, t, b, c, d) {
            if ((t /= d / 2) < 1) return c / 2 * t * t + b;
            return -c / 2 * ((--t) * (t - 2) - 1) + b;
        }
    });

    $('#dchbox-close').mouseover(function () { //mouseover the close button
        $(this).stop().animate({
            'opacity': 0.55
        }, 350);
    }).mouseout(function () { //mouseout the close button
        $(this).stop().animate({
            'opacity': 1.0
        }, 350);
    });

    $('.iframe').click(function () {
        $('html, body').animate({ scrollTop: 0 }, 0);
        iframeLoc = $(this).attr("href");

        loadIframe(iframeLoc);

        return false; //stop the href
    });
    /** STOP CUSTOM LIGHTBOX CODE **/
});


function DCHclose() { //you clicked close eh...?
    $('.dchBox,.dchBoxOverlay').stop().animate({ //fade out the dchbox and adjust height accordingly
        opacity: 0.0
    }, 550, function () { //once the animation finishes
            $('.dchBox', top.document).css({ 'display': 'none', 'opacity': 0.00 }); //display none again
            $('.dchBoxOverlay', top.document).css({ 'display': 'none', 'opacity': 0.00 }); //display none again
            $('.dchBox').remove();
            $('.dchBoxOverlay').remove();
        });
}

$(document).keyup(function (e) {
    if (e.which == 27) {
        DCHclose();
    }


});

function loadIframe(iframeLoc) {
    $("body").append('<div class="dchBoxOverlay"></div>');
    $("body").append('<div class="dchBox"><div class="innerBox"><a href="javascript:DCHclose();" id="dchbox-close"><img src="images/overlay-close.gif" alt="Close" align="right" border="0" width="24" height="24" /></a><iframe src="' + iframeLoc + '" frameborder="0" scrolling="no"></iframe></div></div>');

    if ($('.dchBox').css('display') == 'none') { //if the dchbox display is none
        $('.dchBox').css({ 'display': 'block', 'opacity': 0.00 }); //display block
        $('.dchBoxOverlay').css({ 'display': 'block', 'opacity': 0.00, 'height': $(document).height() }); //display block

        $('.dchBoxOverlay').animate({ //fade non-important divs
            opacity: 0.75
        }, 550);

        $('.dchBox').stop().animate({ //fade in and adjust height of dchbox
            height: 500,
            opacity: 1.0
        }, 550, 'ease');

    } else { //otherwise...
        $('.dchBox,.dchBoxOverlay').stop().animate({ //fade out the dchbox and adjust height accordingly
            opacity: 0.0
        }, 550, 'ease', function () { //once the animation finishes
            $('.dchBox').css({ 'display': 'none', 'opacity': 0.00 }); //display none again
            $('.dchBoxOverlay').css({ 'display': 'none', 'opacity': 0.00 }); //display none again
            $('.dchBox').remove();
            $('.dchBoxOverlay').remove();
        });
    }
}
