//get element by id
function $(id){
	if(typeof(id)=="string"&&id.length>0){var e=document.getElementById(id);}
	if(e&&e.id){return e;}
	return false;
}
//get element by unique class name
function $cn(cn){
	if(typeof(cn)!="string"){return false;}
	var nodes=get_offspring(document);
	var results = [];
	for(var i=0;i<nodes.length;i++){if(nodes[i].className==cn){results[results.length]=nodes[i];}}
	if(results.length>0){return results};
	return false;
}
//get all child (grandchild, etc.) nodes as an array
function get_offspring(e){
	if(!e||!e.hasChildNodes||!e.hasChildNodes()){return false;}
	var nodes=e.childNodes;
	var arr=[];
	for(var i=0;i<nodes.length;i++){arr.push(nodes[i]);var c=get_offspring(nodes[i]);if(c){arr=arr.concat(c);}}
	return arr;
}
//dom event handling
function append_event(e,event,f){
	if(!e||typeof(event)!="string"||typeof(f)!="function"){return false;}
	if(window.addEventListener){
		e.addEventListener(event,f,false);
	}else if(window.attachEvent){
		e.attachEvent("on"+event,f);
	}
}
//style an element
function set_styles(e,styles){
	if(!e||!e.style||typeof(styles)!="object"){return false;}
	for(var k in styles){e.style[k]=styles[k];if(k=="opacity"){e.style.filter="alpha(opacity="+Math.round(styles[k]*100)+")";}}
	return true;
}
//fade images
var f = 0;
var fs = 0;
var sfto = false;
var fto0 = false;
var fto1 = false;
var fout = false;
var fin = false;
function start_fade(){
	clearTimeout(sfto);
	fout = $("fader-"+f);
	fin = $("fader-"+((f+1)%fs));
	fade_out();
	fade_in();
	f++;
	f %= fs;
	sfto = setTimeout(start_fade,4000);
}
function fade_in(){
	clearTimeout(fto1);
	if(!fin||!fin.style) return false;
	var oa = 0;
	if(parseFloat(fin.style.opacity)>0) oa = parseFloat(fin.style.opacity);	
	if(Math.abs(100-oa)<0.01) return false;
	set_styles(fin,{"opacity":oa+(1-oa)*0.08,"zIndex":101,"visibility":"visible"});
	fto1 = setTimeout(fade_in,50);
}
function fade_out(){
	clearTimeout(fto0);
	if(!fout||!fout.style) return false;
	var oa = 0;
	if(parseFloat(fout.style.opacity)>0) oa = parseFloat(fout.style.opacity);	
	if(Math.abs(0-oa)<0.01) return false;
	set_styles(fout,{"opacity":oa+(0-oa)*0.08,"zIndex":1,"visibility":"visible"});
	fto0 = setTimeout(fade_out,50);
}
//initialize
function init(){
	var faders = $cn("fader");
	if(faders.length>1){
		fs = faders.length;
		setTimeout(start_fade,4000);
	}
}
append_event(window,"load",init);