// JavaScript Document


window.onload = function () {
	newMark();
	addMagnifier();
}


/* ----------------------------------------------------------------------
 1. 「lightbox」を設定したイメージに拡大鏡のイメージを重ねて配置する
---------------------------------------------------------------------- */

// 初期設定
// ----------------------------------------------------------------------

var targetClass = "zm";					// 新着の情報を判断するエレメントに設定されたクラスネーム

var imgFile = "/images/zoom-in.gif";	// 拡大鏡のイメージファイル
var altText = "ZOOM IN";				// 拡大鏡イメージの代替文字
var wSize = "16";						// 拡大鏡イメージの幅
var hSize = "16";						// 拡大鏡イメージの高さ

// ----------------------------------------------------------------------

function addMagnifier() {
	var elements = document.getElementsByClassName(targetClass);
	elements.each(
		function (item) {
			Element.makePositioned(item);
			Element.setStyle(item, {'display': 'inline-block'});

			var imgTag = document.createElement("img");
			imgTag.setAttribute("src",imgFile);
			imgTag.setAttribute("alt",altText);
			imgTag.setAttribute("width",wSize);
			imgTag.setAttribute("height",hSize);
			item.insertBefore(imgTag,item.firstChild);

			Element.setStyle(imgTag, { 'position': 'absolute', 'left': '5px', 'top': '5px' });

		}
	);
}

/* ----------------------------------------------------------------------
 2. 新着マークの表示（classを追加）
-------------------------------------------------------------------------

指定のclassが与えられた要素を判定し、新しければ指定のclassをどう要素に追加する。

	class="newItem update__2008-01-01"


ブラウザの動作状況

	Windows
		× Internet Explorer 5.0
		× Internet Explorer 5.5
		○ Internet Explorer 6
		○ Internet Explorer 7
		○ Safari 3
		× Opera 9.27 
	Mac
		○ Safari 3
		× Internet Explorer 5.23
		× Opera 9.25 

---------------------------------------------------------------------- */


// 初期設定
// ----------------------------------------------------------------------

// 新着として扱う日数
var passage = 7;

// 新着の情報を判断するエレメントに設定されたクラスネーム
var targetDate = "ifNew";

// 日付データに付加する文字列
var addStr = "update__";		// 日付形式: 2008-01-01 例: update__2008-01-01

// 新着の情報に追加するクラスネーム
var addClass = "newItem";

// ----------------------------------------------------------------------

var currentDate = new Date().getTime();

function newMark() {
	regObj = new RegExp("ifNew");
	var elements = document.getElementsByClassName(targetDate);
	elements.each(
		function (item) {
			var updateTime;
			if(document.all) {
				var clsasss = item.getAttribute("className");
			}
			else {
				var clsasss = item.getAttribute("class");
			}
			var cls = clsasss.split(" ");
			for (i=0; i<cls.length; i++) {
				if(cls[i].match(addStr)) {
					updateStr = cls[i];
					updateStrs = updateStr.split("__");
					updateTime = updateStrs[1];
				}
			}
			var times = updateTime.split("-");
			var entryDate = new Date(times[0], times[1]-1, times[2], 0, 0, 0).getTime();
			var passDay = Math.floor((currentDate - entryDate) / (24 * 60 * 60 * 1000));
			if(passage >= passDay) {
				Element.addClassName(item, addClass);
			}
		}
	);
}



