var imagesNormal = new Object();
var imagesHilite = new Object();
function SwapImage (name,normalSrc,hiliteSrc) {
   this.name = name;
   this.normalSrc = normalSrc;
   this.hiliteSrc = hiliteSrc;
}
function setupSwapImages(swapImages) {
    preloadSwapImages(swapImages);
    setupSwapEvent(swapImages);
}


function preloadSwapImages (a) {
    for (var i=0; i < a.length; i++){
        imagesNormal[a[i].name] = new Image();
        imagesNormal[a[i].name].src = a[i].normalSrc;
        imagesHilite[a[i].name] = new Image();
        imagesHilite[a[i].name].src = a[i].hiliteSrc;
    }
}
function setupSwapEvent (a) {
    for (var i=0; i<a.length; i++){
        var images = getElementsByClass(a[i].name);
        for (var j=0; j<images.length; j++){
            var image = images[j];
            if (image.getAttribute("src")){
               image.onmouseover = function () {swapImage( this, "hilite" );}
               image.onmouseout  = function () {swapImage( this, "normal" );}
            }
        }
    }
}
function swapImage(image,type){
    if (type=="hilite") {
       image.src = imagesHilite[image.className].src;
    } else if (type=="normal") {
       image.src = imagesNormal[image.className].src;
    }
}

function getElementsByClass(searchClass,node,tag) {
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp('(^|\\s)'+searchClass+'(\\s|$)');
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}

var swapImages = [new SwapImage('i_contact','/image/en/top/contact.gif','/image/en/top/contact2.gif'),new SwapImage('i_ic','/image/en/top/ic.gif','/image/en/top/ic2.gif'),new SwapImage('i_semi','/image/en/top/semi.gif','/image/en/top/semi2.gif'),new SwapImage('i_develop','/image/en/top/develop.gif','/image/en/top/develop2.gif'),new SwapImage('i_corp','/image/en/top/corp.gif','/image/en/top/corp2.gif'),new SwapImage('i_recruit','/image/en/top/recruit.gif','/image/en/top/recruit2.gif'),new SwapImage('i_news','/image/en/top/newslist.gif','/image/en/top/newslist2.gif'),new SwapImage('i_japanese','/image/en/top/japanese.gif','/image/en/top/japanese2.gif'),new SwapImage('m_contact','/image/en/common/contact.gif','/image/en/common/contact2.gif'),new SwapImage('m_top','/image/en/common/top.gif','/image/en/common/top2.gif'),new SwapImage('m_ic','/image/en/common/ic.gif','/image/en/common/ic2.gif'),new SwapImage('m_semi','/image/en/common/semi.gif','/image/en/common/semi2.gif'),new SwapImage('m_develop','/image/en/common/develop.gif','/image/en/common/develop2.gif'),new SwapImage('m_corp','/image/en/common/corp.gif','/image/en/common/corp2.gif'),new SwapImage('m_recruit','/image/en/common/recruit.gif','/image/en/common/recruit2.gif'),new SwapImage('m_news','/image/en/common/news.gif','/image/en/common/news2.gif'),new SwapImage('m_japanese','/image/en/common/japanese.gif','/image/en/common/japanese2.gif'),new SwapImage('m_newslist','/image/en/news/tolist.gif','/image/en/news/tolist2.gif'),new SwapImage('m_gotop','/image/en/common/gotop.gif','/image/en/common/gotop2.gif'),new SwapImage('c_map','/image/en/company/map.gif','/image/en/company/map2.gif')];
window.onload = function () {setupSwapImages(swapImages);};
