/* ---------- start up items ----------
the item in the Array "startup_items" will be executed in order as a function, when the document is loaded.
when you want to add an attribute "onload" in body tag (and that sucks), you'd better make it a function and push into the Array "startup_items".
*/
var startup_items = new Array();
//window.onload = function(){ for(var i=0 ; i<startup_items.length ; i++) startup_items[i](); };
function startup(){ for(var i=0 ; i<startup_items.length ; i++) startup_items[i](); };

/* ---------- common library ---------- */

function getElementsByTagAndClassName(tag_name,class_name){
	/*
	this is not a method but a function.
	This returns it as Array, when the corresponding elements are discovered.
	This returns false, when the corresponding tag name or class name is not able to be discovered.
	when you do not want to limit the kind of tag, you can use "*" for the 1st argument but it's so expensive.
	*/
	var return_array = new Array();
	if(!document.getElementsByTagName(tag_name)) return false;

	var tmp = document.getElementsByTagName(tag_name);
	for(var i=0 ; i<tmp.length ; i++){
		var class_array = tmp[i].className.split(" ");
		for(var c=0 ; c<class_array.length ; c++){
			if(class_array[c] == class_name){
				return_array[return_array.length] = tmp[i];
			}
		}
	}
	if(return_array.length < 1) return false;
	return return_array;
}

/* ----- rollover ----- */

function SwapAndRestoreImage(){
	/*
	when you want to use the rollover effect in any JavaScript, You'd better use this function at window.onload.
	if the sauce file name of an Image object is not a regular form or there is no Image object in children of the node, this will not be executed.
	you have nothing to do to preload swap images :-)
	*/
	SARI_tagName   = "img";
	SARI_className = "SARI";
	SARI_array     = new Array();

	function SARI(obj){
		this.image = obj;
		this.image.f1 = new Image();
		this.image.f1.src = obj.src;
		this.image.f2 = new Image();
		this.image.f2.src = obj.src.replace("_f1","_f2");
		this.image.onmouseover = function(){ if(this.f2) this.src = this.f2.src; }
		this.image.onmouseout  = function(){ if(this.f1) this.src = this.f1.src; }
	}

	var tmp = getElementsByTagAndClassName(SARI_tagName,SARI_className);
	for(var i=0 ; i<tmp.length ; i++){
		if(!tmp[i].src || !tmp[i].src.match(/.*_f1\.[a-zA-Z0-9]+/)) continue;

		SARI_array[SARI_array.length] = new SARI(tmp[i]);
	}
}
startup_items[startup_items.length] = SwapAndRestoreImage;



