﻿soundManager.url = 'swf/';
var PP_CONFIG = {
    flashVersion: 9,       // version of Flash to tell SoundManager to use - either 8 or 9. Flash 9 required for peak / spectrum data.
    usePeakData: true,     // [Flash 9 only] whether or not to show peak data (left/right channel values) - nor noticable on CPU
    useWaveformData: false, // [Flash 9 only] show raw waveform data - WARNING: LIKELY VERY CPU-HEAVY
    useEQData: false,      // [Flash 9 only] show EQ (frequency spectrum) data
    useFavIcon: false,     // try to apply peakData to address bar (Firefox + Opera) - performance note: appears to make Firefox 3 do some temporary, heavy disk access/swapping/garbage collection at first(?) - may be too heavy on CPU
    useMovieStar: true,     // Flash 9.0r115+ only: Support for a subset of MPEG4 formats.
    durationEstimateConst :true
};

function pageload(hash) {
    if (hash)
        changeContent(hash);
    else changeContent('home');
}


function ShowPanels(hash)
{
    if ($("#" + hash.toLowerCase())) {
        var panels = $("#RegisterForm").find('#' + hash.toLowerCase()).val().split(',');
        $("#Right").children().hide();
        $("#Left").children().hide();
        $("#Left").hide();
        $("#Right").hide();
        for (var i = 0; i < panels.length; i++)
            if (panels[i] != "") {
                $("#" + panels[i]).parent().show();
                $("#" + panels[i]).parent().parent().show();
                if ($("#" + panels[i]).parent().parent().attr("id") == "Left")
                    $("#Left").find('.ContentFooter').show();  
                else
                     $("#Right").find('.ContentFooter').show();  
              }
    }
};

$(document).ready(function () {

    $(".MediaPlayerButtonEMail").click(function () {
        if ($(this).attr("isExistScripture") == 'True') {
            $.fancybox.showActivity();
            $.ajax({
                type: "POST",
                cache: false,
                url: "ScriptureList.aspx?DoctrineID=" + $(this).attr("DoctrineID"),
                data: $("#RegisterForm").serializeArray(),
                success: function (data) {
                    $.fancybox(data);
                    $(".PrintButton").click(function () {
                        $(".ScriptureListBody").printElement({
                            overrideElementCSS: ['Css/PrintStyle.css']
                        });
                    });
                }
            });
        }
        return false;
    });

    $.history.init(pageload);

    $('#StreemMenu').click(function (e) {

        if (allUIMenus[allUIMenus.length - 1].menuOpen == true)
            allUIMenus[allUIMenus.length - 1].kill();
        else {

            var menuitems = $('#MenuUI').children(); //  $(document).find('li').attr('role', 'menuitem').filter(":visible");
            var top = 0;
            //  if ($.browser.msie)
            top = (menuitems.length - 1) * 23 + 40;
            //  else
            //      top =  30;
            $('#flat').newmenu({
                content: $('#flat').next().html(), // grab content from this page
                width: 85,
                positionOpts: { posX: 0, posY: 0,
                    offsetX: 105,
                    offsetY: top
                },
                showSpeed: 0
            });
            allUIMenus[allUIMenus.length - 1].showLoading();
            allUIMenus[allUIMenus.length - 1].showMenu();
        }

        return stopEvent(e);
    });
    $('#flat').menu({
        content: $('#flat').next().html(), // grab content from this page
        maxHeight: 180,
        positionOpts: { posX: 0, posY: 0, offsetX: 0, offsetY: 0 },
        showSpeed: 400
    });


    DownLoadButtonFancyBox();
    $("#SignInLink").click(function () {

        changeContent("#Register");
        $.fancybox.close();
    });
    $("#EMailLogin").keypress(function () {

        $(".InvalidText").hide();
    });



    $("#ctl00_ContentPlaceHolder1_SignIn").click(function () {
        switch ($("#ctl00_ContentPlaceHolder1_SignIn").text()) {
            default:
                changeContent("register");
                break;
            case "Sign In":
                $.fancybox({
                    'scrolling': 'no',
                    'titleShow': false,
                    'href': '#login_form',
                    'onClosed': function () {
                        $(".InvalidText").hide();
                    }
                });
                break;
        }
        return false;
    });

    $(".FeaturedPlayListLink").click(function () {
        return PlayDoctine($(this).text(), $(this).attr('DoctrineID'), $(this).attr('URL'), 0, true, $(this).attr('Time'), $(this).attr('isExistScripture'));
    });
    $(".FeaturedMediaListLink").click(function () {
        return PlayDoctine($(this).find('.Title').text(), $(this).attr('DoctrineID'), $(this).attr('URL'), 0, true, $(this).find('.Time').text(),
             $(this).attr('isExistScripture'));
    });


    LoadFirstFeaturedAudioToPlayer();

    $('.ScriptureReference').mouseover(function () {
        var f = $(this);
        clearTimeout(JTDelay);
        JTDelay = setTimeout(function () {
            var height = 0;
            JT_show('ShowVerseBlog.aspx?IndicatorFrom=' + f.attr('IndicatorFrom') + '&IndicatorTo=' + f.attr('IndicatorTo') + '&width=320',
                f.attr('id'), f.attr('BookName'), f.position().top - height);
        }, 1000);
    });


    $('.ScriptureReference').mouseout(function () {
        clearTimeout(JTDelay);
        JTDelay = setTimeout(function () {
            JTClose();
        }, 100);
    });
    $('.ScriptureReference').click(function () {
        JTClose();

    });


    $(".Gray").each(function () {
        $(this)[0].DefaultValue = $(this).val();
    });

    $(".SearchScriptures").keypress(function () {
        if ($(this).val() == $(this)[0].DefaultValue) {
            $(this).removeClass("Gray");
            $(this).val('');
        }
    });


    $(".SearchScriptures").focus(function () {
        if ($(this).val() == $(this)[0].DefaultValue) {
            $(this).removeClass("Gray");
            $(this).val('');
        }
    });

    $(".Gray").blur(function () {
        if ($(this).val() == '') {
            $(this).addClass("Gray");
            $(this).val($(this)[0].DefaultValue);
        }
    });

    $("#GoSearch").click(function () {
        if ($(".SearchScriptures").val() != '')
            if ($(".SearchScriptures").val() != $(".SearchScriptures")[0].DefaultValue)
                $.history.load("Scriptures/SearchKey/" + $(".SearchScriptures").val());
    });

    $(".SearchScriptures").keypress(function (e) {
        if (e.keyCode == 13) {
            $("#GoSearch").trigger('click');
            return false;
        }
        return true;
    });
    $("#reset_passwordlink").fancybox({
        'scrolling': 'no',
        'titleShow': false,
        'onStart': function () {
            $(".InvalidText").hide();
            $("#LoginPassword").val('');
        },
        'onClosed': function () {
            $(".InvalidText").hide();
            $("#LoginPassword").val('');
        }
    });
    $("#reset_password").bind("submit", function () {
        $(".InvalidText").hide();
        $.fancybox.showActivity();
        $.ajax({
            type: "POST",
            cache: false,
            url: "ResetPassword.aspx",
            data: $(this).serializeArray(),
            success: function (data) {
                var status = NodeValue(data.getElementsByTagName('status')[0]);
                $("#fancybox-loading").hide();
                switch (status) {
                    case "success":
                        $(".InvalidText").hide();
                        var message = NodeValue(data.getElementsByTagName('message')[0]);
                        alert(message);
                        $.fancybox.close();
                        break;
                    case "Invalid":
                        var message1 = NodeValue(data.getElementsByTagName('message')[0]);
                        $(".InvalidText").show();
                        $(".InvalidText").text(message1);
                        $("#MemberEmailAddress").addClass("InvalidData");

                        $.fancybox.resize();
                        break;
                    case "Error":
                        $(".InvalidText").hide();
                        var message2 = NodeValue(data.getElementsByTagName('message')[0]);
                        alert(message2);
                        break;
                }
            },
            error: function () {
                alert('error');
            }
        });
        return false;
    });


    $("#login_form").bind("submit", function () {
        if ($("#EMailLogin").val().length < 1 || $("#Password").val().length < 1) {
            $(".InvalidText").show();
            $(".InvalidText").text('You must enter a username and password');
            $.fancybox.resize();
            return false;
        }

        $(".InvalidText").hide();
        $.fancybox.showActivity();

        $.ajax({
            type: "POST",
            cache: false,
            url: "Login.aspx",
            data: $(this).serializeArray(),
            success: function (data) {
                $("#fancybox-loading").hide();
                var status = NodeValue(data.getElementsByTagName('status')[0]);
                switch (status) {
                    case "success":
                        var username = NodeValue(data.getElementsByTagName('username')[0]);
                        $("#ctl00_ContentPlaceHolder1_Audience").val(NodeValue(data.getElementsByTagName('audience')[0]));

                        $("#ctl00_ContentPlaceHolder1_SignIn").text(username);
                        $("#ctl00_ContentPlaceHolder1_SignIn").attr("href", "#Register");
                        $("#ctl00_ContentPlaceHolder1_SignUp").text("Sign Out");
                        $("#ctl00_ContentPlaceHolder1_SignUp").attr("href", "#");
                        $("#LoginPassword").val('');
                        $.fancybox.close();
                        $.history.load((currenthash == '#' || currenthash == '') ? "home" : currenthash.replace(/^.*#/, '').replace('/ShowLogin', ''));

                        break;
                    case "Invalid":
                        var message = NodeValue(data.getElementsByTagName('message')[0]);
                        $(".InvalidText").show();
                        $(".InvalidText").text(message);
                        $("#MemberName").addClass("InvalidData");
                        $("#Password").addClass("InvalidData");
                        $("#ctl00_ContentPlaceHolder1_SignIn").attr("href", "#login_form");
                        $.fancybox.resize();
                        break;
                }

                //$.fancybox(data);
            },
            error: function () {
                alert('error');
            }
        });

        return false;
    });
    $(".MasterPageHeaderMenuItem").click(function () {
        var hash = this.href;
        hash = hash.replace(/^.*#/, '');
        $.history.load(hash);

        return false;
    });
    $("#ctl00_ContentPlaceHolder1_SignUp").click(function () {
        switch ($("#ctl00_ContentPlaceHolder1_SignUp").text()) {
            case "Register":
                changeContent("register");
                break;
            case "Sign Out":
                $.ajax({
                    type: "POST",
                    url: "logout.aspx",
                    success: function () {
                        $("#ctl00_ContentPlaceHolder1_SignIn").text("Sign In");
                        $("#ctl00_ContentPlaceHolder1_SignUp").text("Register");
                        $("#ctl00_ContentPlaceHolder1_SignUp").attr("href", "#Register");
                        $("#ctl00_ContentPlaceHolder1_Audience").val("1");
                        $.history.load((currenthash == '#' || currenthash == '') ? "home" : currenthash.replace(/^.*#/, ''));
                    }
                });
                break;
        }
    });
});

