function initRollovers() {
	if (!document.getElementById) return
	
	var aPreLoad = new Array();
	var sTempSrc;
	var aImages = document.getElementsByTagName('img');
	var aInputs = document.getElementsByTagName('input');

	doRollover(aImages);
	doRollover(aInputs);

	function doRollover(array) {
		for (var i = 0; i < array.length; i++) {
			if (array[i].className == 'btn') {
				var src = array[i].getAttribute('src');
				var ftype = src.substring(src.lastIndexOf('.'), src.length);
				var hsrc = src.replace(ftype, '_o'+ftype);

				array[i].setAttribute('hsrc', hsrc);
				
				aPreLoad[i] = new Image();
				aPreLoad[i].src = hsrc;

					if(src.match(/_o.gif/)) {
					} else {
					
					array[i].onmouseover = function() {
						sTempSrc = this.getAttribute('src');
						this.setAttribute('src', this.getAttribute('hsrc'));
					}
					
					array[i].onmouseout = function() {
						if (!sTempSrc) sTempSrc = this.getAttribute('src').replace('_o'+ftype, ftype);
						this.setAttribute('src', sTempSrc);
					}
				}

			}
		}
	}
}


function externalLinks() {
	if (!document.getElementsByTagName) return;
	var anchors = document.getElementsByTagName("a");
	for (var i=0; i<anchors.length; i++) {
		var anchor = anchors[i];
		if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external")
			anchor.target = "_blank";
	}
}


function addEvent(elm,listener,fn){
	try{
		elm.addEventListener(listener,fn,false);
	}catch(e){
		elm.attachEvent("on"+listener,fn);
	}
}



addEvent(window,"load",externalLinks);
addEvent(window,"load",initRollovers);





Number.prototype.toFormatString = function(place) {
	place = place || 2;
	var str = this.toString();
	while (str.length < place) str = '0'+str;
	return str;
};


if (typeof Mori == 'undefined') Mori = {};


Mori.setup = function() {
	Mori.topic.setup();
};


Mori.topic = {
	setup: function() {
		var screen = $('#mainVright img');
		$('#mainVleft a').each(function(i) {
			var n = (i + 1).toFormatString();
			var src = '/en/img/home/bt_head_img_'+n+'.jpg';
			new Image().src = src;
			$(this).mouseenter(function() {
				screen.attr('src', src);
			});
		});
	}
};


$(Mori.setup);
