function initRollOverImages() {
	var image_cache = new Object();
	$(".rollover").not("[@src*='_on.']").each(function(i) {
		var imgsrc = this.src;
		var dot = this.src.lastIndexOf('.');
		var imgsrc_on = this.src.substr(0, dot) + '_on' + this.src.substr(dot, 4);
		image_cache[this.src] = new Image();
		image_cache[this.src].src = imgsrc_on;
		$(this).hover(
			function() { this.src = imgsrc_on; },
			function() { this.src = imgsrc; }
		);
	});
}
$(document).ready(initRollOverImages);

var ImgSrcChanges={

	varsion:"1.0.0",

	set:function(){
		//対象となるAタグのクラス名
		this.set_class="ImgSrcChanges";
		
		//対象を切り替えるボタンアクション(onclick or onmouseover)
		this.bt_action="onmouseover";
		
		//ボタンからマウスアウトした際に、対象を元の画像に戻すか true or false
		this.bt_mouseout_back=false;
		
		//プリロードイメージを仕様するか
		this.preloadImgFlag=true;
		
		this.targetIds=new Array();
		
		this.window_load();
	},
	
	execute:function(){
		ImgSrcChanges.btaction();
		if(ImgSrcChanges.bt_mouseout_back){
			ImgSrcChanges.targetDefaltImgSet();
		}
	},
	
	btaction:function(){
		var a=document.getElementsByTagName("a");
		var act=this.bt_action;
		for(var i=0; i<a.length; i++){
			if(a[i].className == this.set_class){
				if(this.bt_action == "onmouseover"){
					a[i].onmouseover=function(){
						var target=document.getElementById(this.target);
						if(target){
							target.src=this.href;						
						}
					};
				}
				if(this.bt_action == "onclick"){
					a[i].onclick=function(){
						var target=document.getElementById(this.target);
						if(target){
							target.src=this.href;						
						}
						return false;
					};
				}else{
					a[i].onclick=function(){
						return false;
					}
				}
				if(this.bt_mouseout_back){
					a[i].onmouseout=function(){
						var target=document.getElementById(this.target);
						if(target){
							target.src=target.lowsrc;
						}
					};
				}
				if(this.preloadImgFlag){
					this.preload(a[i].href);
				}
				this.targetIds.push(a[i].target);
			}
		}
	},
	
	targetDefaltImgSet:function(){
		var es={};
		var ids= this.targetIds;
		for(var i=0; i<ids.length; i++){
			if(es[ids[i]]){
				ids[i]=null;
			}else{
				es[ids[i]]=true;
				var tarObj=document.getElementById(ids[i]);
				if(tarObj){
					tarObj.lowsrc=tarObj.src;
				}
			}
		}
	},
	
	preload:function(img){
		this.preloadnum=(this.preloadnum >= 0)?this.preloadnum+1:0;
		if(this.preloadnum == 0){
			this.preloadimgs=new Array();
		}
		this.preloadimgs[this.preloadnum]=new Image();
		this.preloadimgs[this.preloadnum].src=img;
	},

	window_load:function(){
		if(window.addEventListener) {
			window.addEventListener("load", this.execute, false);
		}
		else if(window.attachEvent) {
			window.attachEvent("onload", this.execute);
		}
	}
};
ImgSrcChanges.set();

