﻿$(document).ready(function () {


    /* This is for the Broker and Investor login boxes that have the tabbing option. Lives primarily on the homepage. Uses the jquery ui tabs plugin. */
    $('#tabbed-login').tabs();

    /* This is so each column in the footer sitemap has the same height to allow for the border on either side of the item to be the exact lenght. */
    var sitemapMaxHeight = 0;
    var sitemapHeight = 0;

    $('nav.sitemap > ul > li').each(function (i, n) {
        sitemapHeight = $(n).height();
        if (sitemapMaxHeight < sitemapHeight) {
            sitemapMaxHeight = sitemapHeight;
        }
    });

    $('nav.sitemap > ul').height(sitemapMaxHeight);
    $('nav.sitemap > ul > li').height(sitemapMaxHeight);

    /* This if for the header for profiles. Hides and shows the text above images. */
    $('.demo-header li').hover(function () {
        $(this).children('.caption').fadeIn('slow');
    }, function () {
        $(this).children('.caption').fadeOut('slow');
    });


    /* This is the accordian functionality primarily for FAQs. */
    $('.accordian .head').click(function () {
        $(this).next().toggle();
        return false;
    }).next().hide();

    $('.accordian .collapsible-area').hide();

    $('.accordian').bind('click', function (e) {
        var t = $(e.target);
        if (t && t.is("h3")) {
            if (t.next('.collapsible-area:visible').length > 0) {
                t.removeClass('current').next('.collapsible-area').hide();
            } else {
                t.addClass('current').next('.collapsible-area').show();
            }
        }
    });

    /* Gives appropriate classes to parts within a table element. */
    $('table').each(function (i, n) {
        $(n).find('tbody tr:odd').addClass('even');
        $(n).find('tbody tr :first-child').addClass('first');
        $(n).find('tbody tr :last-child').addClass('last');
    });



    //$('a.open-certificate').bind('click', openCert);

    

    //new carousel
    $("div.carousel").carousel(
        {
            pagination: true,
            loop: true, 
            autoSlide: true,
            autoSlideInterval:6000
        }
    );

});

function openCert(name, date) {
    $('body').append('<div class="overlay-background"></div><div class="overlay-content"></div>');

    var documentWidth = $(document).width();
    var documentHeight = $(document).height();
    var windowWidth = $(window).width();
    var windowHeight = $(window).height();
    var windowScroll = $(window).scrollTop();


    $('.overlay-background')
			.css({ 'width': documentWidth, 'height': documentHeight, 'position': 'absolute', 'top': '0', 'left': '0', 'background-color': '#000', 'z-index': 99 })
			.fadeTo(0, 0.5)
			.click(function () {
			    $('.overlay-background').remove();
			    $('.overlay-content').remove();
			    window.location.assign("../financepartners");
			    //$(window).scrollTop(windowScroll);
			});

    $('.overlay-content')
			.css({ 'width': '500px', 'height': '730px', 'padding-top': '10px', 'position': 'absolute', 'top': '30px', 'left': '50%', 'margin-left': '-235px', 'background-color': '#fff', 'z-index': 999 })
			.append('<iframe src="/FinancePartnerSignup/CertificateSmall?date=' + date + '&name=' + name + '" border="0" height="730px" width="500px" style="border: 0 none;"></iframe><p style="text-align: left; margin-top: -30px; padding-left: 75px;"><a href="../documents/accreditation-certificates/' + name + '.pdf" target="_blank">Save Certificate</a> | <a href="/FinancePartnerSignup/CertificatePrint?date=' + date + '&name=' + name + '" target="_blank">Print Certificate</a> | <a href="#" class="close">Close Window X</a></p>');

    $('.overlay-content .close').click(function () {
        $('.overlay-background').remove();
        $('.overlay-content').remove();
        window.location.assign("../financepartners");
        return false;
    });

    $(window).scrollTop(0);

    return false;
}
