// JavaScript Document

var LsPT_ImageReplacement = Class.create();

LsPT_ImageReplacement.prototype = {
	
	initialize : function(inActionElement, inReplaceAction, inRollbackAction, inReplaceElement, inReplaceImage, inFilterFunc){
		if($(inReplaceElement).tagName == "IMG"){
			this.replaceElement = $(inReplaceElement);
			this.replaceImage = inReplaceImage;
			this.defaultImage = this.replaceElement.src;
			if(inFilterFunc != ""){
				this.filterName = inFilterFunc + "()";
			}
			Event.observe($(inActionElement), inReplaceAction, this.replaceToRollOver.bind(this));
			if(inRollbackAction != ""){
				Event.observe($(inActionElement), inRollbackAction, this.replaceToDefault.bind(this));
			}
		}else{
			alert("Element " + inReplaceElement + " is not image tag.");
		}
	},
	
	replaceToRollOver : function(){
		this.replaceElement.src = this.replaceImage;
		if(typeof this.filterName != "undefined"){
			this.replaceElement.style.opacity = 0;
			this.replaceElement.style.filter = "alpha(opacity=0)";
			//funcFilter();
			eval(this.filterName);
		}
	},
	
	replaceToDefault : function(){
		this.replaceElement.src = this.defaultImage;
		this.replaceElement.style.opacity = 1;
		this.replaceElement.style.filter = "alpha(opacity=100)";
	}
	
}

/*
function funcFilter(inOpac){
	var chKeta = Math.pow(10,2);
	var tmp_num = inOpac*chKeta;
	var tmp_result = Math.round(tmp_num);
	var result = tmp_result/chKeta;
	$("mainMap").style.opacity = result;
	$("mainMap").style.filter = "alpha(opacity=" + result*100 + ")";
}
*/


var LsPT_GroupImage = Class.create();

LsPT_GroupImage.prototype = {
	
	initialize : function(inReplaceEvent){
		this.replaceEvent = inReplaceEvent;
		this.images = {};
		if(arguments.length>1){
			for(i=1; i<arguments.length; i=i+2){
				if(arguments[i] != "undefined" && arguments[i+1] != "undefined"){
					this.addImage(arguments[i], arguments[i+1]);
				}
			}
		}
	},
	
	addImage : function(inElement, inReplaceSrc){
		if($(inElement).tagName == "IMG"){
			if(typeof this.images[$(inElement).id] == "undefined"){
				this.images[$(inElement).id] = { orgSrc : $(inElement).src, replaceSrc : inReplaceSrc };
				//Event.observe($(inElement), this.replaceEvent, this.rollbackReplace.bind(this));
				Event.observe($(inElement), this.replaceEvent, this.doReplace.bind(this), true);
			}
		}else{
			alert(inElement + " is not image tag.");
		}
	},
	
	doReplace : function(evt){
		for(id in this.images){
			this.rollbackReplace(id);
		}
		Event.element(evt).src = this.images[Event.element(evt).id].replaceSrc;
	},
	
	rollbackReplace : function(inElement){
		if($(inElement) != "undefined"){
			$(inElement).src = this.images[$(inElement).id].orgSrc;
		}
	}
	
}