/* 
 * Mark bits of content on a page that need some tweaking
 */
 
(function(jQuery) {
		  
	var self = null;
 
	jQuery.fn.evalcontent = function(o)
	{	
		return this.each(function() {
			new jQuery.evalcontent(this, o);
		});
	};
	

    /**
     * The evalcontent object.
     *
     * @constructor
     * @name jQuery.evalcontent
     * @param Hash o A set of key/value pairs to set as configuration properties.
     * @cat Plugins/evalcontent
     */
	
	jQuery.evalcontent = function (e, o)
	{
		this.options		  	= o || {};

		siteMsg = '';
		
		// images
		$('img', e).each(function() {
		var msg = '<ul>';
		if ($(this).attr('alt').length == 0) {
		msg += '<li>no alt attribute</li>';
		}
/*
		if ($(this).attr('title').length == 0) {
		msg += '<li>no title attribute</li>';
		}
*/

		msg += '</ul>';

		if (msg != '<ul></ul>') {
		msg = '<h3>Image Errors</h3>'+msg;
		jQuery.evalcontent.fn.showMessage($(this), msg);
		}
		});


		// paragraphs
		$('p', e).each(function() {
		var msg = '<ul>';
		if ($('*', this).length == 0 && $.trim($(this).text()) == '') {
		msg += '<li>empty paragraph</li>';
		}

		msg += '</ul>';

		if (msg != '<ul></ul>') {
		msg = '<h3>Paragraph Errors</h3>'+msg;
		jQuery.evalcontent.fn.showMessage($(this), msg);
		}
		});

		// h1
		var msg = '<ul>';
if ($('h1').length > 1) {
$('h1', e).each(function(i) {
jQuery.evalcontent.fn.showMessage($(this), '<ul><li>too many h1, max 1</li></ul>');
});
}



		// anchor 
		$('a', e).each(function() {
		var msg = '<ul>';
		if ($(this).attr('title').length == 0) {
		msg += '<li>no title attribute</li>';
		}
		if ($(this).attr('title') == 'Read more') {
		msg += '<li>More descriptive title required</li>';
		}

		if ($(this).attr('href') !== undefined) {
		if ($(this).attr('href').length == 0 || $(this).attr('href') == '#') {
		msg += '<li>no link specified</li>';
		} else if ($(this).attr('href').indexOf('http://www') == 0 && $(this).attr('target') != '_blank') {
		msg += '<li>external link opening in same window</li>';
		} else if ($(this).attr('href').indexOf('www') == 0) {
		msg += '<li>external link without http://</li>';
		}
		}
		msg += '</ul>';

		if (msg != '<ul></ul>') {
		msg = '<h3>Link Errors</h3>'+msg;
		jQuery.evalcontent.fn.showMessage($(this), msg);
		}
		});

		if ($('a', e).length > 100) {
		siteMsg += 'Too many links on this page ('+$('a', e).length+')\n';
		}


		if ($('title').html().length > 65) {
		siteMsg += '<title> tag is too long at '+$('title').html().length+' characters (max 65 recommended)\n';
		}
		if ($('title').html().length < 5) {
		siteMsg += '<title> tag is too short at '+$('title').html().length+' characters (min 5 recommended)\n';
		}
0
		if ($('meta[name=description]').attr('content').length > 150) {
		siteMsg += '<meta> description is too long at '+$('meta[name=description]').attr('content').length+' characters (max 150 recommended)\n';
		}
		if ($('meta[name=description]').attr('content').length < 25) {
		siteMsg += '<meta> description is too short at '+$('meta[name=description]').attr('content').length+' characters (min 25 recommended)\n';
		}

		if (siteMsg.length > 0) {
		alert(siteMsg);
		}


	};

	jQuery.evalcontent.fn = jQuery.evalcontent.prototype = {
    autogrow: '1.0'
  };

jQuery.evalcontent.fn.extend = jQuery.evalcontent.extend = jQuery.extend;

	jQuery.evalcontent.fn.extend({
		showMessage: function(obj, message) {	
var id = 'msg'+obj.attr('id')+$('.evalcontentMsg').length;
var pos = $(obj).offset(); 
var msg = '<div id="'+id+'" class="evalcontentMsg" style="position: absolute; left: '+parseInt(pos.left)+'px; top: '+parseInt(pos.top)+'px; width: '+obj.attr('width')+'px; height: '+obj.attr('height')+'px;">'+message+'</div>';
$('body').append(msg);
		}
});

	
})(jQuery);
