/*
 * Copyright (C) 2008 Mo Chen <withinsea@gmail.com>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
(function ($) {

	$.extend({
	
		httpequiv: function (name) {
			if (!name) {
				var httpequiv = {};
				$("head>meta[http-equiv]", document).each(function () {
					httpequiv[$(this).attr("http-equiv").toLowerCase()] = $(this).attr("content");
				});
				return httpequiv;
			} else {
				return (
					$("head>meta[http-equiv]", document).filter(function () {
						return $(this).attr("http-equiv").toLowerCase() == name.toLowerCase();
					}).attr("content") ||
					undefined
				);
			}
		},

		meta: function (name) {
			if (!name) {
				var meta = {};
				$("head>meta[name]", document).each(function () {
					meta[$(this).attr("name").toLowerCase()] = $(this).attr("content");
				});
				return meta;
			} else {
				return (
					$("head>meta[name]", document).filter(function () {
						return $(this).attr("name").toLowerCase() == name.toLowerCase();
					}).attr("content") ||
					undefined
				);
			}
		}
		
	});
	
	$.fn.extend({
		meta: function (name) {
			if (this.length == 0) {
				return undefined;
			} else {
				var meta = (function () {
					return eval("(" + $(this).attr("meta") + ")");
				}).apply(this[0]);
				return (name) ? meta[name] : meta;
			}
		}
	});
	
}) (jQuery);
