/**
 * Created by SonicK.
 * User: vadim.lyahovic
 * Date: 5/16/11
 * Time: 4:26 PM
 * To change this template use File | Settings | File Templates.
 */
(function($) {
    function Hero(obj) {
        this.obj = obj;
        this.opts = {
            sels : {
                slide      : "li",
                al_active  : "first",
                hero_arrow : ".heroArrow"
            },
            index : 1
        };
        this.init();
    }

    Hero.prototype.init = function() {
        var instance = this;
        $(this.obj).find(this.opts.sels.slide).eq(1).each(function() {
            $(this)
                    .find(instance.opts.sels.hero_arrow)
                    .css("margin-top", -($(this).height() + 20) / 2)
        });
        $(this.obj).find(this.opts.sels.slide).filter(":not(:first)").mouseenter(function() {
            $(instance.obj)
                    .find("." + instance.opts.sels.al_active)
                    .removeClass(instance.opts.sels.al_active);
            $(this)
                    .find(instance.opts.sels.hero_arrow)
                    .css("margin-top", -($(this).height() + 20) / 2);
        });
        $(this.obj).find(this.opts.sels.slide).filter(":not(:first)").click(function() {
            instance.opts.index = $(this).index();
        });
        $(this.obj).find(this.opts.sels.slide).filter(":first").mouseenter(function() {
            $(instance.obj)
                    .find(instance.opts.sels.slide)
                    .eq(instance.opts.index)
                    .addClass(instance.opts.sels.al_active);
        });
        $(this.obj).mouseleave(function() {
            $(instance.obj)
                    .find(instance.opts.sels.slide)
                    .eq(instance.opts.index)
                    .addClass(instance.opts.sels.al_active);
        });
    };

    $.fn.extend({
        Hero: function() {
            return this.each(function() {
                this.hero = new Hero(this);
            });
        }
    });
})(jQuery);
