//Andrey [kee] Peskov, warhuman[]mail.ru, 2009

String.implement({
	ends: function(v){	if(v.length>this.length || (v.length==this.length && v!=this))return false;	return v == this.substr(this.length-v.length); },
	starts: function(v){ if(v.length>this.length || (v.length==this.length && v!=this))return false; return (this.indexOf(v) == 0);},
	clearend:function(v){ if(!this.ends(v))return this;	return this.substr(0,this.length-v.length); },
	clearstart:function(v){ if(!this.starts(v))return this;	return this.substr(v.length);},
	trans: function(){ return kee.trans(this); },
	dec: function(bin,js){ var s = this;if(bin!==false)s = kee.base64_decode(s);if(js!==false)s = JSON.decode(s);return s; },
	cut: function(len,more){more = (more||'...').toString().toLowerCase();	if(this.length>=len)return this;return this.substr(0,len) + more;},
	ex: function(){ return (window[this])?true:false; }
});

if(!Kee) 
var Kee = {};
Kee.Corr = new Class({Implements:[Events, Options],
	options: {},
	initialize: function(o){
			this.setOptions(o);
			this.csh = {};
			if(Browser.Engine.webkit){ window.addEvent('domready', this.domReady.delay(200,this))}
			else{ window.addEvent('domready', this.domReady.bind(this))}
		},
	domReady: function(){
			this.dmp = new Element("div",{style:'display:none;width:98%;border:1px solid black;background:white;position:absolute;top:3px;max-height:300px;min-height:20px;padding:3px;overflow:auto;'}).inject(document.body);
			this.dmp.togg = function(v){if(v!==true&&v!==false)v=(this.getStyle('display')=='none'); this.setStyle('display',(v?'block':'none')); return this; };
			this.ifr();
		},
	ifr:function(){
			return;
			var i = $(document.body).getElements('iframe');
			if(!i)return;
			this.ifr = [];
			i.each(function(ifr){
				ifr = $(ifr);
				if(ifr && ifr.document){
					var h = ifr.document.getElement("head");
					new Element('style',{src:'/css/wyg.css'}).inject(h,"bottom");
				}
			});
		},
	dump: function(obj){
			this.dmp.togg(true).innerHTML += JSON.encode(obj) + '<br>';
			this.dmp.scrollTo(0,this.dmp.getScrollSize().y); 
	},		
	keyru:"а,б,в,г,д,е,ё,ж,з,и,й,к,л,м,н,о,п,р,с,т,у,ф,х,ц,ч,ш,щ,ъ,ы,ь,э,ю,я, ,-",
	keyen:"a,b,v,g,d,e,yo,zh,z,i,i,k,l,m,n,o,p,r,s,t,u,f,h,ts,ch,sh,sh,,y,,e,u,ya,_,_",
	e:function(o,cash){ if(cash!==true){ return document.getElementById(''+o); } else{ if(!this._e)this._e={};  if(!this._e[o]){ var el = document.getElementById(''+o); if(el) this._e[o]=el; return el;} return this._e[o]; } },
	trans:function(n){ 	n = n||'';var r = this.transh(); n = n.toLowerCase().replace(/^\\s+|\\s+$/g,"").replace(r.re,function(o){return r.rh[o];}).replace(/[^a-z0-9_]/ig,""); return n; },	
	transh:function(){ if(!this._transh){ var r = this.keyru.split(','); var e = this.keyen.split(','); var rh = {}; for(var i=r.length;i>=0;i--)rh[r[i]]=e[i]; var re = new RegExp("("+r.join('|')+")","ig"); this._transh = {rh:rh, re:re}; }; return this._transh;},
	limits: function(v,min,max){ if(v>max){v=max;} else if(v<min){ v=min;} return v;},
	key64:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
	base64_encode: function (inc) { var out = ""; var c = []; var e = []; inc = this.utf8(inc); var i = 0; while (i < inc.length) { c = [inc.charCodeAt(i++), inc.charCodeAt(i++), inc.charCodeAt(i++)]; e = [c[0]>>2,((c[0]&3)<<4)|(c[1]>>4),((c[1]&15)<<2)|(c[2]>>6), c[2]&63]; if (isNaN(c[1])) { e[2]=e[3]=64; } else if (isNaN(c[2])) { e[3]=64; }; out += (this.key64.charAt(e[0]) + this.key64.charAt(e[1]) + this.key64.charAt(e[2]) + this.key64.charAt(e[3])); } return out;},	
	base64_decode: function (inc) {inc = inc.replace(/[^A-Za-z0-9\+\/\=]/g,''); var out = ''; var i = 0; var c = []; var e = []; while (i < inc.length) { e = [this.key64.indexOf(inc.charAt(i++)), this.key64.indexOf(inc.charAt(i++)), this.key64.indexOf(inc.charAt(i++)), this.key64.indexOf(inc.charAt(i++))]; c = [(e[0]<<2)|(e[1]>>4), ((e[1]&15)<<4)|(e[2]>>2), ((e[2]&3)<<6)|e[3]]; out += (String.fromCharCode(c[0]) + ((e[2]!=64)?String.fromCharCode(c[1]):'') + ((e[3]!=64)?String.fromCharCode(c[2]):'')); }	return this.deutf8(out);},
	utf8: function (s) {var u = ''; s = s.replace(/\r\n/g,"\n"); for (var n=0;n<s.length;n++) {var c = s.charCodeAt(n);  u += (c<128) ? String.fromCharCode(c) : (((c>127)&&(c<2048))? (String.fromCharCode((c>>6)|192) + String.fromCharCode((c & 63)|128)): (String.fromCharCode((c>>12)|224) + String.fromCharCode(((c>>6)&63)|128) + String.fromCharCode((c&63)|128))); } return u; },
	deutf8: function(u){ var s = ''; var i = 0; var c = c1 = c2 = 0; while ( i < u.length ) { c = u.charCodeAt(i); if (c<128) { s += String.fromCharCode(c); i++; } else if((c>191)&&(c<224)) { c2 = u.charCodeAt(i+1); s += String.fromCharCode(((c&31)<<6)|(c2&63)); i += 2; } else {c2 = u.charCodeAt(i+1); c3 = u.charCodeAt(i+2); s += String.fromCharCode(((c&15)<<12)|((c2&63)<<6)|(c3&63)); i += 3;} } return s;},
	ex: function(o){var m = false; try{if(o)m=true;}catch(e){}; return m; }		
});
var kee = new Kee.Corr();





