
/* file:base/Mjax.Base.class.js */

// +---------------------------------------------------------------------------+
// | This file is part of the MrJeep Agavi Extension package.                  |
// | Copyright (c) 2006, 2007 Jean-Philippe Dery                               |
// |                                                                           |
// | For the full copyright and license information, please view the LICENSE   |
// | file that was distributed with this source code.                          |
// +---------------------------------------------------------------------------+

var clientPC  = navigator.userAgent.toLowerCase(); // Get client info
var clientVer = parseInt(navigator.appVersion); // Get browser version

var ie5   = ((clientPC.indexOf("msie") != -1) && (clientPC.indexOf("opera") == -1));
var isIe  = ((clientPC.indexOf("msie") != -1) && (clientPC.indexOf("opera") == -1));
var isNav = ((clientPC.indexOf('mozilla')!=-1) && (clientPC.indexOf('spoofer')==-1) && (clientPC.indexOf('compatible') == -1) && (clientPC.indexOf('opera')==-1) && (clientPC.indexOf('webtv')==-1) && (clientPC.indexOf('hotjava')==-1));

var isWin = ((clientPC.indexOf("win")!=-1) || (clientPC.indexOf("16bit") != -1));
var isMac = (clientPC.indexOf("mac")!=-1);

var Mjax = {};
/* file:element/Element.class.js */

// +---------------------------------------------------------------------------+
// | This file is part of the MrJeep Agavi Extension package.                  |
// | Copyright (c) 2006, 2007 Jean-Philippe Dery                               |
// |                                                                           |
// | For the full copyright and license information, please view the LICENSE   |
// | file that was distributed with this source code.                          |
// +---------------------------------------------------------------------------+

Element.extend(
{

 	// +-----------------------------------------------------------------------+
	// | PUBLIC VARIABLES                                                      |
	// +-----------------------------------------------------------------------+

    container : null,

	// +-----------------------------------------------------------------------+
	// | METHODS                                                               |
	// +-----------------------------------------------------------------------+

	setContainer : function(container)
	{

		this.container = container;

	},

	// --------------------------------------------------------------------

	getContainer : function()
	{

		return this.container;

	}

});
/* file:html/Mjax.HtmlElement.class.js */

// +---------------------------------------------------------------------------+
// | This file is part of the MrJeep Agavi Extension package.                  |
// | Copyright (c) 2006, 2007 Jean-Philippe Dery                               |
// |                                                                           |
// | For the full copyright and license information, please view the LICENSE   |
// | file that was distributed with this source code.                          |
// +---------------------------------------------------------------------------+

Mjax.HtmlElement = new Class(
{

	// +-----------------------------------------------------------------------+
	// | PROTECTED VARIABLES                                                   |
	// +-----------------------------------------------------------------------+

    element : null,

	// +-----------------------------------------------------------------------+
	// | METHODS                                                               |
	// +-----------------------------------------------------------------------+

	initialize : function(element)
	{

		this.element = $(element);

	},

	// ------------------------------------------------------------------------

	setId : function(id)
	{

		this.element.setProperty('id', id);

	},

	// ------------------------------------------------------------------------

	getId : function()
	{

		return this.element.getProperty('id');

	},

	// ------------------------------------------------------------------------

	addEvent : function(name, event)
	{

		this.element.addEvent(name, event);

	},

	// ------------------------------------------------------------------------

	setProperty : function(name, value)
	{

		this.element.setProperty(name, value);

	},

	// ------------------------------------------------------------------------

	getProperty : function(name)
	{

		return this.element.getProperty(name);

	}

 });
/* file:html/Mjax.HtmlTab.class.js */

// +---------------------------------------------------------------------------+
// | This file is part of the MrJeep Agavi Extension package.                  |
// | Copyright (c) 2006, 2007 Jean-Philippe Dery                               |
// |                                                                           |
// | For the full copyright and license information, please view the LICENSE   |
// | file that was distributed with this source code.                          |
// +---------------------------------------------------------------------------+

Mjax.HtmlTab = Mjax.HtmlElement.extend(
{

	// +-----------------------------------------------------------------------+
    // | PUBLIC VARIABLES                                                      |
    // +-----------------------------------------------------------------------+

    locked : false,

	// +-----------------------------------------------------------------------+
    // | METHODS                                                               |
    // +-----------------------------------------------------------------------+

	initialize : function(element)
	{

		this.parent(element);

		this.element.setContainer(this);
		this.element.addEvent('mouseover', function()
		{

			if (!this.getContainer().isLocked())
			{

				this.className = "alt";

			}

		});

		this.element.addEvent('mouseout', function()
		{

			if (!this.getContainer().isLocked())
			{

				this.className = "gen";

			}

		});

	},

	// -----------------------------------------------------------------------------

	setLocked : function(locked)
	{

		this.locked = locked;

	},

	// -----------------------------------------------------------------------------

	isLocked : function()
	{

		return this.locked;

	}

});
/* file:behavior/Mjax.Selector.class.js */

// +---------------------------------------------------------------------------+
// | This file is part of the MrJeep Agavi Extension package.                  |
// | Copyright (c) 2006, 2007 Jean-Philippe Dery                               |
// |                                                                           |
// | For the full copyright and license information, please view the LICENSE   |
// | file that was distributed with this source code.                          |
// +---------------------------------------------------------------------------+

Mjax.Selector = new Class(
{

	// +-----------------------------------------------------------------------+
	// | METHODS                                                               |
	// +-----------------------------------------------------------------------+

	start : function(rules)
	{

		window.addEvent('domready',function(){this.assign(rules);}.bind(this));

	},

	// ------------------------------------------------------------------------

	assign : function(rules)
	{

		for(var key in rules)
		{

			var rule = rules[key];

			// Loop through all the selectors which are
			// separated by a ,

			key.clean().split(',').each(function(selector)
			//$each(key.clean().split(','), function(selector)
			{

				var pair = selector.split(':');

				$$(pair[0]).each(function(elem)
				{

					// Let see if there is no events binded to the selector. In
					// this case we just fire the rule

					if (pair.length == 1)
					{

						return rule(elem);

					}

					// At this point we have an event attached
					// to the selector so we simply add the event

					elem.addEvent(pair[1], rule.pass(elem));

				});

			});

		}

	}

});
/* file:editor/Mjax.Editor.class.js */

// +---------------------------------------------------------------------------+
// | This file is part of the MrJeep Agavi Extension package.                  |
// | Copyright (c) 2006, 2007 Jean-Philippe Dery                               |
// |                                                                           |
// | For the full copyright and license information, please view the LICENSE   |
// | file that was distributed with this source code.                          |
// +---------------------------------------------------------------------------+

Mjax.Editor = Mjax.HtmlElement.extend(
{

	// +-----------------------------------------------------------------------+
	// | PUBLIC VARIABLES                                                      |
	// +-----------------------------------------------------------------------+

    doc : null,

    win : null,

    body : '',

	// +-----------------------------------------------------------------------+
	// | METHODS                                                               |
	// +-----------------------------------------------------------------------+

	initialize : function(id, body, textarea)
	{

		this.parent(id);

		this.body = body;
		this.win  = this.element.contentWindow;
		this.doc  = this.element.contentWindow.document;

		window.addEvent('domready', this.display.bind(this));

	},

	// -----------------------------------------------------------------------------

	display : function(content)
	{

		this.doc.designMode = 'On';
		this.doc.open();
        this.doc.write('<html>');
        this.doc.write('<head>');
        this.doc.write('<link rel="stylesheet" href="css/edit.css" />');
        this.doc.write('</head>');
        this.doc.write('<body>');
        this.doc.write(this.body);
        this.doc.write('</body>');
        this.doc.write('</html>');
        this.doc.close();
		this.win.focus();

	},

	// -----------------------------------------------------------------------------

	process : function(command)
	{

		command.execute(this.doc);

		this.win.focus();

	},

	// -----------------------------------------------------------------------------

	getContent : function()
	{

		return this.doc.body.innerHTML;

	}

});
/* file:editor/Mjax.EditorCommand.class.js */

// +---------------------------------------------------------------------------+
// | This file is part of the MrJeep Agavi Extension package.                  |
// | Copyright (c) 2006, 2007 Jean-Philippe Dery                               |
// |                                                                           |
// | For the full copyright and license information, please view the LICENSE   |
// | file that was distributed with this source code.                          |
// +---------------------------------------------------------------------------+

Mjax.EditorCommand = new Class(
{

	// +-----------------------------------------------------------------------+
	// | METHODS                                                               |
	// +-----------------------------------------------------------------------+

	execute : function(doc)
	{

		throw 'EditorCommand.execute() : Override me.';

	}

});
/* file:editor/Mjax.EditorCommandBold.class.js */

// +---------------------------------------------------------------------------+
// | This file is part of the MrJeep Agavi Extension package.                  |
// | Copyright (c) 2006, 2007 Jean-Philippe Dery                               |
// |                                                                           |
// | For the full copyright and license information, please view the LICENSE   |
// | file that was distributed with this source code.                          |
// +---------------------------------------------------------------------------+

Mjax.EditorCommandBold = Mjax.EditorCommand.extend(
{

	// +-----------------------------------------------------------------------+
	// | METHODS                                                               |
	// +-----------------------------------------------------------------------+

	execute : function(doc)
	{

		doc.execCommand('bold', false, null);

	}

});
/* file:editor/Mjax.EditorCommandH1.class.js */

// +---------------------------------------------------------------------------+
// | This file is part of the MrJeep Agavi Extension package.                  |
// | Copyright (c) 2006, 2007 Jean-Philippe Dery                               |
// |                                                                           |
// | For the full copyright and license information, please view the LICENSE   |
// | file that was distributed with this source code.                          |
// +---------------------------------------------------------------------------+

Mjax.EditorCommandH1 = Mjax.EditorCommand.extend(
{

	// +-----------------------------------------------------------------------+
	// | METHODS                                                               |
	// +-----------------------------------------------------------------------+

	execute : function(doc)
	{

		doc.execCommand('formatblock', false, '<h1>');

	}

});
/* file:editor/Mjax.EditorCommandH2.class.js */

// +---------------------------------------------------------------------------+
// | This file is part of the MrJeep Agavi Extension package.                  |
// | Copyright (c) 2006, 2007 Jean-Philippe Dery                               |
// |                                                                           |
// | For the full copyright and license information, please view the LICENSE   |
// | file that was distributed with this source code.                          |
// +---------------------------------------------------------------------------+

Mjax.EditorCommandH2 = Mjax.EditorCommand.extend(
{

	// +-----------------------------------------------------------------------+
	// | METHODS                                                               |
	// +-----------------------------------------------------------------------+

	execute : function(doc)
	{

		doc.execCommand('formatblock', false, '<h2>');

	}

});
/* file:editor/Mjax.EditorCommandImage.class.js */

// +---------------------------------------------------------------------------+
// | This file is part of the MrJeep Agavi Extension package.                  |
// | Copyright (c) 2006, 2007 Jean-Philippe Dery                               |
// |                                                                           |
// | For the full copyright and license information, please view the LICENSE   |
// | file that was distributed with this source code.                          |
// +---------------------------------------------------------------------------+

Mjax.EditorCommandImage = Mjax.EditorCommand.extend(
{

	// +-----------------------------------------------------------------------+
	// | METHODS                                                               |
	// +-----------------------------------------------------------------------+

	execute : function(doc)
	{

		doc.execCommand('insertimage', false, prompt('Adresse de l\'image'));

	}

});
/* file:editor/Mjax.EditorCommandItalic.class.js */

// +---------------------------------------------------------------------------+
// | This file is part of the MrJeep Agavi Extension package.                  |
// | Copyright (c) 2006, 2007 Jean-Philippe Dery                               |
// |                                                                           |
// | For the full copyright and license information, please view the LICENSE   |
// | file that was distributed with this source code.                          |
// +---------------------------------------------------------------------------+

Mjax.EditorCommandItalic = Mjax.EditorCommand.extend(
{

	// +-----------------------------------------------------------------------+
	// | METHODS                                                               |
	// +-----------------------------------------------------------------------+

	execute : function(doc)
	{

		doc.execCommand('italic', false, null);

	}

});
/* file:editor/Mjax.EditorCommandLink.class.js */

// +---------------------------------------------------------------------------+
// | This file is part of the MrJeep Agavi Extension package.                  |
// | Copyright (c) 2006, 2007 Jean-Philippe Dery                               |
// |                                                                           |
// | For the full copyright and license information, please view the LICENSE   |
// | file that was distributed with this source code.                          |
// +---------------------------------------------------------------------------+

Mjax.EditorCommandLink = Mjax.EditorCommand.extend(
{

	// +-----------------------------------------------------------------------+
	// | METHODS                                                               |
	// +-----------------------------------------------------------------------+

	execute : function(doc)
	{

		doc.execCommand('createlink', false, prompt('Adresse du lien (Débuter par http://)'));

	}

});
/* file:editor/Mjax.EditorCommandUnderline.class.js */

// +---------------------------------------------------------------------------+
// | This file is part of the MrJeep Agavi Extension package.                  |
// | Copyright (c) 2006, 2007 Jean-Philippe Dery                               |
// |                                                                           |
// | For the full copyright and license information, please view the LICENSE   |
// | file that was distributed with this source code.                          |
// +---------------------------------------------------------------------------+

Mjax.EditorCommandUnderline = Mjax.EditorCommand.extend(
{

	// +-----------------------------------------------------------------------+
	// | METHODS                                                               |
	// +-----------------------------------------------------------------------+

	execute : function(doc)
	{

		doc.execCommand('underline', false, null);

	}

});