//<script language="Javascript">


function nospam(user) {
	locationstring = "mailto:" + user + "@" + init.ext;
	window.location = locationstring;
}


///// MODULE RELATED FUNCTIONS //////
mod 			= {};

///// MEDIA
mod.media		= {
	album		: function(vars) {
		Object.extend(obj = new Element("div", {id: vars.id+".album", "class":"album"}), mod.media._proto_.album);
		obj.insert(new Element("div",{id:vars.id+".status", "class":"status"}).update("klik..."));
		obj.insert(new Element("div",{"class":"ico"}));
		obj.insert(bar = new Element("div", {"class":"bar"}));
		bar.insert(new Element("div",{id:vars.id+".thumb0", "class":"thumb" }));
		bar.insert(new Element("div",{id:vars.id+".thumb1", "class":"thumb" }));
		obj.insert(control = new Element("div", {"class":"control"}));
		
		control.insert(new Element("div", {id:vars.id+".arright", "class":"arright"}).observe("click", function(e){ this.ancestors()[1].flip(2); }));	
		control.insert(new Element("div", {id:vars.id+".arrleft", "class":"arrleft"}).observe("click", function(e){ this.ancestors()[1].flip(-2); }));
		control.insert(new Element("ul", {id:vars.id+".num", "class":"num"}));
		
		obj.getstring = "&unt=1&lay=1&sze="+vars.sze;
		obj.insert(new Element("div", {"class":"name"}).update(vars.name).observe("click", obj.flip));

		obj.vars	= vars;
		return obj;
	},
	_proto_		: {
		album	: {
			seed	: function(values, obj) {
				if(!obj) obj = this;
				obj.values	= values;
				
				(obj.am = (obj.vars.am<values.length)? obj.vars.am:values.length).times(function(n) {
					$(obj.vars.id+".num").insert(li = new Element("li",{id:obj.vars.id+".n"+n}))
					li.observe("click", obj.show);
				});
				$(obj.vars.id+".thumb0").observe("click", obj.show);
				$(obj.vars.id+".thumb1").observe("click", obj.show);
				
				if(obj.vars.active) {
					obj.n = obj.cur = (obj.vars.random)? (Math.random()*(values.length-2)).round():0;
					tm = setTimeout(function(obj){ obj.show(); }, 1000, obj);  
				} else obj.flip(0);
				
			},
			flip	: function(add, override) {
				obj	= (this.className == "album")? this : this.ancestors()[ (this.ancestors()[1].vars)? 1:((this.ancestors()[2].vars)?2:0)];
				if(!add || typeof add != "number") obj.cur = 0;
				else obj.cur = (obj.cur+add<obj.values.length-1)? ((obj.cur+add>=0)? obj.cur+add : 0) : obj.values.length-2;
				
				$(obj.vars.id+".thumb0").update( new Element("img", {"src":"/engine.room/gfx/img.php?id="+obj.values[obj.cur]['ID']+obj.getstring}) );
				$(obj.vars.id+".thumb0").n = obj.cur;
				$(obj.vars.id+".thumb1").update(new Element("img", {"src":"/engine.room/gfx/img.php?id="+obj.values[obj.cur+1]['ID']+obj.getstring}) );
				$(obj.vars.id+".thumb1").n = obj.cur+1;
				
				span = (obj.cur+obj.am <= obj.values.length)? obj.cur : obj.values.length-obj.am;
				(obj.am).times(function(n) { li = $(obj.vars.id+".n"+n);
					li.update(n+span+1); li.n = span+n;
					if(span+n == obj.active) li.className = "active";
					else if(span+n == obj.cur || span+n == obj.cur+1) li.className = "demi";
					else li.className = "";
				});
				return album;
			},
			show	: function(e) {
				obj	= (this.className == "album")? this : this.ancestors()[ (this.ancestors()[1].vars)? 1:((this.ancestors()[2].vars)?2:0)];
				img		= $(obj.vars.trg).childElements()[0];
				img.src	= "/engine.room/gfx/img.php?sze="+obj.vars.trgsze+"&id="+obj.values[this.n].ID;
				img.observe("load", obj.loaded);
				obj.cur = obj.active = img.n	= this.n; img.refid	= obj.vars.id;
				$(obj.vars.id+".status").update("efkes...");
				obj.flip(1);
			},
			loaded	: function(e) {
				$(this.refid+".status").update((this.n+1)+" van "+$(this.refid+".album").values.length);
			}
		}
	}
} 


///////// OLD CODE (deprecated, to clean)
func_when_loaded = [];

Qfast=function(get,dta){
	
	new Ajax.Request('/inc/ajx/'+get+'.php?'+Object.toJSON(dta), {method:'get', onSuccess: function(com) {
    		if (com.responseText){
				ajx=com.responseText.evalJSON(true);
				if(ajx.ajx){
					$('drop').descendants().invoke("remove");
					drop.ajx= new RegExp(ajx.ajx,"i");
					drop.ajxgroup=ajx.drop;
				}
				if(ajx.drop)fillDrop(ajx);
				
			}
  	}});
}



Query=function(get,dta){
	new Ajax.Request('/inc/ajx/'+get+'.php?'+Object.toJSON(dta), {method:'get', onSuccess: function(com) {
    		if (com.responseText){
				ajx=com.responseText.evalJSON(true);
				if(ajx.gfx){ gfXhttp(ajx); }else if(ajx.err){ errXhttp(ajx); }else if(ajx.red){ redXhttp(ajx); }else{ decodeXhttp(ajx); }
				if(ajx.func) eval(ajx.func);
			}
  	}});
	return false;
}



redXhttp=function(ajx){
	if(ajx.trg)$(ajx.trg).innerHTML=ajx.red;
	setTimeout("window.location='"+ajx.uri+"'",(ajx.int)?ajx.int:0);
}

errXhttp=function(ajx){
	if($(ajx.trg))$(ajx.trg).innerHTML="<b>"+ajx.err.tle+"</b> (code "+ajx.cde+")<br />"+ajx.err.txt;
	if(ajx.red) redXhttp(ajx.red);
}

gfXhttp=function(ajx){

	if(typeof ajx.box.attr.id == "undefined") ajx.box.attr.id = ajx.trg+"_"+ajx.gfx;
	el = elBirth(ajx.box.tpe,ajx.box.attr,ajx.box.cont);
	if(ajx.update) $(ajx.trg).update(el); else $(ajx.trg).appendChild(el);
	
	if(ajx.gfx=="Highlight"){ el.addClassName('message'); new Effect.Highlight(ajx.box.attr.id, ajx.options); }
	else if (ajx.gfx=="Opacity") new Effect.Opacity(ajx.box.attr.id, ajx.options);
	
	if(ajx.red || ajx.uri){ ajx.int = ajx.options.duration*1000; ajx.trg = 0; redXhttp(ajx); }
}


decodeXhttp=function(ajx){
	for(trg in ajx){
		if($(trg) && !ajx.insert) $(trg).update(); else if(!ajx.insert) document.body.appendChild(new Element('div',{id:trg}));
		
		if(ajx[trg].attr){
			$(trg).writeAttribute(ajx[trg].attr);
			ajx[trg]=ajx[trg].ajx;
		}
		
		for(id in ajx[trg]){ 
			if(ajx[trg][id].tpe=='field'){ el=elField(id,ajx[trg][id]);
			}else{
				el=elBirth(ajx[trg][id].tpe,ajx[trg][id].attr,ajx[trg][id].cont);
				el.id=id;
			}
			$(trg).appendChild(el);
		}
		
		if(ajx[trg].func) eval(ajx[trg].func);
	}
}

elField=function(id,raw){
	cont=new Object();
	cont['cont_'+id]={tpe:'div',attr:{'class':"big"},cont:raw.cont};
	el=elBirth('div',Object.extend(raw.attr,{'id':id}),cont);
	$(el).appendChild(new Element('div',{'class':'big_bot'}));
	return el;
}

elBirth=function(tpe,attr,cont,func){
	var el = new Element(tpe,attr);
	if(tpe=='input' && !attr.name) el.name=el.id;
	if(typeof cont == "string" || typeof cont == "number"){
		if(tpe=='input')el.value=cont; else if(tpe=='img') el.alt = cont; else el.update(cont);
	}else if(typeof cont == "object" && typeof cont[0] != "undefined"){
		cont.each(function(s){ el.appendChild((typeof s == "string")?document.createTextNode(s):((s.tagName)? s : elBirth(s.tpe,s.attr,s.cont,s.func) )); });
	}else if(typeof cont == "object"){
		$H(cont).each(function(p){
			el.appendChild( (p.tagName)? p : elBirth(p.value.tpe,(p.value.attr)?Object.extend(p.value.attr,{'id':p.key}):{'id':p.key},p.value.cont,p.value.func) );
		});
	}
	if(typeof func == "object"){
		
		$H(func).each(function(p){
			Event.observe(el, p.key, eval(p.value));
		});
		
	} else if(typeof func == "string") eval(func);
	return el;
}


xForm=function(frm){
	return $(frm).serialize(true);
}

// DROP //
drop={old:false,ajx:/\O/,ajxgroup:false,get:false,type:false,name:false,virgin:true};
Drop=function(prnt,get,type,ajx){}

Pluck = function(obj){
	return obj.id;
}
