//--tools by artico@overdesign.net

/* function started with $ means operations with HTML Elements */

$get=function(id, windowName){
	if(!windowName) windowName = self;
	return windowName.document.getElementById(id);
}

$getbyclass=function(className, from, tagName){
	var out = [];
	if(!from){from = document;}
	if(!tagName){tagName = ['*'];}
	if(!(tagName instanceof Array)){tagName = [tagName];}
	foreach(tagName, function(tagName){
		foreach(from.getElementsByTagName(tagName), function(elem){
			if(new RegExp('\b'+className+'\b').test(elem.className)){
				out.push(elem);
			}
		}, null, true);
	});
	return out;
}

imagePreload = function(src) {
	if ( !(src instanceof Array) ) {
		src=[src];
	}
	for ( var i=0; i<src.length; i++ ){
		(new Image()).src=src[i];
	}
}


$make=function(tag,id,className,content,attr,prop){
	var obj;
	if(tag!='#text'){
		obj=document.createElement(tag);
		if(id){obj.id=id;}
		if(className){obj.className=className;}
		if(!(content instanceof Array)){content=[content];}
		for(var i=0; i<content.length; i++){
			switch(typeof(content[i])){
				case 'string': if(content[i].length){obj.innerHTML+=content[i];} break;
				case 'object': obj.appendChild(content[i]); break;
				case 'undefined': break;
				default: obj.innerHTML=content[i]; break;
			}
		}
	}
	else{
		obj=document.createTextNode(content);
	}
	if(attr){
		for(var i in attr){
			if(obj.setAttribute){
				obj.setAttribute(i, attr[i]);
			}
			else{
				obj[i]=attr[i];
			}
		}
	}
	if(prop){
		for(var i in prop){
			obj[i]=prop[i];
		}
	}
	return obj;
}

$isparent=function(elem,parent){
	if(!elem){return false;}
	var p=elem.parentNode;
	while(p){
		if(!p){return false;}
		if(p==parent){return true;}
		p=p.parentNode;
	}
}

/* prototypes extending */

/*
Array.prototype.find=function(){
	var found=0;
	for(var i=0;i<this.length;i++){
		for(var j=0;j<arguments.length;j++){
			if(this[i]==arguments[j]){found++;}
		}
	}
	return found;
}

if (!Array.forEach) {
	Array.prototype.forEach = function(func){
		for(var i=0; i<this.length; i++){
			func.call(this, this[i]);
		}
	}
}

Array.prototype.replace=function(){
	var found=0;
	for(var i=0;i<this.length;i++){
		if(this[i]==arguments[0]){
			found++;
			if(arguments[1]){
				this[i]=arguments[1];
			}
			else{
				this.splice(i,1);
			}
		}
	}
	return found;
}
*/
/* service functions */

extend = function(obj, libs){
	if(!(libs instanceof Array)){libs = [libs];}
	for(var i=0; i<libs.length; i++){
		for(var j in libs[i]){
			obj[j] = libs[i][j];
		}
	}
}

foreach = function(set, func, context, forceArray){
	if(!context) context = self;
	if((set instanceof Array) || forceArray){
		for(var i=0; i < set.length; i++){
			func.call(context, set[i]);
		}
	}
	else{
		for(var i in set){
			func.call(context, set[i]);
		}
	}
}

alarm=function(input,dw){
	var type=typeof(input);
	if(type=='object'){
		str='';
		for(var i in input){
			str+=i+' = '+input[i]+'\n';
			}
		}
		else{str=input;}
		if(dw){
			var nw=open();
			nw.document.write(str);
			}
			else{
				alert(	'Alarm ['+type+']'
					+' (length: '+((type!='undefined')?input.length:'...')+')'
					+'\n'+str);
			}
}

provide={
	gets:function(windowName){
		if(!windowName){windowName=self;}
		var getsarr=windowName.location.search.substring(1).split('&');
		var gets={};
		for(var i=0; i<getsarr.length; i++){
			gets[getsarr[i].split('=')[0]]=getsarr[i].split('=')[1];
		}
		return gets;
	},
	imagePreload:function(src){
		if(!(src instanceof Array)){src=[src];}
		for(var i=0; i<src.length; i++){
			(new Image()).src=src[i];
		}
	},
	stopIEflicker:function(){
		try{document.execCommand("BackgroundImageCache", false, true);}
		catch(e){}
	},
	stopPageLoading:function(){
		if(window.stop){
			window.stop();
		}
		else if(document.execCommand){
			document.execCommand('Stop');
		}
	}
}


mailto = function(e){
	location.href = 'mailto:' + e.replace('[at]', '&#64;');
}


EmailCode = function(email)
{
if (email != "") {
ecd = "";
for (i = 0; i < email.length; i++) {
ecd += "\&amp;amp;#" + String(email.charCodeAt(i)) + ";";
};
document.write (email + ecd);
};
};