
$(document).ready(function () {
    $(".button").hover(function () {
        $(this).toggleClass('button-active');
    });

    $(".mybutton").button();
    //accordian
    if ($("#ng_us_accordion").length)
        $("#ng_us_accordion").accordion({ collapsible: true, autoHeight: false, active: false });

    //initialize scrollable
    if ($('.scrollable').length) {
        $(".scrollable").scrollable({
            speed: 700,
            circular: true,
            keyboard: false,
            onBeforeSeek: function (obj, idx) {
                this.getRoot().next().children('.button-number').find('div').removeClass('button-active');
            },
            onSeek: function (obj, idx) {
                this.getRoot().next().children('.button-number').find('div').removeClass('button-active');
                this.getRoot().next().children('.button-number').find('div').eq(idx).addClass('button-active');
            }
        });
    }


    $(".scrollable").eq(0).autoscroll({ interval: 5000, autoplay: true, autopause: true });
    $(".scrollable").eq(1).autoscroll({ interval: 8000, autoplay: true, autopause: true });

    $('.scrollable').each(function (idx) {
        var api = $(".scrollable").eq(idx).scrollable();

        var container = api.getRoot().next().children('.button-number');
        for (var i = 1; i <= api.getSize(); i++) {
            var el = $('<div class="button button-small button-light"><a href="javascript:;">' + i + '</a></div>').hover(function () {
                    $(this).toggleClass('button-active');
                }).appendTo(container);
            el.click(function () {
                var idx = parseInt($(this).text(), 10);
                if (api.getIndex() + 1 == idx) return false;
                api.seekTo(idx - 1);
            });
        }
        container.children('div:first').addClass('button-active');
    });


    $('.ng_us_search').click(function () {
        $(this).parent().next().slideToggle();
    });

    $('.ng_us_featured:first').show();

    if ($('.ng_us_featured').length > 3) {
        $('.ng_us_featuredbtnAll').text('Show All').click(function () {
            var mydev = $('<div>').prependTo($('body'));
            mydev.addClass("ng_us_featuredAll");
            $('.ng_us_featured').clone(true).appendTo(mydev).show();
            mydev.dialog({
                width: 600,
                height: 500,
                draggable: false,
                title: 'Featured Download',
                modal: true,
                close: function () {
                    mydev.remove();
                    $(this).dialog('destroy');
                }
            });
        });
    }
    //else {
    $('.ng_us_featuredbtn').toggle(function () {
        $('.ng_us_featured').show();
        $(this).text('Less');
    }, function () {
        $('.ng_us_featured:not(:first)').hide();
        $(this).text('More');
    });
    //}

    if ($('#ng_us_search_text').length > 0) {
        $('#ng_us_searchSubmit').click(function () {
            $('#ng_us_searchSubmitBtn').click();
        });
        $('#ng_us_search_text').keypress(function (event) {
            if (event.keyCode == 13) {
                $('#ng_us_searchSubmitBtn').click();
            }
        });
    }
});


