function get_browser() {
	checkOP = window.opera;            // OP
	checkN6 = document.getElementById; // N6
	checkIE = document.all;            // IE
	checkN4 = document.layers;         // N4

	if(checkOP) {
		return "OP6";  // Opera 6 or above
	} else if(checkIE) {
		return "IE4";  // Internet Explorer 4.0 or above
	} else if(checkN6) {
		userAgent = navigator.userAgent;
		if(userAgent.indexOf("Safari") >= 0) {
			return "SA1";  // Safari 1.X
		}
		return "NS6";  // Netscape 6 or above
	} else if(myN4) {
		return "NN4";  // Netscape Navigator 4 to 5
	} else {
		if(navigator.appName == "Netscape") {
			return "NS";
		} else if(navigator.appName == "Microsoft Internet Explorer") {
			return "IE";
		}
	}

	return "UNKNOWN";
}

function popupImage(imgURL, imgWidth, imgHeight, imgTitle) {
	winWidth = imgWidth + 20;
	winHeight = imgHeight + 20;
	title = unescape(imgTitle);

	if(get_browser() == "SA1") {
		newWin = window.open("", "", "toolbar=no,location=no,directoryies=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no,width="+winWidth+",height="+winHeight);
		newWin.moveTo(10, 10);
	} else {
		newWin = window.open("./", "", "toolbar=no,location=no,directoryies=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no,width="+winWidth+",height="+winHeight);
		newWin.moveTo(10, 10);
	}

	newWin.document.open();
	
	newWin.document.writeln('<?xml version="1.0" encoding="utf-8"?>');
	newWin.document.writeln('');
	newWin.document.writeln('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">');
	newWin.document.writeln('');
	newWin.document.writeln('<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ja" lang="ja">');
	newWin.document.writeln('');
	newWin.document.writeln('<head profile="http://gmpg.org/xfn/11">');
	newWin.document.writeln('    <meta http-equiv="content-type" content="application/xhtml+xml; charset=utf-8" />');
	newWin.document.writeln('    <meta http-equiv="content-language" content="ja" />');
	newWin.document.writeln('    <meta http-equiv="content-style-type" content="text/css" />');
	newWin.document.writeln('    <meta http-equiv="imagetoolbar" content="no" />');
	newWin.document.writeln('');	
	newWin.document.writeln('    <style type="text/css"><![CDATA[');
	newWin.document.writeln('        * { margin:0px; paddingt:0px; border-style:none; border-width:0px; }');
	newWin.document.writeln('        body { margin:0px; padding:10px; }');
	newWin.document.writeln('    ]]></style>');
	newWin.document.writeln('');
	newWin.document.writeln('    <title>'+title+'</title>');
	newWin.document.writeln('</head>');
	newWin.document.writeln('');
	newWin.document.writeln('<body>');
	newWin.document.writeln('<div><img src="'+imgURL+'" width="'+imgWidth+'" height="'+imgHeight+'" title="'+title+'" alt="'+title+'" /></div>');
	newWin.document.writeln('</body>');
	newWin.document.writeln('');
	newWin.document.writeln('</html>');
	
	newWin.document.close();
}

function outputQuickTimeHTML(posterURL, posterWidth, posterHeight, movURL)
{
	window.document.writeln('<object width="'+posterWidth+'" height="'+posterHeight+'" classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" codebase=\"http://www.apple.com/qtactivex/qtplugin.cab\">');
	window.document.writeln('    <param name="src" value="'+posterURL+'">');
	window.document.writeln('    <param name="href" value="'+movURL+'">');
	window.document.writeln('    <param name="target" value="quicktimeplayer">');
	window.document.writeln('    <param name="controller" value="false">');
	window.document.writeln('    <embed src="'+posterURL+'" href="'+movURL+'" width="'+posterWidth+'" height="'+posterHeight+'" controller="false" target="quicktimeplayer" />');
	window.document.writeln('</object>');
}



function rewrite_links()
{
	if(!document.getElementsByTagName) {
		return;
	}
	
	var anchors = document.getElementsByTagName('a');
	
	for(var i=0; i<anchors.length; i++) {
		var a = anchors[i];
		var classes = a.className.split(" ");
	
		if(a.href) {
			var bTargetBlank = false;
			var bPopupImage = false;
			var imgWidth = 0;
			var imgHeight = 0;
			
			for(var j=0; j<classes.length; j++) {				
				if(classes[j] == 'popupNewWindow') {
					bTargetBlank = true;
				} else if(classes[j] == "popupImage") {
					bPopupImage = true;
				} else if(classes[j].substr(0, 1) == "w") {
					imgWidth = classes[j].substr(1, 9999);
				} else if(classes[j].substr(0, 1) == "h") {
					imgHeight = classes[j].substr(1, 9999);
				}
			}
			
			if(bTargetBlank) {
				a.target = '_blank';
			}
			
			if(bPopupImage && imgWidth!=0 && imgHeight!=0) {
				a.href = 'javascript:popupImage("'+a.href+'", '+imgWidth+', '+imgHeight+', "'+escape(a.title)+'");';
			}
		}
	}
}

