﻿/* TheQuran.com */

// User Master Page scripts //

var isWidgetPaneVisible = true;

$(document).ready(function () {

    $('a[href=#top]').click(function () {
        $('html, body').animate({ scrollTop: 0 }, 'slow');
        return false;
    });

    $('a[href=#top]').click(function () {
        $('html, body').animate({ scrollTop: 0 }, 'slow');
        return false;
    });

    var selectedCulture = '<%: ((System.Globalization.CultureInfo)HttpContext.Current.Session["Culture"]).Name %>';
    if (selectedCulture != '') {
        $(".subLang").hide();
        $(".subLang").each(function () {
            if ($(this).attr('value') == selectedCulture) {
                $(this).show();
                $("#selectedLanguage").attr('value', selectedCulture);
            }
        });
    }

    $(".subLang").click(function () {
        if ($("#selectOnOff").attr('value') == '0') {
            $(".subLang").show();
            $("#selectOnOff").attr('value', '1');
        } else {
            $(".subLang").hide();
            $("#selectOnOff").attr('value', '0');
            $(this).show();
            var elementId = $(this).attr('value');
            $("#selectedLanguage").attr('value', elementId);
            document.location = "/Localization/ChangeCulture/" + $(this).attr('value') + "/<%: this.Request.RawUrl.ToString().Replace('/', '-') %>";
        }
    });

    $("#submitLogin").click(function (e) {
        e.preventDefault();
        document.forms["form1"].action = "/User/Login";
        document.forms["form1"].submit();
    });

    //            $("#submitSearch, #searchSubmit").click(function (e) {
    //                e.preventDefault();
    //                search();
    //            });
    //            $("#searchBoxOne, #searchBoxTwo").keydown(function (e) {
    //                if (e.keyCode == 13) {
    //                    e.preventDefault();
    //                    search();
    //                }
    //            });

    //            $("#searchBoxOne").keyup(function () {
    //                if ($(this).val() != '') {
    //                    $("#searchBoxTwo").val($(this).val());
    //                    $("#SearchCriteria").val($(this).val());
    //                }
    //            });

    //            $("#searchBoxTwo").keyup(function () {
    //                if ($(this).val() != '') {
    //                    $("#searchBoxOne").val($(this).val());
    //                    $("#SearchCriteria").val($(this).val());
    //                }
    //            });

    //            $("#searchBoxTwo").html(function () {
    //                if ($(this).val() != '') {
    //                    $("#searchBoxOne").val($(this).val());
    //                }
    //            });

    $(".widgetHeader").toggle(function (e) {
        $(this).siblings(".widgetInnerContent").slideUp();
    }, function (e) {
        $(this).siblings(".widgetInnerContent").slideDown();
    });

    //            <% if(Session["Culture"] != null && Session["Culture"].ToString().Equals("ar")) { %>
    //                $(".menu a").each(function () {
    //                    $(this).addClass('localizeArabic');
    //                });
    //            <% } %>

    var isExpanded = window.location.href.indexOf("expanded");
    var areTipsShown = window.location.href.indexOf("tips");
    var $widgetContent = $("div#widgetBar");
    var $tipsContent = $("div.tip");
    var $verseGridInner = $("table.verseGridInner");

    if (isExpanded != -1) {
        $($widgetContent).css({ 'display': 'none' });
        $($verseGridInner).css({ 'width': '870px' });
        $("#imgExpand").attr({ 'title': 'Collapse Details', 'alt': 'Collapse Details' });
        isWidgetPaneVisible = !isWidgetPaneVisible;
    }

    if (areTipsShown != -1) {
        $($tipsContent).css({ 'display': 'none' });
       
    }

    $("#imgExpand").click(function (e) {
        if (isWidgetPaneVisible) {
            $($widgetContent).css({ 'display': 'none' });
            $($verseGridInner).css({ 'width': '870px' });
            $(this).attr({ 'title': 'Collapse Details', 'alt': 'Collapse Details' });
        }
        else {
            $($widgetContent).css({ 'display': '' });
            $($verseGridInner).css({ 'width': '575px' });
            $(this).attr({ 'title': 'Expand Details', 'alt': 'Expand Details' });
        }
        isWidgetPaneVisible = !isWidgetPaneVisible;
        e.preventDefault();
    });

});

//        function search() {
//            document.forms["form1"].action = "/Search/Index_Landing";
//            document.forms["form1"].submit();
//        }

