/**
 * @Name     
 * @Desc    サイト全般に使用
 * @Author  Y.Okuyama
 * @Date    2008/06/13 01:48
 * @charset UTF-8
 **/

function loadTopFlash()
{

	var flashNumber = Math.floor(Math.random()*4);
	
	switch(flashNumber)
	{
		case 0:
			var flashPath = 1;
			break;
	
		case 1:
			var flashPath = 2;
			break;
	
		case 2:
			var flashPath = 3;
			break;
		
		case 3:
			var flashPath = 4;
			break;
			
		default :
			var flashPath = 1;
	}

	document.write("<object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" width=\"535\" height=\"260\" id=\"flashImage\" align=\"middle\">");
	document.write("<param name=\"allowScriptAccess\" value=\"sameDomain\" />");
	document.write("<param name=\"movie\" value=\"/images/flash/flash0" + flashPath + ".swf\" />");
	document.write("<param name=\"quality\" value=\"high\" />");
	document.write("<param name=\"bgcolor\" value=\"#000000\" />");
	document.write("<param name=\"wmode\" value=\"transparent\" />");
	document.write("<embed src=\"/images/flash/flash0" + flashPath + ".swf\" quality=\"high\" wmode=\"transparent\" bgcolor=\"#000000\" width=\"535\" height=\"260\" name=\"flashImage\" align=\"middle\" allowScriptAccess=\"sameDomain\" type=\"application/x-shockwave-flash\" />");
	document.write("</object>");
}


var sourceReplace = function(off,on)

{
	img = document.getElementsByTagName("img");
	p = [];
	off_reg=new RegExp(off+"(\.[a-z]+$)","i");
	on_reg=new RegExp(on+"(\.[a-z]+$)","i");
	
	for(var x=0,i;i=img[x];x++)
	{
		if(i.src.match(off_reg))
		{
			p[x]=new Image();p[x].src=i.src.replace(off_reg,on+"$1");
			i.onmouseover=function()
			{
				this.src=this.src.replace(off_reg,on+"$1");
			};
			i.onmouseout=function()
			{
				this.src=this.src.replace(on_reg,off+"$1");
			};
		};
	};
};

window.onload = function()
{
 sourceReplace( "_off" , "_on" );
};


$(function()
{
	var currentSize = readCookie('sizeCheck');
	
	if (currentSize)
	{
		switchSize(currentSize);
	};

	$("a.small").click(function()
	{
		switchSize("sizeSmall");
		return false;
	});
  
	$("a.middle").click(function()
	{
 		switchSize("sizeMiddle");
 		return false;
 	});

	$("a.large").click(function()
	{
		switchSize("sizeLarge");
		return false;
 	});
});


function switchSize(className)
{
	$("body").removeAttr("class").addClass(className);
	createCookie('sizeCheck', className, 365);
};


// cookie script http://www.quirksmode.org/js/cookies.html
function createCookie(name,value,days)
{
	if (days)
	{
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";

	document.cookie = name + "=" + value + expires + "; path=/";
}

function readCookie(name)
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');

	for(var i=0;i < ca.length;i++)
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
 	}
	return null;
}


var path = window.location.pathname;

function rightColumnInclude()
{
	$.ajax(
	{
		url: "/include/rightcolumn.ini",		
		dataType: "html",
		success: function(html)
		{
			$("#rightColumn").append(html);
			footerInclude();
		}
	});
}

function footerInclude()
{
	$.ajax(
	{
		url: "/include/footercontents.ini",		
		dataType: "html",
		success: function(html)
		{
			$("#footerContents").append(html);
		}
	});
}

if($.browser.msie)
{
	addLoadEvent(rightColumnInclude);
}

else
{
	rightColumnInclude();
}

function addLoadEvent(func)
{
	var oldonload = window.onload;

	if (typeof window.onload != 'function')
	{
		window.onload = func;
	}

	else
	{
		window.onload = function()
		{
			oldonload();
			func();
		}
	}
}

function fontControl()
{
	document.write("<dl id=\"fontControl\">");
	document.write("<dt>文字サイズ</dt>");
	document.write("<dd id=\"font01\"><a href=\"javascript:void(0);\" class=\"small\">小</a></dd>");
	document.write("<dd id=\"font02\"><a href=\"javascript:void(0);\" class=\"middle\">中</a></dd>");
	document.write("<dd id=\"font03\"><a href=\"javascript:void(0);\" class=\"large\">大</a></dd>");
	document.write("</dl>");
}

function analytics()
{
	document.write("<script src=\"http://www.google-analytics.com/urchin.js\" type=\"text/javascript\"></script>");
	document.write("<script type=\"text/javascript\">");
	document.write("_uacct = \"UA-4751829-1\";");
	document.write("urchinTracker();");
	document.write("</script>");
}


function bbsWindow()
{
	window.open('bbs/', 'new', 'width=800, height=600, menubar=no, toolbar=no, scrollbars=yes');
}


function openWin(path, title, width, height)
{
  photoWindow = window.open("","newWindow","resize=0,scrollbars=0,menubar=0,directories=0,status=0,location=0,width=" + width + ",height=" + height + "");
  photoWindow.document.open();
  photoWindow.focus();
  photoWindow.document.write("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">");
  photoWindow.document.write("<html xmlns=\"http://www.w3.org/1999/xhtml\">");
  photoWindow.document.write("<head>");
  photoWindow.document.write("<meta http-equiv=\"content-type\" content=\"text/html; charset=UTF-8\" />");
  photoWindow.document.write("<meta http-equiv=\"content-style-type\" content=\"text/css\" />");
  photoWindow.document.write("<meta http-equiv=\"content-script-type\" content=\"text/javascript\" />");
  photoWindow.document.write("<meta http-equiv=\"content-language\" content=\"ja\" />");
  photoWindow.document.write("<meta name=\"description\" content=\"「江戸しぐさ」安心な社会・豊かな人づくりを目指すNPO法人\" />");
  photoWindow.document.write("<meta name=\"keywords\" content=\"江戸しぐさ,共生文化,共生社会,公共マナー,江戸時代,商人,越川禮子,今しぐさ\" />");
  photoWindow.document.write("<meta name=\"author\" content=\"NPO法人江戸しぐさ\" />");
  photoWindow.document.write("<meta name=\"copyright\" content=\"Copyright &copy; 2008 NPO法人江戸しぐさ\" />");
  photoWindow.document.write("<meta name=\"viewport\" content=\"width=900\" />");
  photoWindow.document.write("<style type=\"text/css\">");
  photoWindow.document.write("<!-- ");
  photoWindow.document.write("body{margin:0;padding:0;text-align:center;} p{margin:5px 0;} form{margin:0;padding:0;}");
  photoWindow.document.write("-->");
  photoWindow.document.write("</style>");
  photoWindow.document.write("<title>" + title + "</title>");
  photoWindow.document.write("<link rel=\"index\" href=\"/\" />");
  photoWindow.document.write("<link rel=\"shortcut icon\" href=\"/favicon.ico\" type=\"image/ico\" />");
  photoWindow.document.write("</head>");
  photoWindow.document.write("<body>");
  photoWindow.document.write("<img src=\"" + path + "\" />"); 
  photoWindow.document.write("<form action=\"\"><input type=\"button\" value=\"このページを閉じる\" onclick=\"window.close()\" /></form>");
  photoWindow.document.write("</body>");
  photoWindow.document.write("</html>");
  photoWindow.document.close();
}




