/**
 * Cookie plugin
 *
 * Copyright (c) 2006 Klaus Hartl (stilbuero.de)
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 *
 */


/**
 * Get the value of a cookie with the given name.
 *
 * @example $.cookie('the_cookie');
 * @desc Get the value of a cookie.
 *
 * @param String name The name of the cookie.
 * @return The value of the cookie.
 * @type String
 *
 * @name $.cookie
 * @cat Plugins/Cookie
 * @author Klaus Hartl/klaus.hartl@stilbuero.de
 */
jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        // CAUTION: Needed to parenthesize options.path and options.domain
        // in the following expressions, otherwise they evaluate to undefined
        // in the packed version for some reason...
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};
/*
Standard Stylesheet-Deklaration im HTML:
<link rel="stylesheet" type="text/css" href="myStyle_normal.css" id="fontSwitch" />

Stylesheets die verwendet werden:
normal	-> myStyle_normal.css
big		-> myStyle_big.css
bigger	-> myStyle_bigger.css

Aufruf im HTML
Plus:
<a href="#" onclick="setFontSize(1); return false;">+</a>
Minus: 
<a href="#" onclick="setFontSize(-1); return false;">-</a>

Falls das Cookie "fontSwitch" nicht gefunden wird, wird das Cookie mit dem Wert "normal" gesetzt.
Ansonsten wird der Style entsprechend dem Cookie-Wert gesetzt, solange er nicht "normal" entspricht.
Bei "normal" wird der Minus-Button ausgegraut.
*/

jQuery(function() {
	var c = jQuery.cookie("fontSwitch");
	if (c && c!= "normal") {
		jQuery('#fontSwitch').attr("href", jQuery('#fontSwitch').attr("href").replace("normal", c))
		if (c == "bigger") {
			jQuery('.increaseFont').css({opacity: 0.5, cursor :"default"});
			jQuery(".increaseFont").addClass("whiter");
		}
		else { 
			jQuery('.increaseFont').css({opacity: 1, cursor :"pointer"});
			jQuery(".increaseFont").removeClass("whiter");
		}
		
	}
	else {
		jQuery.cookie("fontSwitch", "normal", {expires: 30});
		jQuery('.decreaseFont').css({opacity: 0.5, cursor :"default"});
		jQuery(".decreaseFont").addClass("whiter");
	}
});

function setFontSize(a) {
	var b = ["normal","big","bigger"];
	var c = jQuery.cookie("fontSwitch");
	var d = jQuery.inArray(c, b) + a;
	if (d > -1 && d < b.length) {
		jQuery('#fontSwitch').attr("href", jQuery('#fontSwitch').attr("href").replace(c, b[d]));
		jQuery.cookie("fontSwitch", b[d], {expires: 30});
		switch (b[d]) {
			case "normal" :
				jQuery('.decreaseFont').css({opacity: 0.5, cursor :"default"});
				jQuery(".decreaseFont").addClass("whiter");
				break;
			case "bigger" :
				jQuery('.increaseFont').css({opacity: 0.5, cursor :"default"});
				jQuery(".increaseFont").addClass("whiter");
				break;
			default:
					jQuery('.decreaseFont, .increaseFont').css({opacity: 1, cursor :"pointer"});
					jQuery(".decreaseFont, .increaseFont").removeClass("whiter");
				break;
		}

	}
	return false;
}

