/*	name			: ClassBehaviours, the javascript framework based on class-name parsing	update			: 9.2.2	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(){}

	// replace in class
	jQuery.classBehaviours.handlers.classMouseHover = {
		// properties
		name: 'classMouseHover',
		// methods
		start: function(node){
			node.onmouseover = this.addHover;
			node.onmouseout = this.remHover;
		},
		hasNoStateClass: function(objNode){
			return (objNode.className.indexOf('link')<0 && objNode.className.indexOf('hover')<0 && objNode.className.indexOf('active')<0);
		},
		// events
		addHover: function(that){
			var objNode = (typeof(this.nodeName)=='undefined') ? that : this ;
			var cmh = jQuery.classBehaviours.handlers.classMouseHover;
			// replace link by hover
			objNode.className = (cmh.hasNoStateClass(objNode)) ? 'hover ' + objNode.className : objNode.className.replace('link','hover') ;
			// if there is an image within, replace it with the hover state too
			allImages = objNode.getElementsByTagName('IMG');
			if(allImages.length>0) allImages[0].src = allImages[0].src.replace('_link','_hover');
		},
		remHover: function(that){
			var objNode = (typeof(this.nodeName)=='undefined') ? that : this ;
			var cmh = jQuery.classBehaviours.handlers.classMouseHover;
			// replace hover by link
			objNode.className = (cmh.hasNoStateClass(objNode)) ? 'link ' + objNode.className : objNode.className.replace('hover','link') ;
			// if there is an image within, replace it with the hover state too
			allImages = objNode.getElementsByTagName('IMG');
			if(allImages.length>0) allImages[0].src = allImages[0].src.replace('_hover','_link');
		},
		addActive: function(that){
			var objNode = (typeof(this.nodeName)=='undefined') ? that : this ;
			var cmh = jQuery.classBehaviours.handlers.classMouseHover;
			// replace link by active
			objNode.className = objNode.className.replace('link','active') ;
			// replace hover by active
			objNode.className = objNode.className.replace('hover','active') ;
			// if there's still no active class
			if(cmh.hasNoStateClass(objNode)) objNode.className = 'active ' + objNode.className;
		}
	}
			
	// add this addon to the jQuery object
	if(typeof(jQuery.fn)!='undefined'){
		// extend jQuery with this method
		jQuery.fn.classMouseHover = function(){
			return this.each(
				function(){
					jQuery.classBehaviours.handlers.classMouseHover.start(this);
				}
			);
		};
		// set the event handler for this jQuery method
		$(document).ready(
			function(){
				$(".classMouseHover").classMouseHover();
			}
		);
	}

