jQuery.extend({

  get_window_sizes: function()
	{
		var iebody = (document.compatMode && document.compatMode != 'BackCompat') ? document.documentElement : document.body;
		return {
			'offset_x'   : iebody.scrollLeft ? iebody.scrollLeft : (self.pageXOffset ? self.pageXOffset : 0),
			'offset_y'   : iebody.scrollTop  ? iebody.scrollTop : (self.pageYOffset ? self.pageYOffset : 0),
			'view_height': self.innerHeight ? self.innerHeight : iebody.clientHeight,
			'view_width' : self.innerWidth ? self.innerWidth : iebody.clientWidth,
			'height'     : iebody.scrollHeight ? iebody.scrollHeight : window.height,
			'width'      : iebody.scrollWidth ? iebody.scrollWidth : window.width
		}
	},

  redirect: function(url)
	{
		if ($('base').length && url.indexOf('/') != 0) {
			url = $('base').attr('href') + url;
		}
		window.location.href = url;
	},

  ua:
  {
		version: (navigator.userAgent.toLowerCase().indexOf("chrome") >= 0) ? (navigator.userAgent.match(/.+(?:chrome)[\/: ]([\d.]+)/i) || [])[1] : ((navigator.userAgent.toLowerCase().indexOf("msie") >= 0)? (navigator.userAgent.match(/.*?msie[\/:\ ]([\d.]+)/i) || [])[1] : (navigator.userAgent.match(/.+(?:it|pera|irefox|ersion)[\/: ]([\d.]+)/i) || [])[1]),
		browser: (navigator.userAgent.toLowerCase().indexOf("chrome") >= 0) ? 'Chrome' : (jQuery.browser.safari ? 'Safari' : (jQuery.browser.opera ? 'Opera' : (jQuery.browser.msie ? 'Internet Explorer' : 'Firefox'))),
		os: (navigator.platform.toLowerCase().indexOf('mac') != -1 ? 'MacOS' : (navigator.platform.toLowerCase().indexOf('win') != -1 ? 'Windows' : 'Linux')),
		language: (navigator.language ? navigator.language : (navigator.browserLanguage ? navigator.browserLanguage : (navigator.userLanguage ? navigator.userLanguage : (navigator.systemLanguage ? navigator.systemLanguage : ''))))
	},

   /**
   * Create a cookie with the given key and value and other optional parameters.
   *
   * @example $.cookie('the_cookie', 'the_value');
   * @desc Set the value of a cookie.
   * @example $.cookie('the_cookie', 'the_value', { expires: 7, path: '/', domain: 'jquery.com', secure: true });
   * @desc Create a cookie with all available options.
   * @example $.cookie('the_cookie', 'the_value');
   * @desc Create a session cookie.
   * @example $.cookie('the_cookie', null);
   * @desc Delete a cookie by passing null as value. Keep in mind that you have to use the same path and domain
   *       used when the cookie was set.
   */
  cookie: function (key, value, options) {

    // key and value given, set cookie...
    if (arguments.length > 1 && (value === null || typeof value !== "object")) {
        options = jQuery.extend({}, options);

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

        if (typeof options.expires === 'number') {
            var days = options.expires, t = options.expires = new Date();
            t.setDate(t.getDate() + days);
        }

        return (document.cookie = [
            encodeURIComponent(key), '=',
            options.raw ? String(value) : encodeURIComponent(String(value)),
            options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE
            options.path ? '; path=' + options.path : '',
            options.domain ? '; domain=' + options.domain : '',
            options.secure ? '; secure' : ''
        ].join(''));
    }

    // key and possibly options given, get cookie...
    options = value || {};
    var result, decode = options.raw ? function (s) {return s;} : decodeURIComponent;
    return (result = new RegExp('(?:^|; )' + encodeURIComponent(key) + '=([^;]*)').exec(document.cookie)) ? decode(result[1]) : null;
  },

  /*
   * @js
   * $.ihint();
   *
   * @html
   * <span><input type="text" class="ihint" title="HELP TEXT HERE"/></span>
   *
   * @css
   * .ihint-help {}
   */
  ihint: function()
  {
    return $('.ihint').each(function(){
      var obj = this;

      var container = $(obj).parent().css({position: 'relative'}).append('<span class="ihint-help">' + $(obj).attr('title') + '</span>');
      var help = container.find('.ihint-help').css({'top': Math.ceil(($(obj).height() - help.height()) / 2)})
      
      $(obj).removeAttr('title');

      if ($(obj).val()) {
        help.hide();
      }

      help.click(function(){
        help.hide();
        $(obj).focus();
      });

      $(obj).focus(function(){
        help.hide();
      });

      $(obj).blur(function(){
        if (!$(obj).val()) {
          help.show();
        }
      });
    });
  }

});
