﻿// Feature object
//---------------------------------
/*
Feature is used to rotate home feature
---------------------------------------------
*/
var Feature = {
    // variables
    current: false,
    interval: {
        delay: 5000,
        rotation: {}
    },
    solid: "",

    preventHover: 0,
    doMouseOver: false,
    count: 0,
    bg: "Feature-Background",
    menu: {
        id: "CityTV-FeatureMenu",
        node: "li",
        state: ["on", ""]
    },
    // 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; }
            if (this.doMouseOver == false) {
                this.Bind(prop);

            }
            else {
                this.BindWithMouseOver(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: this.solid + " url(" + feature.background + ") no-repeat top center" })
        $("#" + feature.div).show();
        Feature.stopBubble(this);

        Feature.List(this.current, 0);

    },

    Bind: function (prop) {
        var obj = $("li[trigger='" + prop + "']")


        obj.bind(
			'click',
			function (event) {
			    event.preventDefault();
			    Feature.Switch($(this).attr("trigger"))
			}
		)

    },

    BindWithMouseOver: function (prop) {
        if (prop == 'feature-1') {
            var obj = $("li[trigger='" + prop + "']")
            obj.bind(
			    'mouseover',
			    function () {
			        var currentDiv = prop.substring(prop.length - 1)

			        $(".topPhoto").hide();

			        if (Feature.preventHover == 0 || prop.indexOf(Feature.preventHover) != -1) {
			            Feature.Switch($(this).attr("trigger"))
			        }
			        else {
			            //$("li[trigger]").css("background-color", "#FFFFFF");
			            $("li[trigger]").addClass("myClass");
			            //$(this).css("background-color", "#E5EFF6");
			            $(this).removeClass("yourClass");
			        }

			    }
		    )
            obj.bind(
			    'click',
			    function (event) {
			        event.preventDefault();
			        window.location = $(this).attr("link")
			    }
    		)
        }
        else {
            var obj = $("li[trigger='" + prop + "']")
            if (!obj.hasClass("BrightCove")) {

                obj.bind(
			'click',
			function (event) {
			    event.preventDefault();
			    window.location = $(this).attr("link")

			}
    		)
            }
            //if it is a brightcove vi
            else {
                obj.bind(
                	'click', function (event) {

                	    event.stopPropogation();
                	    window.location = $(this).attr("link")
                	    return false;

                	});


                //	'click', function() { playvideo(29710107001, 82003561001, 'RelatedVideo', 'GreenRadioVideo'); ; });

            }



            obj.bind(
			'mouseover',
			function () {


			    var currentDiv = prop.substring(prop.length - 1)
			    //  $(".clickdiv").hide()
			    // $("#clickdiv" + currentDiv).show()
			    if (Feature.preventHover == 0 || prop.indexOf(Feature.preventHover) != -1) {

			        Feature.Switch($(this).attr("trigger"))
			    }
			    else {
			        //$("li[trigger]").css("background-color", "#FFFFFF");

			        //$(this).css("background-color", "#E5EFF6");
			    }



			}
			)


        }

    },

    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();



    },
    stopBubble: function (evt) {
        if (!evt) var evt = window.event;
        evt.cancelBubble = true;
        if (evt.stopPropagation) evt.stopPropagation();
    },

    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 + "']")
        if (state == "on") {

            //$("li[trigger='" + prop + "']").css("background-color", "#E5EFF6");
            $("li[trigger='" + prop + "']").removeClass("listOFF").addClass("listON");
        }

        //state == "on" ? obj.css("background-color", "#E5EFF6") : obj.css("background-color", "#ffffff");
        state == "on" ? obj.removeClass("listOFF").addClass("listON") : obj.removeClass("listON").addClass("listOFF");

        /*
        obj.attr(
        {
        "class":state
        }
        )
        */
    }
}
