

red.prototype.util = {
	
	camelize : function ( value ) {
		return value.replace(/\-(.)/g, function(m, l){return l.toUpperCase()});
	},
	
	deCamelize : function ( value ) {
		return value.replace(/([A-Z])/g, '-$1').toLowerCase();
	},
	
	fromto : function(numberfrom,numberto,totalsteps,step,max){
		if(numberfrom == numberto){
			return numberfrom;
		}
		if(max == null){
			var diff = (numberfrom-numberto)/totalsteps;
			return numberfrom-(Math.round(diff*step));	
		}
		else{
			var diff1 = (numberfrom-numberto);
			var diff2 = (max-Math.max(numberfrom,numberto))+Math.min(numberfrom,numberto);
			if(Math.abs(diff1) <= Math.abs(diff2)){
				var diff = diff1/totalsteps;
				return numberfrom-Math.round(diff*step);	
			}
			else{
				var diff = diff2/totalsteps;
				//rechtsrum
				if(numberfrom >= numberto){
					var total = numberfrom+(Math.round(diff*step));
					if(total > max){return total-max;}
					else{return total;}
				}
				//linksrum
				else{
					var total = numberfrom-(Math.round(diff*step));
					if(total < 0){return max-Math.abs(total);}
					else{return total;}
				}
			}
		}
	},
	
	collect : function(a,f){
		var n=[];
		for(var i = 0;i < a.length;i++){
			var v = f(a[i]);
			if(v != null){
				n.push(v);
			}	
		}
		return n;
	},
	
	popup : function(w,h,site){
		x = screen.availWidth/2-w/2;
		y = screen.availHeight/2-h/2;
		var Fensteroptionen = "toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=1,resizable=1";
		var popupWindow = window.open(
		'','','width='+w+',height='+h+',left='+x+',top='+y+',screenX='+x+',screenY='+y+
		','+Fensteroptionen);
		popupWindow.document.open('text/html');
		popupWindow.document.write(site);
		popupWindow.document.close();
		return popupWindow;
	},
	
	htmlsite : function(title,head,body){
		var html = '<html><head><title>'+title+'</title>';
		html += head+'</head><body>'+body+'</body></html>';
		return html;	
	}
		
	

};