/*
--------------------------------------------------
jquery.photopreview.js - Photo Previews
version: 4.2008
[JavaScript Library Dependencies]
jquery.js
-------------------------------------------------- */
var count = 0;
var photoSrcList = new Array();
var photoElementList = new Array();

/**
 * Check Tags
 */
$(document).ready(function(){
	var nodeList = document.getElementsByTagName("a");
	// alert(nodeList.length);
	// Check "a rel=preview"
	for (var i=0; i<nodeList.length; i++) {
		if (nodeList[i].rel == "preview") {
			// Photo Source List Build
			photoSrcList.push(nodeList[i].href);
			// Photo Element List Build
			photoElementList.push(nodeList[i]);
		}
	}
	// Setting Event for "a rel=preview"
	for (var i=0; i<photoElementList.length; i++) {
		// alert(nodeList[i].href);
		// nodeList[i].onclick = new Function("previewPhoto('"+nodeList[i].href+"'); return false;");
		photoElementList[i].onclick = new Function("photoPreviews(this,"+i+"); return false;");
		// nodeList[i].onmouseover = new Function("blinkPhoto(this,0.6);");
		// nodeList[i].onmouseout = new Function("blinkPhoto(this,1);");
		// nodeList[i].href = "javascript:void(0);";
		// nodeList[i].href = "javascript:preview('"+nodeList[i].href+"',"+i+");";
		photoElementList[i].href = photoSrcList[i];
	}
	// Debug: "rel" Attribute Check
	/*var check_rel = "";
	check_rel += "このページに a 要素は " + nodeList.length + " つあります。\n";
	check_rel += "そのうち rel 属性があるのは以下。\n";
	for (var i in nodeList) {
		if(nodeList[i].rel) check_rel += "- " + nodeList[i].rel + "\n";
	}
	alert(check_rel);*/
});

/**
 * Preview Photos
 */
function photoPreviews(photoSelected,photoNum) {
	// alert(photoSrcList[photoNum]);
	var targetImage = new Image();
	// alert(targetImage.height);
	targetImage.src = photoSrcList[photoNum];
	// targetImage.src = photoSrc;
	$("#photo-preview-item").fadeTo(300,0,function(){
		$("#photo-preview-item").animate({height:targetImage.height},1000,function(){
			photoData = "<img src=\""+targetImage.src+"\" alt=\"Photo\" />";
			$("#photo-preview-item").html(photoData);
			$("#photo-preview-item").fadeTo(300,1);
		});
	});
	// Photo Number into Count
	count = photoNum;
	// alert(count);
}

/**
 * Preview Photos for Next
 */
function nextPhoto() {
	// alert(count);
	// alert(photoSrcList.length);
	count++;
	count %= photoSrcList.length;
	// alert(photoSrcList[count]);
	photoPreviews(this,count);
}

