﻿$(document).ready(function() {
    $(".expandBox .title a").toggle(
        function() {
            $(this).parents(".expandBox:first").children(".description").slideDown(250);
            $(this).text("Less").addClass("up");

            return false;
        },
        function() {
            $(this).parents(".expandBox:first").children(".description").slideUp(250);
            $(this).text("More").removeClass("up");

            return false;
        }
    );

    $(".archiveBox .title a").toggle(
        function() {
            $(this).parents(".archiveBox:first").children(".description").slideDown(250);
            $(this).parents(".title:first").children(".more").addClass("up");

            return false;
        },
        function() {
            $(this).parents(".archiveBox:first").children(".description").slideUp(250);
            $(this).parents(".title:first").children(".more").removeClass("up");

            return false;
        }
    );

    $(".tabbedContent").tabs();

    $(".photoBrowser .buttonsWrap a.lnkPrevious").click(function() {
        var $prev;

        if ($(".photoBrowser .photoFrame.visible").is(":first-child"))
            $prev = $(".photoBrowser .photoFrame:last");
        else
            $prev = $(".photoBrowser .photoFrame.visible").prev();

        $(".photoBrowser .photoFrame.visible").removeClass("visible");
        $prev.addClass("visible");

        return false;
    });

    $(".photoBrowser .buttonsWrap a.lnkNext").click(function() {
        var $next;

        if ($(".photoBrowser .photoFrame.visible").is(":last-child"))
            $next = $(".photoBrowser .photoFrame:first");
        else
            $next = $(".photoBrowser .photoFrame.visible").next();

        $(".photoBrowser .photoFrame.visible").removeClass("visible");
        $next.addClass("visible");

        return false;
    });

    if (jQuery().fancybox) {
        $("a.fancybox").fancybox({
            'zoomSpeedIn': 300,
            'zoomSpeedOut': 300
        });
    }

    $("#mapDialog").dialog({
        autoOpen: false,
        title: 'Renaissance Services SAOG - Location Map',
        width: 924,
        height: 574,
        resizable: false,
        draggable: false,
        modal: true
    });

    $(".rightPane .contentText div.mapWrap").click(function() {
        $('#mapDialog').dialog('open');
    });

    $(".question a").toggle(
        function() {
            $(this).parents(".faqWrap:first").children(".answer").slideDown(250);

            return false;
        },
        function() {
            $(this).parents(".faqWrap:first").children(".answer").slideUp(250);

            return false;
        }
    );

    $("#ifrmCharts").load(function() {
        $('.divLoading').hide(5);
    });

    $(".cbSubscribeAll :checkbox").change(function() {
        if ($(this).is(':checked'))
            $(".cblSubscriptionCategories :checkbox").attr('checked', true);
        else
            $(".cblSubscriptionCategories :checkbox").attr('checked', false);
    });

    $(".cblSubscriptionCategories :checkbox").change(function() {
        if (!$(this).is(':checked'))
            $(".cbSubscribeAll :checkbox").attr('checked', false);
    });

    $("#rssInfo").toggle(
        function() {
            $(".infoMsg").slideDown(250);

            return false;
        },
        function() {
            $(".infoMsg").slideUp(250);

            return false;
        }
    );

    $(".rightPane .contentText > p:first:not(.notFirst)").addClass("first");
});

