/**
 * Styleswitcher, using mootools
 *
 * Based on PPK's styleswitcher. See: http://www.alistapart.com/stories/alternate/
 
 * @author Gerard van Helden
 * @copyright Zicht nieuwe media ontwerpers
 */

StyleSwitcher = new Class ({
    initialize:function ( className ) {
        var sheets = $$(document.getElementsByTagName('link'));
        this.className = className;
        this.sheets = {};
        sheets.each ( function ( link ) {
            if ( link.hasClass(className) ) {
                this.sheets[link.getAttribute('title')] = link;
            }
        }, this );
        this.reset( false );
        if ( $type(Cookie) && $type(Cookie.get) ) {
            this.setActive ( Cookie.get('stylesheet.' + this.className) );
        }
    },
    
    setActive:function ( title, save ) {
        //alert( 'Setting active: ' + title);
        //console.log('Setting active ' + title);
        for (var i in this.sheets) {
            this.sheets[i].setProperty('disabled', i != title);
        }
        if ( $type(Cookie) && $type(Cookie.set) && save ) {
            Cookie.set('stylesheet.' + this.className, title);
        }
    },
    
    getPreferred:function () {
        for ( var i in this.sheets ) {
            if ( this.sheets[i].getAttribute('title').indexOf( 'alt') != -1 ) {
                return i;
            }
        }
        return null;
    },
    
    reset:function ( save ) {
        this.setActive ( this.getPreferred(), save );
    }
} );