﻿/*
MooSizer - a Mootools rewrite of: Supersized - Full Screen Background/Slideshow jQuery Plugin

License:
MIT-style license.

Credits:
Original jQuery supersized script By Sam Dunn ( <http://buildinternet.com> / <http://onemightyroar.com>	 )
found here: <http://buildinternet.com/2009/02/supersized-full-screen-backgroundslideshow-jquery-plugin/>
rewritten for Mootools 1.2 by Markus Timtner ( <http://mtness.net> ) 2009-03-27 1100-1500 GMT+1
*/


var mooSizer = new Class({

    Implements: [Options, Events],
    options: {
        bgElement: ''
    },

    initialize: function(options) {
        this.setOptions(options);



        window.addEvent('resize', function() {
            this.resizenow();
        } .bind(this));

    },

    resizenow: function() {

        var clientsize = window.getSize();

        var image = $(this.options.bgElement).getElement('img');

        image.setStyles({ 'height': clientsize.y, 'width': 'auto' });

        if (image.getSize().x < 250) {

            image.setStyles({ 'width': 250, 'height': 'auto' });

        }

        $$('.contentouter').setStyle('width', (clientsize.x - 300));

    }

});

/*************************************************************/

window.addEvent('domready', function() {

    moosizer = new mooSizer({ bgElement: 'background' });


    var current = -1;
    var np = $$('.pictures img');
    if (np.length > 0) {
        np.setOpacity(0).set('tween', { 'duration': 2000 });
        for (var i = 0; i < np.length / 2; i++) {
            np[i * 2].setStyle('left', '0');
            np[(i * 2) + 1].setStyle('left', '275px');
        }

        var next = function() {
            if (current >= 0) {
                np[current * 2].fade(0);
                np[(current * 2) + 1].fade(0);
            }
            current++;

            if (current >= (np.length / 2))
                current = 0;
            np[current * 2].fade(1);
            np[(current * 2) + 1].fade(1);
        }

        next();
        next.periodical(7000);
    }
});

window.addEvent('load', function() {
    moosizer.resizenow();
});
