//class Zstring
var zstring=new Zstring();
function Zstring(){
this.myWord="";
}//end function

Zstring.prototype.init=function (){
var q_zd="@\n@\t@\"@<br>@setdoc('documents/@setinter('chapter','@setinter('infotext','@setinter('@setvideo('@.jpg@.gif@eventlist_endmark('@eventlist_startmark('@<EVENTLISTSEP>@</EVENTLIST>@','@ @/Slide";
//q_zd=q_zd+"@<div id=@style=@visibility:@visible;@left:@px; @top:@width:@height:@position:absolute;@<img id=@src=@http://@</div>@font-size:@hidden;@font-size:@alt=@cursor:pointer;@onclick=@onmouseout@onmouseover@onmousedown@'downbut(this);'@'viewer_Control(@'touchbut(this);'";
this.q_Dictionary=q_zd.split("@");
}//end function

Zstring.prototype.unzip=function Zstring_unzip(q_str){
this.q_Dictionary=q_sxor(unescape(q_str),2).split("@");
q_str=this.q_Dictionary[0];
this.q_Dictionary[0]="";
this.q_Dictionary[1]="@";
var q_out=new Array();
for(q_ix=0;q_ix<q_str.length;q_ix=q_ix+2){
	q_index=q_base2Dec(q_str.substr(q_ix,2))+1;
	if(q_index<this.q_Dictionary.length){
		q_out[q_out.length]=this.q_Dictionary[q_index];
	}else{
		q_out[q_out.length]="error"+q_index;
	}//end if
}//next
return q_out.join("");
}//end function

Zstring.prototype.toCode=function Zstring_toCode(q_str){
this.init();
q_str=q_str.replace(/@/g,q_zSeparator(0));
q_str=q_str.replace(/\n/g,q_zSeparator(1));
for(q_ix=2;q_ix<this.q_Dictionary.length;q_ix++){
	q_str=replace(q_str,this.q_Dictionary[q_ix],q_zSeparator(q_ix));
}//next
return q_str;
}//end function

Zstring.prototype.zip=function Zstring_zip(q_e){
return escape(this.compress(this.toCode(q_e))); 
}//end function

Zstring.prototype.compress=function Zstring_compress(q_str){
var q_arr=q_str.split("@");
var q_out=new Array();
for(var q_ix=0;q_ix<q_arr.length;q_ix++){
if(q_ix==0){
	if(q_arr[0]>""){
		q_word=q_arr[0];
		q_out[q_out.length]=q_dec2Base(this.getWordIndex(q_word));
	}//end if
}else{
	q_out[q_out.length]=q_arr[q_ix].substr(0,2);
	if(q_arr[q_ix].length>2){
		q_word=q_arr[q_ix].substr(2,q_arr[q_ix].length);
		q_out[q_out.length]=q_dec2Base(this.getWordIndex(q_word));
	}//end if
}//end if
}//next
return q_sxor(q_out.join("")+"@"+this.q_Dictionary.join("@"),2);
}//end function

Zstring.prototype.getWordIndex=function getWordIndex(q_word){
for(var q_ix=2;q_ix<this.q_Dictionary.length;q_ix++){
	if(q_word==this.q_Dictionary[q_ix]){
		return q_ix;
	}//end if
}//next
this.q_Dictionary[this.q_Dictionary.length]=q_word;
return this.q_Dictionary.length-1;
//lookup or add word to dictionary
}//end function

var q_zBase=25;
var q_zOffset=99;
function q_dec2Base(q_x){
return String.fromCharCode(Math.floor(q_x/q_zBase)+q_zOffset)+String.fromCharCode(q_x%q_zBase+q_zOffset);
}//end function

function q_base2Dec(q_x){
return (q_x.charCodeAt(0)-q_zOffset)*q_zBase+(q_x.charCodeAt(1)-q_zOffset);
}//end function

function q_sxor(q_str,q_xor){
var q_n=new Array();
for(var q_ix=0;q_ix<q_str.length;q_ix=q_ix+1){
	q_n[q_n.length]=String.fromCharCode(q_str.charCodeAt(q_ix)^q_xor);
}//next
return q_n.join("");
}//end function

function q_zSeparator(q_ix){
return "@"+q_dec2Base(q_ix);
}//end function

Zstring.prototype.verify=function verify(q_e){
q_t=now();
if(zstring.unzip(zstring.zip(q_e))==q_e){
	return (now()-q_t)+"ms";
}else{
	return 0;
}//end if
}//end function
//end class Zstring
