// JavaScript Document

function prepareImages() {
	if(!document.getElementsByTagName) return false;
	if(!document.getElementById) return false;
	if(!document.getElementById("main_contents")) return false;
	var articles = document.getElementById("main_contents");
	var links = articles.getElementsByTagName("a");
	
	for (var i=0; i<links.length; i++) {
		
		var linkurl = links[i].getAttribute("href");
		var format = new Array(".jpg",".jpeg",".jpe",".gif",".bmp",".png",".JPG",".JPEG",".JPE",".GIF",".BMP",".PNG");
		
		for (var j=0; j<format.length; j++) {
			if(linkurl.indexOf(format[j]) != -1) {
				links[i].onclick = function() {
					popUp(this.getAttribute("href"));
					return false;
				}
			}
		}
	}
	function popUp(winURL) {
		var win_set ='resizable=no';
		win_set += ',toolbar=yes';
		win_set += ',scrollbars=yes';
		win_set += ',menubar=yes';
		win_set += ',status=yes';
		win_set += ',location=yes';
		newwin = window.open(winURL, 'openImg', win_set);
		newwin.focus();
	}
}


function prepareLinks() {
	if(!document.getElementsByTagName) return false;
	var links = document.getElementsByTagName("a");
	
	for(var i=0; i<links.length; i++) {
		if(links[i].getAttribute("className") == "newwin" || links[i].getAttribute("class") == "newwin") {
			links[i].onclick = function() {
				popUp(this.getAttribute("href"));
				return false;
			}
		}
		else if(links[i].getAttribute("className") == "openwin" || links[i].getAttribute("class") == "openwin") {
			links[i].onclick = function() {
				openWin(this.getAttribute("href"));
				return false;
			}
		}
	}
}

function popUp(winURL) {
	var win_set = 'width=465';
	win_set += ',height=482';
	win_set += ',resizable=no';
	win_set += ',toolbar=no';
	win_set += ',scrollbars=no';
	win_set += ',menubar=no';
	win_set += ',status=0';
	win_set += ',location=no';
	newwin = window.open(winURL, 'openWin', win_set);
	newwin.moveTo(0,0);
	newwin.focus();
}

function openWin(winURL) {
	newwin = window.open(winURL,"","");
	newwin.focus();
}

function addLoadEvent(func) {
	var oldonload = window.onload;
	if(typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			oldonload();
			func();
		}
	}
}

addLoadEvent(prepareImages);
addLoadEvent(prepareLinks);
