﻿// JavaScript Document
window.addEvent('domready', function () {
    new Streamer({
        next: $('streamermenu').getElement('a').getProperty('name'),
        auto: true
    })
});

var Streamer = new Class({
    options: {
        next: false,
        auto: true,
        delayed: null,
        maxHeight: null
    },

    initialize: function (options) {
        this.setOptions(options);
        var passThru = this;
        $$('div.streameritem').each(function (theEle) {
            // Use the first image as the layer background...
            var first = theEle.getElement('img');
            theEle.setStyle('backgroundImage', "url(" + first.getProperty('src') + ")");
            var dim = $('streamer').getCoordinates();
            theEle.setStyle('height', (dim.height - 40));
            // make the container the same height!
            if (window.ie6) { //&& passThru.maxHeight<dim.height
                passThru.maxHeight = dim.height;
                $('streamer').setStyle('height', (dim.height));
            }
            //alert(dim.height-40);
        });



        $$('#streamermenu li a').each(function (theA) {
            theA.addEvent('click', passThru.setStreamer.bindWithEvent(passThru, theA.getProperty('name')));
        });
        this.setStreamer();
    },

    setStreamer: function (caller, aName) {
        theName = this.options.next;
        if (typeof (caller) != 'undefined') {
            this.options.auto = false;
            $clear(this.options.delayed);
            theName = aName;
        }
        $$('div.streameritem').each(function (theEle) {
            theEle.addClass('hidden');
        });
        this.options.next = '';
        var setnext = true;
        var passThru = this;
        $$('#streamermenu li a').each(function (theA) {
            if (setnext) {
                passThru.options.next = theA.getProperty('name');
                setnext = false;
            }
            if (theA.getProperty('name') != theName) {
                theA.getParent().removeClass('current');
            } else {
                setnext = true;
                theA.getParent().addClass('current');
                $$('div[id=' + theName + ']').removeClass('hidden'); // Strange but the only way it works in IE...
            }

        });
        if (this.options.auto) {
            this.options.delayed = this.setStreamer.delay(4000, this);
        }
    }

});
Streamer.implement(new Options, new Events);
