/*
information{
	site: http://polaroid.obakachan.com;
	created: saluta;
	email: slt@obakachan.com;
	path: url("/js/mt.js");
}
*/

var agent = navigator.userAgent.toLowerCase();
var ispc = (agent.indexOf("windows") != -1);
var ismac = (agent.indexOf("mac") != -1);
var gecko = agent.indexOf("gecko") != -1;
var opera = agent.indexOf("opera",0) != -1;
var safari = agent.indexOf("safari") != -1;
var ns = agent.indexOf("netscape") != -1;
var ie = agent.indexOf("msie") != -1 && !opera;
var ie5win = (agent.indexOf("msie 5.0") != -1) && ispc && !opera;
var ie55win = (agent.indexOf("msie 5.5") != -1) && ispc && !opera;
var ie5mac = (agent.indexOf("msie") != -1) && ismac;


function addEvent(obj, type, listener) {
	if(window.addEventListener) window.addEventListener('load',listener,false);
	else {
		var prev  = obj[type];
		obj[type] = (prev) ? function() { prev(); listener(); } : listener;
	}
}
window.addOnload = function(listener){
	addEvent(window, 'onload', listener);
}


function is_opener() {
	if(!!window.opener) return typeof window.opener.document == 'object';
	else return false;
}


function loadOpener(url,wname){
	if(is_opener()){
		window.opener.location.href = url;
		window.opener.focus();
	}else{
		openWin(url,wname,800,600,1,1,1,1,1);
	}
}


function openWin(url,wname,w,h,resizable,toolbar,scrollbars,location,menubar){
		if (h >= (screen.height-30)){
			h = screen.height-100;
			w += 18;
			scrollbars = 1;
		}

		if (w >= (screen.width-30)){
			w = screen.width-100;
			h += 20;
			scrollbars = 1;
		}
		
		win_set = 'width = ' + w;
		win_set += ',height = ' + h;
		win_set += ',resizable = ' + resizable;
		win_set += ',toolbar = ' + toolbar;
		win_set += ',scrollbars = ' + scrollbars;
		win_set += ',location = ' + location;
		win_set += ',menubar = ' + menubar;
		win_set += ',statusbar = 1';

		swin = window.open(url,wname,win_set);
		swin.focus();
}

function openC(c){
	openWin(c,"",250,500,1,0,1,0,0);
}

function loadTop(){
	loadOpener("/index.html","toppage");
}

function openIMG(url,w,h){
	openWin(url,"imgwin",(w + 40),(h + 110),1,0,0,0,0);
}


/*	setTargetBlank()
-----------------------------------------------	*/
function setTargetBlank(){
	this.id = "contentwrap";
	var agent = navigator.userAgent.toLowerCase();
	this.w3c = document.getElementById; if (!this.w3c) return false;
	this.ie = agent.indexOf('msie') != -1;
	this.dname = new String(document.domain);
	return this;
}

setTargetBlank.prototype = {
	init : function(){
		TB.oid = document.getElementById(TB.id);if(!TB.oid) return false;TB.setTB();
	},
	
	setTB : function(){
		oa = TB.oid.getElementsByTagName("a");
		for(var i=0 ; i < oa.length; i++){
			var sh = new String(oa[i].getAttribute("href")); sh = sh.toLowerCase();
			var shsplit = sh.split("/");
			
			
			if(sh.indexOf("javascript:") < 0){
				if(sh.indexOf(TB.dname) < 0){
					if(!TB.ie && !!shsplit[2] && sh.indexOf("http") != -1){
						oa[i].setAttribute("target","_blank");
					}else if(TB.ie) oa[i].setAttribute("target","_blank");
				}
			}
			
		}
	}
}

/*

var TB = new setTargetBlank();
window.addOnload(TB.init);

*/





/*	setMainWidth(){
-----------------------------------------------	*/
function setMainWidth(){
	this.w3c = document.getElementById; if (!this.w3c) return false;
	return this;
}

setMainWidth.prototype = {
	init : function(){
		MW.maindiv = document.getElementById("main");if(!MW.maindiv) return false;
		MW.plid = document.getElementById("pl");if(MW.plid) MW.setArea("pl");
		/*
		MW.hlid = document.getElementById("hl");if(MW.hlid) MW.setArea("hl");
		MW.wlid = document.getElementById("wl");if(MW.wlid) MW.setArea("wl");
		*/
	},
	
	setArea : function(d){
			ids = document.getElementById(d);
			ps = ids.getElementsByTagName("p");
			if(!ps) return false;
			pw = (d == "pl") ? 349 : ((d == "hl")? 412 : 612);
			w = (ps.length != 1) ? (ps.length * pw) : 720;/*	720	*/
			MW.maindiv.style.width = w + "px";

	},
		
	getPictLen : function(){
		var ps = d.getElementsByTagName("p");if(!ps) return false;
		return ps.length
	}
}

var MW = new setMainWidth();
window.addOnload(MW.init);