//
// styleswitcher.js
//
// jQuery script to implement a styleswitcher using the dynamicCss
// jQuery-plugin.
//
// Author: Johannes Marbach
//
// Copyright (c) 2008, 2009, rapidrabbit GbR.
// All rights reserved.
//

var stylesheet_medium = 'fileadmin/vorlagen/css/medium.css';
var stylesheet_large = 'fileadmin/vorlagen/css/large.css';
var style = null;

// Setup styleswticher after the DOM is loaded
jQuery(document).ready(function() {
    // Query last state from cookie
    var cookie = parseInt(get_cookie('style'));
    switch (cookie)
    {
        case 1:
            style = 1;
            set_style_medium();
            break;
        case 2:
            style = 2;
            set_style_large();
            break;
        default:
            style = 0;
            set_style_small();
    }
    
    // Bind style swticher buttons
    jQuery('#a-small').bind('click', function()
        {
            style = 0;
            set_cookie();
            set_style_small();
            return false;
        }
    );
    
    jQuery('#a-middle').bind('click', function()
        {
            style = 1;
            set_cookie();
            set_style_medium();
            return false;
        }
    );
    
    jQuery('#a-large').bind('click', function()
        {
            style = 2;
            set_cookie();
            set_style_large();
            return false;
        }
    );
});

function set_cookie()
{
    document.cookie = 'style=' + style + ';expires= 01/01/3000 00:00:00;path=/';;
}

function get_cookie(name)
{
    var cookies = document.cookie.match ('(^|;) ?' + name +
        '=([^;]*)(;|$)');
    
    if (cookies)
        return (unescape(cookies[2]));
    else return null;
}


function set_style_small()
{
    jQuery.dynamicCss.unload(stylesheet_medium);
    jQuery.dynamicCss.unload(stylesheet_large);
}

function set_style_medium()
{
    jQuery.dynamicCss.unload(stylesheet_large);
    jQuery.dynamicCss.load(stylesheet_medium);
}

function set_style_large()
{
    jQuery.dynamicCss.unload(stylesheet_medium);
    jQuery.dynamicCss.load(stylesheet_large);
}
