


 function bm_class()
 {

	this.timer= new timer_class();




	this.element= function(e)
	{
		return (e == '') ? false : document.getElementById(e);
	}

	this.get= function(node, tagname, classname, nosingleclass)
	{
		if (typeof(node) == 'string') node= this.element(node);
		blocks= node.getElementsByTagName(tagname);
		blocks_choice= new Array();
		if (classname != null) for (var x= 0; x < blocks.length; x++) if (blocks[x].className == classname || (nosingleclass == true && blocks[x].className.contains(classname))) { blocks_choice.push(blocks[x]); }
		return (classname != null) ? (blocks_choice == '') ? false : blocks_choice : (blocks == '') ? false : blocks;
	}
	
	this.execute= function(elements, action, vars)
	{
		var returns= new Array();
		for (var x= 0; x < elements.length; x++) returns.push(action(elements[x], x, vars));
		return returns;
	}



	this.moveto= function(element, type, to, forcefrom, offset)
	{
		this.timer.addwork(element, 'move', type, {to : to, forcefrom : forcefrom}, offset);
	}


	this.fadein= function(element, offset)
	{
		this.timer.addwork(element, 'fade', null, {from : 0, to : 100}, offset);
	}

	this.fadeout= function(element, offset)
	{
		this.timer.addwork(element, 'fade', null, {from : 100, to : 0}, offset);
	}

	this.fadeto= function(element, to, defaultfrom, offset)
	{
		this.timer.addwork(element, 'fade', null, {from_default : defaultfrom, to : to}, offset);
	}

	this.fade= function(element, from, to, offset)
	{
		this.timer.addwork(element, 'fade', null, {from : from, to : to}, offset);
	}



	function timer_class()
	{
		this.workqueue= new Array();
		this.timerinterval;
		this.active= false;


		this.checkinterval= function()
		{
			if (!this.active) { this.timerinterval= setInterval('bm.timer.work()', 20); this.active= true; }
		}


		this.work= function()
		{
			if (this.workqueue.length == 0) { clearInterval(this.timerinterval); this.active= false; return; }

			var now= new Date().getTime();

			for (job in this.workqueue) if (now >= this.workqueue[job][3]) if (this['action_'+this.workqueue[job][1]](this.workqueue[job][0], this.workqueue[job][2])) this.removework(this.workqueue[job][0], this.workqueue[job][1], this.workqueue[job][2]);
		}


		this.addwork= function(element, func, type, vars, offset)
		{
			var now= new Date().getTime();
			var offset= (offset == null) ? 0 : offset;

			if (!element['vars']) element['vars']= new Object();
			if (!element['vars'][func]) element['vars'][func]= new Object();

			if (type == null) for (var v in vars) element['vars'][func][v]= vars[v];
			else { if (!element['vars'][func][type]) element['vars'][func][type]= new Object(); for (var v in vars) element['vars'][func][type][v]= vars[v]; }

			var addarray= new Array(element, func, type, now-(-offset));
			var added= false;

			for (var x= 0; x < this.workqueue.length; x++) if (this.workqueue[x][0] == element && this.workqueue[x][1] == func) { if (this.workqueue[x][2] != null && type != null && this.workqueue[x][2] != type) { } else { this.workqueue[x]= addarray; added= true; } }

			if (!added) this.workqueue.push(addarray);

			this.checkinterval();
		}


		this.removework= function(element, func, type)
		{
			for (var x= 0; x < this.workqueue.length; x++) if (this.workqueue[x][0] == element) if (func == this.workqueue[x][1] || func == null) if (type == this.workqueue[x][2] || type == null) { this.workqueue.splice(x, 1); x--; }
		}


		this.action_fade= function(element, type)
		{
			if (element.style.display != 'block') element.style.display= 'block';

			var vars= element['vars']['fade'];

			var from= (!vars['from'] && vars['from'] != 0) ? vars['from_default'] : vars['from'];
			var to= vars['to'];

			var c= Math.round(1/10 * Math.abs(from-to) + 2);
			var newvalue= (to > from) ? (from-(-c) > to) ? to : from-(-c) : (from-c < to) ? to : from-c;
			
			if (newvalue == 0) { element.style.display= 'none'; return true; }

			vars['from']= newvalue;

			element.style.filter= (newvalue == 100) ? '' : 'alpha(opacity = '+newvalue+')';
			//element.style.filter= 'progid:DXImageTransform.Microsoft.Alpha(Opacity=' + newvalue + ')';
			element.style["-moz-opacity"]= ""+(newvalue/100);
			element.style["opacity"]= ""+(newvalue/100);

			return (newvalue == to) ? true : false;
		}


		this.action_move= function(element, type)
		{
			if (element.style.display != 'block') element.style.display= 'block';

			var vars= element['vars']['move'][type];

			switch (type)
			{
				case 'width'	:	var from= element.offsetWidth;
							break;
				case 'height'	:	var from= element.offsetHeight;
							break;
				case 'left'	:	var from= element.offsetLeft;
							break;
				case 'top'	:	var from= element.offsetTop;
							break;
				default		:	var from= vars['from'];
			}

			if (vars['forcefrom'] != null) { from= vars['forcefrom']; vars['forcefrom']= null; }

			var to= vars['to'];

			var sub= (to - from) / 5 * (-1);
			if (sub < 2 && sub > 0) sub= 2;
			if (sub < 0 && sub > -2) sub= -2;
			var newvalue= from - Math.round(sub);
			if (Math.abs(from-to) <= 2) newvalue= to;

			if (newvalue == 0 && (type == 'width' || type == 'height')) { element.style.display= 'none'; return true; }
			else element.style[type]= newvalue + 'px';

			vars['from']= newvalue;

			return (newvalue == to) ? true : false;
		}
		
	}



	this.addevent= function(element, type, func)
	{
		if (element.addEventListener) element.addEventListener(type, func, false);
		else if (element.attachEvent)
		{
			element["e"+type+func]= func;
			element[type+func]= function() { element["e"+type+func](window.event); }
			element.attachEvent("on"+type, element[type+func]);
		}
	}

	this.removeevent= function(element, type, func)
	{
		if (element.removeEventListener) element.removeEventListener(type, func, false);
		else if (element.detachEvent)
		{
			element.detachEvent("on"+type, element[type+func]);
			element[type+func]= null;
			element["e"+type+func]= null;
		}
	}



	this.nochild= function(element, e, ieinvers)
	{
		var etarget= (e.relatedTarget) ? e.relatedTarget : (ieinvers) ? e.fromElement : e.toElement;
		var echildren= element.getElementsByTagName('*');
		for (var i= 0; i < echildren.length; i++) if(echildren[i] == etarget || element == etarget) return false;
		return true;
	}

 }


 var bm= new bm_class();




 Array.prototype.contains= function(value)
 {
	for (var i= 0; i < this.length; i++) if (this[i] === value) return true;
	return false;

 };


 Array.prototype.drop= function(value)
 {
	for (var x= 0; x < this.length; x++) if (this[x] == value) { this.splice(x, 1); return true; }
	return false;

 };


 String.prototype.contains= function(value)
 {
	if (this == value || this.search(value) >= 0) return true;
	return false;
 }


 String.prototype.cleanatt= function()
 {
	return (this.substr(this.length-2, 2) == 'px') ? this.substr(0, this.length - 2) : this;
 }


