/* Validators
 *
 * Douglas Thrift
 *
 * $Id: validators.js 1270 2010-08-24 15:50:12Z douglas $
 */

$(function()
{
	$('#copyright').toggle(function()
	{
		var validators = $('#validators');

		if (validators.length == 0)
		{
			var as = ['<a/>', '<a/>'];
			var hrefs = ['http://validator.w3.org/check?uri=' + encodeURIComponent(document.URL), 'http://jigsaw.w3.org/css-validator/validator?uri=' + encodeURIComponent(document.URL)];
			var alts = ['Valid HTML 5', 'Valid CSS Level 2'];
			var srcs = ['valid-html5.png', 'valid-css2.png'];

			$('link[rel=alternate]').each(function ()
			{
				var href = this.href;

				if ($.browser.msie)
					if (/^\//.test(href))
						href = location.protocol + '//' + location.host + (location.port == '' ? '' : ':' + location.port) + href;

				switch ($(this).attr('type'))
				{
				case 'application/atom+xml':
					hrefs.push('http://feedvalidator.org/check.cgi?url=' + encodeURIComponent(href));
					alts.push('Valid Atom');
					srcs.push('valid-atom.png');
					break;
				case 'application/rss+xml':
					hrefs.push('http://feedvalidator.org/check.cgi?url=' + encodeURIComponent(href));
					alts.push('Valid RSS');
					srcs.push('valid-rss.png');
					break;
				default:
					return true;
				}

				as.push('<a/>');
			});

			validators = $('<p/>').attr('id', 'validators').hide().appendTo($('footer')).append(as.join('&nbsp;'));

			validators.children('a').each(function (index)
			{
				$(this).attr('href', hrefs[index]).append('<img/>').children('img').attr({alt: alts[index], src: '/img/' + srcs[index]});
			});
		}

		validators.slideDown('fast');
	}, function()
	{
		$('#validators').slideUp('fast');
	});
});

