var Effects = function (options) {
    this.options = $.extend(this.defaults, options);
    this._init();
}

Effects.prototype = {
    defaults: {
        titleLinkClass: 'title-link',
        subMenuClass: 'ul-submenu',
        iconCenterClass: 'icon-center',
        previewId: 'preview',
        imgPreviewId: 'preview img',
        ulPreviewId: 'preview-ul li'
    },

    _init: function () {
        var _this = this;

        this.preview = $('#' + this.defaults.previewId);
        this.imgPreview = $('#' + this.defaults.imgPreviewId);
        this.ulPreview = $('#' + this.defaults.ulPreviewId);

        this.titleLink = $('.' + this.defaults.titleLinkClass);
        this.subMenu = $('.' + this.defaults.subMenuClass);
        this.icon = $('.' + this.defaults.iconCenterClass);

        _this.scrollEffect();
        _this.sidebarEffect();
        _this.navBarScroll();
        _this.ulEffect();
        _this.previewType();
    },

    previewType: function () {
        var _this = this;

        this.preview.attr('hidden', 'hidden');
        this.ulPreview.hover(
            function () {
                var imgId = $(this).find('a').attr('id');

                _this.preview.fadeIn(100);
                _this.imgPreview.attr('src', '/img/' + imgId + 'Preview.jpg');
            }, function () {
                _this.preview.fadeOut(100);
            }
        );
    },

    ulEffect: function () {
        var _this = this;

        this.titleLink.on('click', function () {
            $(this).next(_this.subMenu).slideDown(300);
        });
    },

    navBarScroll: function () {
        var _this = this;

        $(window).bind('scroll', function () {
            var navHeight = $(window).height() - 500;
            if ($(window).scrollTop() > navHeight) {
                $('nav').addClass('fixed');
                _this.icon.css('top', '69%');
            }
            else {
                $('nav').removeClass('fixed');
                _this.icon.css('top', '74.5%');
            }
        });

    },

    scrollEffect: function () {
        $('a[href*=#anchor]:not([href=#])').click(function () {
            if (location.pathname.replace(/^\//, '') == this.pathname.replace(/^\//, '') && location.hostname == this.hostname) {
                var target = $(this.hash);
                target = target.length ? target : $('[name=' + this.hash.slice(1) + ']');
                if (target.length) {
                    $('html,body').animate({
                        scrollTop: target.offset().top
                    }, 1000);
                    return false;
                }
            }
        });

        $(window).scroll(function () {
            if ($(this).scrollTop() > 100) {
                $('.scrollToTop').fadeIn();
            } else {
                $('.scrollToTop').fadeOut();
            }
        });

        $('.scrollToTop').click(function () {
            $('html, body').animate({scrollTop: 0}, 800);
            return false;
        });

    },

    sidebarEffect: function () {
        if (!$('.nav-sidebar').is.visible) {
            $('#paramBack').hide();
        }
        $('#param').click(function () {
            $(this).fadeOut(500);
            $('.nav-sidebar').toggle("slide");
            $('#paramBack').show();
        });
        $('#paramBack').click(function () {
            $('#param').fadeIn(500);
            $('.nav-sidebar').toggle("slide");
        });
    }
}
window.Effects = Effects;
