var isFocusWindow = true;
var isLoadHeader = false;
function initMain(){
	// || navigator.userAgent.indexOf("Chrome") != -1
	if(Prototype.Browser.IE){
		document.onfocusout = onBlurWindow;
		document.onfocusin = onFocusWindow;
	} else {
		window.onblur = onBlurWindow;
		window.onfocus = onFocusWindow;
	}
}
function navigateToURL(src, target){
	if(target = "" || target == "_self"){
		location.href = src;
	} else {
		window.open(src);
	}
}
function embedHeader(){
	var flashvars = {};
	var params = {};
	params.menu = "false";
	params.allowScriptAccess = "always";
	var attributes = {};
	attributes.id = "externalswf";
	swfobject.embedSWF("/blog/material/skin/header.swf", "externaltitle", "940", "140", "9.0.0", false, flashvars, params, attributes);
}
function onBlurWindow(){
	isFocusWindow = false;
	checkHeader();
}
function onFocusWindow(){
	isFocusWindow = true;
	checkHeader();
}
function checkHeader(){
	clearInterval(intervalID);
	if(isLoadHeader){
		var str = (isFocusWindow)? "true" : "false";
		var elm = $("externalswf");
		try{
			if(elm && !window.closed) elm.setActiveFlash(str);
		}catch(e){
		}
	}
}
var intervalID;
function onLoadFlash(){
	isLoadHeader = true;
	intervalID = setInterval("checkHeader()", 1);
}

function trace(str)
{
	window.status = str;
}

function openPage(path, width, height)
{
	if(!width) width = 640;
	if(!height) height = 480;
	var left = (window.screen.width-width)/2;
	var top = (window.screen.height-height)/2;
	var param = "width="+width+",height="+height+",scrollbars=no,resizable=no,toolbar=no,directories=no,location=no,menubar=no,status=no,left="+left+",top="+top;
	var nam = path.gsub(".", "_").gsub("/", "_").gsub(":", "_");
	var win = window.open(path, "_blank", param);
	win.focus();
}

function popup(swf, width, height, ver)
{
	if(!width) width = 640;
	if(!height) height = 480;
	var left = (window.screen.width - width) / 2;
	var top = (window.screen.height - height) / 2;
	var param = "width=" + win_w + ",height=" + win_h + ",scrollbars=no,resizable=no,toolbar=no,directories=no,location=no,menubar=no,status=no,left=" + left + ",top=" + top;
	var nam = swf.gsub(".", "_").gsub("/", "_").gsub(":", "_");
	window.open("/js/popup.html", nam, param);
}

function openswf(swf, width, height, ver)
{
	if(!ver) ver = "10.0.0";
	if(!width) width = 640;
	if(!height) height = 480;
	var win_w = width + 20;
	var win_h = height + 20;
	var left = (window.screen.width-win_w)/2;
	var top = (window.screen.height-win_h)/2;
	var param = "width="+win_w+",height="+win_h+",scrollbars=no,resizable=no,toolbar=no,directories=no,location=no,menubar=no,status=no,left="+left+",top="+top;
	var nam = swf.gsub(".", "_").gsub("/", "_").gsub(":", "_");
	var win = window.open("", nam, param);
	var str = '';
	str += '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">\n';
	str += '<html xmlns="http://www.w3.org/1999/xhtml">\n';
	str += '<head>\n';
	str += '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />\n';
	str += '<title></title>\n';
	str += '<script type="text/javascript">\n'
	str += 'var swfWidth = '+width+';\n';
	str += 'var swfHeight = '+height+';\n';
	str += 'var swfPath = "'+swf+'";\n';
	str += 'var swfVer = "'+ver+'";\n';
	str += '</script>\n';
	str += '<script type="text/javascript" src="http://www.morocoshi.net/lib/prototype/prototype.js"></script>\n';
	str += '<script type="text/javascript" src="http://www.morocoshi.net/lib/swfobject/swfobject.js"></script>\n';
	str += '<script type="text/javascript" src="http://www.morocoshi.net/js/openerevent.js"></script>\n';
	str += '<link rel="stylesheet" type="text/css" media="all" href="http://www.morocoshi.net/css/popup.css" />\n';
	str += '</head>\n';
	str += '<body>\n<div id="swf"></div>\n';
	str += '</body>\n</html>\n';
	win.document.open();
	win.document.write(str);
	win.document.close();
}

function openWonderfl(code, title)
{
	var win_w = 465 + 20;
	var win_h = 490 + 40;
	var left = (window.screen.width-win_w)/2;
	var top = (window.screen.height-win_h)/2;
	var param = "width="+win_w+",height="+win_h+",scrollbars=no,resizable=no,toolbar=no,directories=no,location=no,menubar=no,status=no,left="+left+",top="+top;
	var win = window.open("","",param);
	var titleset = title + " - wonderfl build flash online";
	var str = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">\n';
	str += '<html xmlns="http://www.w3.org/1999/xhtml">\n';
	str += '<title>'+title+'</title>\n';
	str += '<script type="text/javascript" src="http://www.morocoshi.net/lib/prototype/prototype.js"></script>\n';
	str += '<script type="text/javascript" src="http://www.morocoshi.net/js/wonderflwin.js"></script>\n';
	str += '</head>\n<body>\n';
	str += '<div style="text-align:center;width:465px;">';
	str += '<iframe id="wonderfl" title="'+titleset+'" scrolling="no" src="http://wonderfl.net/blogparts/'+code+'" width="465" height="490" style="border:1px black solid;">';
	str += '</iframe>\n'
	str += '<a href="http://wonderfl.net/c/'+code+'" title="'+titleset+'" target="_blank">'+titleset+'</a></div>\n';
	str += '</body>\n</html>\n';
	win.document.open();
	win.document.write(str);
	win.document.close();
}
