/**
 * StripTweet framework
 *
 * @fileOverview    StripTweet_Rotation_Rotation
 * @author          Matej Keglevic, Copyright (c) 2009, ThirdFrameStudios
 */

/**
 * Description.
 *
 * @name    StripTweet_Rotation_Rotation
 * @class   Short Description.
 * @author  Matej Keglevic, Copyright (c) 2009, <a href="http://www.thirdframestudios.com">ThirdFrameStudios</a>
 * @version 1.0
 */
var StripTweet_Rotation_Rotation = new Class({
    Extends: StripTweet_Core,
    htmlElements: {
        hints: '',
        dotz: ''
    },
    items: '',
    currentclick: 0,
    currentdot: 1,
    initialize: function(items, options) {
        var that = this;

        this.items = $$(items);

        this.hints = $$('#content h2 + a');
        this.hints.addEvent('click', this.cHints.bind(this));

        this.htmlElements.hints = new Element("a", {
            href: "#",
            html: "more hints",
            events: {
                click: this.cHints.bind(this)
            }
        }).injectAfter($$('#content h2')[0]);

        this.htmlElements.dotz = new Element("ol").setProperty("id", "dotz").injectAfter($$('#content div')[0]);

        $each(this.items, function(li, index) {
            li.setStyles({
                'position': 'absolute',
                'top': '20px'
            });

            if (index % 2 === 1) {
                li.setStyle('right', '0px');

                var ol_li = new Element("li", {
                    html: "dot"
                });

                ol_li.injectInside(this.htmlElements.dotz);
            }

            if ((index + 1) > 2) {
                li.setStyle("opacity", 0)
            }
        }.bind(this));

        this.htmlElements.dotz.getElements('li:first-child').addClass('selected');
        this.htmlElements.dotz.getElements('li:last-child').addClass('l');
    },
    cHints: function(event) {
        event = new Event(event).stop();

        this.items[this.currentclick].fade('out');
        this.items[this.currentclick+1].fade('out');

        if (this.currentclick <= parseInt(this.items.length/2)) {
            this.currentclick += 2;
            this.currentdot++;
        } else {
            this.currentclick = 0;
            this.currentdot = 1;

            this.items[this.items.length - 2].fade('out');
            this.items[this.items.length - 1].fade('out');
        }

        this.items[this.currentclick].fade('in');
        this.items[this.currentclick+1].fade('in');

        this.htmlElements.dotz.getElements('li').removeClass('selected');
        this.htmlElements.dotz.getElements('li:nth-child('+this.currentdot+')').addClass('selected');

        return false;
    }
});