// Feature object
//---------------------------------
/*
	Feature is used to rotate home feature
	---------------------------------------------
*/
var Feature = {
    // variables
    current: false,
    interval: {
        delay: 10000,
        rotation: {}
    },
    solid: "",
    count: 0,
    bg: "Feature-Background",
    menu: {
        id: "FeatureMenu",
        node: "li",
        state: ["on", ""]
    },
    features: [],
    // methods

    Init: function(rotate) {
        var features = this.features[0];
        var first = true;



        for (prop in features) {
            if (!first) { $("#" + features[prop].div).hide(); }
            else {
                Feature.List(prop, 0);
            }
            if (!this.current) { this.current = prop; }
            this.Bind(prop);
            first = false;
        }

        if (rotate) {
            this.interval.rotate = setInterval(
				this.Rotate,
				this.interval.delay
			)
        }
    },

    Display: function() {
        var feature = this.features[0][this.current];

        $("#" + this.bg).css({ background: " url(" + feature.background + ") no-repeat top center" })
        $("#" + feature.div).fadeIn('fast');
        if (this.strecherID && this.strecherID != '') {
            $("#" + this.strecherID).css({ background: " url(" + feature.strecher + ")" })
        }
        Feature.List(this.current, 0);

    },

    Bind: function(prop) {
        var obj = $("li[trigger='" + prop + "']")
        obj.bind(
			'click',
			function() {
			    Feature.Switch($(this).attr("trigger"))
			}
		)
    },

    Switch: function(trigger) {
        this.current = trigger;
        var features = this.features[0];
        for (prop in features) {
            $("#" + features[prop].div).hide();
            Feature.List(prop, 1);
        }

        this.Display();
        this.Kill();
    },

    Kill: function() {
        clearInterval(this.interval.rotate);
    },

    Rotate: function() {
        var features = Feature.features[0];
        var current = Feature.current;
        var count = Feature.count;
        var next = false;
        var is = false;
        var first = false
        for (prop in features) {
            first = !first ? prop : first;
            if (is) { next = prop; }
            is = prop == current ? true : false;

            $("#" + features[prop].div).hide();
            Feature.List(prop, 1);
        }
        Feature.current = next ? next : first;
        Feature.Display()
    },

    List: function(prop, state) {
        var state = this.menu.state[state];
        var obj = $("li[trigger='" + prop + "']")

        state == "on" ? obj.addClass("on") : obj.removeClass("on");
    }
}
