
var lib = {
	console :{
		on 			: function(){if(typeof console == 'object' && console.firebug && navigator.userAgent.indexOf('Firefox') != 0  ){return true;} else if(typeof console == 'object' && navigator.userAgent.indexOf('Webkit') != 0 ) {return true;} else { return false; }},
		log 		: function(cmd){if(lib.console.on()){console.log(cmd);}},
		debug 		: function(cmd){if(lib.console.on()){console.debug(cmd);}},
		info 		: function(cmd){if(lib.console.on()){console.info(cmd);}},
		warn 		: function(cmd){if(lib.console.on()){console.warn(cmd);}},
		error 		: function(cmd){if(lib.console.on()){console.error(cmd);}},
		trace 		: function(cmd){if(lib.console.on()){console.trace();}},
		group 		: function(title){if(lib.console.on()){console.group(title);}},
		groupEnd 	: function(cmd){if(lib.console.on()){console.groupEnd();}},
		dir 		: function(obj){if(lib.console.on()){console.dir(obj);}},
		trace 		: function(cmd){if(lib.console.on()){console.trace();}}
	}
};



jj = {};

/**
 * Creates cookie or return it's value.
 *
 * @example $.cookie('the_cookie', 'the_value');
 * @desc Creates session cookie.
 * @example $.cookie('the_cookie', 'the_value', { expires: 7, path: '/', domain: 'site.com', secure: true });
 * @desc Creates cookie with values.
 * @example $.cookie('the_cookie', null);
 * @desc Deletes cookie.
 * @example $.cookie('the_cookie');
 * @desc Returns value of the cookie.
 *
 * @param String name Cookie name.
 * @param String value Cookie value.
 * @param Object options Cookie options object.
 * @option Number|Date expires Either an integer specifying the expiration date from now on in days or a Date object.
 *                             If a negative value is specified (e.g. a date in the past), the cookie will be deleted.
 *                             If set to null or omitted, the cookie will be a session cookie and will not be retained
 *                             when the the browser exits.
 * @option String path The value of the path atribute of the cookie (default: path of page that created the cookie).
 * @option String domain The value of the domain attribute of the cookie (default: domain of page that created the cookie).
 * @option Boolean secure If true, the secure attribute of the cookie will be set and the cookie transmission will
 *                        require a secure protocol (like HTTPS).
 * @return Cookie value or jj object.
 * @author Klaus Hartl/klaus.hartl@stilbuero.de
 * @version 1.0
 */
jj.cookie = function(name, value, options) {

	if ('undefined' != typeof value) {
		options = options || {};

		if (null === value) {
			value = '';
			options.expires = -1;
		}

		var expires = '';

		if (options.expires && ('number' == typeof options.expires || options.expires.toUTCString)) {
			var date;

			if ('number' == typeof options.expires) {
				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('');

		return this;
	}

	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;
};
