/*	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(){}

	// blinks
	jQuery.classBehaviours.handlers.blink = {
		// properties
		name: 'blink',
		nodes: new Array(),
		index: -1,
		interval: null,
		// methods
		start: function(node){
			// set the starting class, if not present
			if(node.className.indexOf('blinkon')<0) node.className += " blinkon";
			// make new blink entry and fill it with the node's settings
			blinkObject = new jQuery.classBehaviours.handlers.blink.BlinkObject;
			blinkObject.node = node;
			blinkObject.jiffy = parseInt(jQuery.classBehaviours.utilities.getClassParameter(node, 'jiffy', '1'));
			this.nodes[this.nodes.length] = blinkObject;
			// start blink loop only the first time
			if(this.index<0){this.index++; this.interval = setInterval("jQuery.classBehaviours.handlers.blink.loop()", 512);}
		},
		// events
		loop: function(blinkIndex){
			var blk = jQuery.classBehaviours.handlers.blink;
			// count this update
			blk.index = (blk.index>100000) ? 0 : blk.index + 1 ;
			// for all blink objects in the list
			for(var a=0; a<blk.nodes.length; a++)
				// check if this count is the right jiffy
				if(blk.index%blk.nodes[a].jiffy==0)
					// toggle the blink class
					blk.nodes[a].node.className = (blk.nodes[a].node.className.indexOf('blinkoff')>-1) ? blk.nodes[a].node.className.replace('blinkoff','blinkon') : blk.nodes[a].node.className.replace('blinkon','blinkoff');	
		}
	}
		jQuery.classBehaviours.handlers.blink.BlinkObject = function(){
			this.node = null;
			this.jiffy = 1;
		}
			
	// add this addon to the jQuery object
	if(typeof(jQuery.fn)!='undefined'){
		// extend jQuery with this method
		jQuery.fn.blink = function(){
			return this.each(
				function(){
					jQuery.classBehaviours.handlers.blink.start(this);
				}
			);
		};
		// set the event handler for this jQuery method
		$(document).ready(
			function(){
				$(".blink").blink();
			}
		);
	}


