﻿/**
* common.js
*
* @version		1.0.2.0
* @update		21:09 2008/11/25
* @extends		----
*
*/

( function(){

/* ============================================================================== colorRows - 'rowTint'
	Automatic coloured rows | Bite Size Standards
	http://bitesizestandards.com/bites/automatic-coloured-rows
*/
var colorRows = function() {
	var tr = document.getElementsByTagName('tr');
	for (var i = 0, l = tr.length;i < l; i++) {
		if (i % 2) {
			tr[i].className = 'rowTint';
		}
	}
};

/* ============================================================================== initRollovers - 'imgover'
	Standards Compliant Rollover Script
	Author : Daniel Nolan
	http://www.bleedingego.co.uk/webdev.php
*/

var initRollovers = function() {
	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 = aImages[i].onclick = function() {
				if (!sTempSrc) sTempSrc = this.getAttribute('src').replace('_o'+ftype, ftype);
				this.setAttribute('src', sTempSrc);
			}
		}
	}
};

/* ============================================================================== createExternalLink - 'external'
	Author : Sakai
	Date   : 2008-01-19
*/

var createExternalLink = function() {
	var externalLink = document.getElementsByTagName('a');
	for (var i = 0, len = externalLink.length; i < len; i++) {
		var a = externalLink[i];
		if (a.getAttribute('rel') == 'external') {
			if (a.title) a.title += ' : 新しいウィンドウで開きます';
			a.onclick = function() {
				window.open(this.getAttribute('href'), '_blank');
				return false;
			}
		}
	}
};

/* ============================================================================== formAdjust
	Author : Sakai
	Date   : 2008-03-10
	Update : 2008-10-08
*/

var formAdjust = function() {
	var inputForm = document.getElementsByTagName('input');
	for (var i = 0, len = inputForm.length; i < len; i++) {
		var iptFm = inputForm[i];
		if (iptFm.getAttribute('type') == 'text' && iptFm.size) {
			var inputSize = iptFm.size;
			if (0 < inputSize && inputSize <= 5) {
				if (iptFm.className != '') {
					iptFm.className += ' level1 typeText';
				} else {
					iptFm.className = 'level1 typeText';
				}
			} else if (inputSize <= 20) {
				if (iptFm.className != '') {
					iptFm.className += ' level2 typeText';
				} else {
					iptFm.className = 'level2 typeText';
				}
			} else if (inputSize <= 40) {
				if (iptFm.className != '') {
					iptFm.className += ' level3 typeText';
				} else {
					iptFm.className = 'level3 typeText';
				}
			} else {
				if (iptFm.className != '') {
					iptFm.className += ' level4 typeText';
				} else {
					iptFm.className = 'level4 typeText';
				}
			}
		}
	}
};


/* ============================================================================== floorMap
*/

var floorMap = function(id) {

	if (!document.getElementById(id)) return;
	
	var f = document.getElementById(id).getElementsByTagName('img')[0];
	var t = document.getElementById(id).getElementsByTagName('img')[1];
	var thumb = t.src;
	var imap = document.getElementById(id).getElementsByTagName('area');
	
	for (var i = 0, l = imap.length; i < l; i++) {
		imap[i].onmouseover = function() {
			t.src = this.href;
		};
		imap[i].onmouseout = function() {
			t.src = thumb;
		};
		imap[i].onclick = function() {
			return false;
		};
	}
	
};


/* ============================================================================== addEvent
*/

function addEvent(elm, listener, fn){
	try{
		elm.addEventListener(listener, fn, false);
	}catch(e){
		elm.attachEvent('on' + listener, fn);
	}
}

addEvent(window, 'load', function() {
	colorRows();
	initRollovers();
	formAdjust();
	createExternalLink();
	if (document.getElementById('gmaps')) {
		var delay = setTimeout(function(){
			SetGmaps.init(document.getElementsByTagName('body')[0].className);
			clearTimeout(delay);
		}, 1000);
	}
	floorMap('fm1');
	floorMap('fm0');
});


}) ();

