/*	name			: ClassBehaviours, the javascript framework based on class-name parsing	update			: 9.3.17	author			: Maurice van Creij	dependencies	: jquery.classbehaviours.js	info			: http://www.classbehaviours.com/

    This file is part of jQuery.classBehaviours.
    
    ClassBehaviours is a javascript framework based on class-name parsing.
    Copyright (C) 2008  Maurice van Creij

    ClassBehaviours is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    ClassBehaviours is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with ClassBehaviours. If not, see http://www.gnu.org/licenses/gpl.html.*/

	// create the jQuery object if it doesn't already exist
	if(typeof(jQuery)=='undefined') jQuery = function(){};
	
	// create the root classbehaviours object if it doesn't already exist
	if(typeof(jQuery.classBehaviours)=='undefined') jQuery.classBehaviours = function(){};
	
	// create the handlers child object if it doesn't already exist
	if(typeof(jQuery.classBehaviours.handlers)=='undefined') jQuery.classBehaviours.handlers = function(){}

	// Transform HTML 5 and XHTML 2 to a lower standard
	jQuery.classBehaviours.handlers.degradeGracefully = {
		// properties
		name: 'degradeGracefully',
		firstTime: true,
		// methods
		start: function(node){
			if(this.firstTime && navigator.userAgent.indexOf('MSIE')>-1 || navigator.userAgent.indexOf('Firefox/2')>-1){
				// rewrite the html
				node.innerHTML = node.innerHTML.replace
				(
					/<!DOCTYPE html>/gi, 	'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">'
				).replace(
					/<HEADER/gi, 			'<div'
				).replace(
					/<SECTION/gi, 			'<div'
				).replace(
					/<ARTICLE/gi, 			'<div'
				).replace(
					/<NAV/gi, 				'<div'
				).replace(
					/<FOOTER/gi, 			'<div'
				).replace(
					/<TIME/gi, 				'<span'
				).replace(
					/<METER/gi, 			'<span'
				).replace(
					/<PROGRESS/gi, 			'<span'
				).replace(
					/<MENU/gi, 				'<ul'
				).replace(
					/<\/HEADER/gi, 			'</div'
				).replace(
					/<\/SECTION/gi, 		'</div'
				).replace(
					/<\/ARTICLE/gi, 		'</div'
				).replace(
					/<\/NAV/gi, 			'</div'
				).replace(
					/<\/FOOTER/gi, 			'</div'
				).replace(
					/<\/TIME/gi, 			'</span'
				).replace(
					/<\/METER/gi, 			'</span'
				).replace(
					/<\/PROGRESS/gi, 		'</span'
				).replace(
					/<\/MENU/gi, 			'</ul'
				) + '<div style="position : absolute; left : 16px; top : 5px; z-index : 10000;">Tada!</div>';
				// restart the classBehaviours
				this.firstTime = false;
				jQuery.classBehaviours.parser.parseNode(node);
			}
		}
	}

	// add this addon to the jQuery object
	if(typeof(jQuery.fn)!='undefined'){
		// extend jQuery with this method
		jQuery.fn.degradeGracefully = function(){
			return this.each(
				function(){
					jQuery.classBehaviours.handlers.degradeGracefully.start(this);
				}
			);
		};
		// set the event handler for this jQuery method
		$(document).ready(
			function(){
				$(".degradeGracefully").degradeGracefully();
			}
		);
	}


