﻿var masaruPhotoViewer = {
	loading: "/images/loading/loading.gif",

	start: function() {
		document.getElementById("photoImage").src = this.loading;

		var ns = (navigator.appName == "Netscape");
		if (ns) document.captureEvents(Event.CLICK);

		document.onclick = function(e) {
			if (!e) {
				e = window.event;
			}
			
			var pass = true;
			var regex = new RegExp("/s(144|288|320|400)/", "g");

			var t = ns ? e.target.className : e.srcElement.className;

			if (t == "largePhoto") {
				pass = masaruPhotoViewer.initPhoto((ns ? e.target.src : e.srcElement.src).replace(regex, "/s800/"));
			}
			else if (t == "photo") {
				pass = false;
			}
			return pass;
		}
	},

	initPhoto: function(photo) {
		var pass = navigator.userAgent.indexOf("MSIE 6") > 0 ||
			navigator.userAgent.indexOf("MSIE 7") > 0 ||
			navigator.userAgent.indexOf("MSIE 8") > 0 ||
			navigator.userAgent.indexOf("Firefox") > 0 ||
			navigator.userAgent.indexOf("Chrome") > 0 ||
			navigator.userAgent.indexOf("Safari") > 0;

		if (pass) {
			var p = document.getElementById("photoPanel");
			var b = document.getElementById("photoBackground");
			var w = document.documentElement.clientWidth;
			var h = Math.max(document.documentElement.scrollHeight, document.documentElement.clientHeight);
			var st = Math.max(document.body.scrollTop, document.documentElement.scrollTop);
			var t = (document.documentElement.clientHeight / 2) - (600 / 2);
			if (t < 0) {
				t = 0;
			}

			p.style.top = t + st + "px";
			p.style.left = (w / 2) - (770 / 2) + "px";
			b.style.width = w + "px";
			b.style.height = h + "px";

			p.style.display = b.style.display = 'block';
			photo = photo.replace("/s/","/b/")
			photo = photo.replace("/s/","/b/")
			document.getElementById("photoImage").src = photo;
		}

		return !pass;
	},

	closePhoto: function() {
		var p = document.getElementById("photoPanel");
		var b = document.getElementById("photoBackground");
		p.style.display = b.style.display = 'none';
		document.getElementById("photoImage").src = this.loading
		return false;
	}
};
function funChangeMediumpic(obj){
	var imgUrl = obj.src.toLowerCase();
	document.getElementById("imgMediumpic").src = imgUrl.replace("small","medium");
}
