//-------------------------------------------------------------------->
//- file   : opendoors.js
//- admin  : MEGA-D Inc. Tatsuro Kimoto
//- update : 20080207
//- desc   : JavaScript for opendoors.asahi.com
//- ver    : 1.0
//-------------------------------------------------------------------->

function scrollToTop() {
	var IE  = navigator.appName.indexOf("Microsoft Internet Explorer",0) != -1;
	if( IE ){
		position = document.body.scrollTop + document.documentElement.scrollTop;
	} else {
		position = window.pageYOffset;
	}
	movePosition();
}

function movePosition() {
	position = Math.floor(position * 0.7);
	if( position > 1 ){
		window.scrollTo(0, position)
		setTimeout("scrollToTop()", 30);
	} else {
		window.scrollTo(0,0);
	}
}

function showLinkList(id1, id2) {
	document.getElementById(id1).style.visibility = 'visible';
	document.getElementById(id1).style.display = 'block';
	document.getElementById(id2).innerHTML = '<a href="javascript:hideLinkList(\''+id1+'\',\''+id2+'\');">閉じる</a>';
	document.getElementById(id2).className = 'close';
}
function hideLinkList(id1, id2) {
	document.getElementById(id1).style.visibility = 'hidden';
	document.getElementById(id1).style.display = 'none';
	document.getElementById(id2).innerHTML = '<a href="javascript:showLinkList(\''+id1+'\',\''+id2+'\');">全件表示する</a>';
	document.getElementById(id2).className = 'more';
}

function initRollovers() {
	if (!document.getElementById) return
	
	var aPreLoad = new Array();
	var sTempSrc;
	var aImages = document.getElementsByTagName('img');

	for (var i = 0; i < aImages.length; i++) {		
		if (aImages[i].className == 'imgover') {
			var src = aImages[i].getAttribute('src');
			var ftype = src.substring(src.lastIndexOf('.'), src.length);
			var hsrc = src.replace(ftype, '_o'+ftype);

			aImages[i].setAttribute('hsrc', hsrc);
			
			aPreLoad[i] = new Image();
			aPreLoad[i].src = hsrc;
			
			aImages[i].onmouseover = function() {
				sTempSrc = this.getAttribute('src');
				this.setAttribute('src', this.getAttribute('hsrc'));
			}	
			
			aImages[i].onmouseout = function() {
				if (!sTempSrc) sTempSrc = this.getAttribute('src').replace('_o'+ftype, ftype);
				this.setAttribute('src', sTempSrc);
			}
		}
	}
}

try{
	window.addEventListener("load",initRollovers,false);
}catch(e){
	window.attachEvent("onload",initRollovers);
}
