﻿features = function() { };

features.prototype.currentFeature = 0;
features.prototype.rotateSpeed = 2000;
features.prototype.totalFeatures;
features.prototype.autoRotate;
features.prototype.isMouseOver = false;

features.prototype.initList = function() {
    var s = this;
    totalFeatures = $('div.feature_panel ul li').length;

    $('div.feature_panel ul a').mouseover(function() {
        s.isMouseOver = true;
        s.displayFeature($(this));
        return false;
    }).mouseout(function() {
        s.isMouseOver = false;
        s.startRotate();
    });

    $('div.feature_panel').mouseover(function() {
        clearTimeout(s.autoRotate);
        s.isMouseOver = true;
    }).mouseout(function() {
        s.isMouseOver = false;
        s.startRotate();
    });

    this.displayFeature($('div.feature_panel a:eq(' + this.currentFeature + ')'));
    $('div.feature_panel').mouseout();
};

features.prototype.displayFeature = function(obj) {
    var s = this;
    clearTimeout(s.autoRotate);

    var thisFeature = $('div.feature_panel ul a').index(obj);

    $('div.feature_panel div.feature_info').hide();
    $('div.feature_panel ul a').removeClass('hover');

    obj.addClass('hover');
    $('div.feature_panel div.feature_info:eq(' + thisFeature + ')').show().click(function() {
        window.location = obj.attr('href');
    });

    currentFeature = thisFeature;

    if (this.isMouseOver == false) {
        s.startRotate();
    }
};

features.prototype.startRotate = function() {
    var s = this;
    clearTimeout(s.autoRotate);
    s.autoRotate = setTimeout(function() {
        s.rotateFeatures();
    }, s.rotateSpeed);
};

features.prototype.rotateFeatures = function() {
    var nextFeature = (currentFeature == (totalFeatures - 1)) ? 0 : currentFeature + 1;
    this.displayFeature($('div.feature_panel a:eq(' + nextFeature + ')'));
};


$(function() {
    features = new features();
    features.initList();
});
