var CommonClass = Class.create();

CommonClass.prototype = {
	initialize: function(callback, frequency) {

		this.browser = this.checkBrowser();

		// line-breaker
/*
		if (! this.browser.match(/msie|opera/)) {
			this.applyLineBreaker();
		}
*/

		// 角丸適用
/*
		if (this.browser != 'safari') {
			RUZEE.ShadedBorder.create({ corner:6 }).render('contents');
			if ($('contents')) {
				$('contents').style.backgroundColor = 'transparent';
			}
		}
*/

		var bodyClassName = document.body.className;
		var bodyId = document.body.id;

		// class名から method名を作成 (ex: bodyTop -> initBodyTop)
		var initByClassName = 'init' + bodyClassName.substr(0,1).toUpperCase() + bodyClassName.substr(1);

		// bodyのclassによる初期化 (class名、method共にあれば)
		bodyClassName && this[initByClassName] && this[initByClassName]();


		// id名から method名を作成 (ex: bodyTop -> initBodyTop)
		var initById = 'init' + bodyId.substr(0,1).toUpperCase() + bodyId.substr(1);

		// bodyのclass名とid名が同じだった場合の２重初期化を防止
		if (initByClassName != initById) {
			// bodyのidによる初期化 (id、method共にあれば)
			bodyId && this[initById] && this[initById]();
		}
	},

	initBodyTopPage: function () {
	},

	applyLineBreaker: function(node) {
		var s = document.createElement('script');
		s.setAttribute('charset', 'utf-8');
		s.setAttribute('type', 'application/x-javascript');
		s.setAttribute('src', '/lib/external/linebreak.js');
		document.body.appendChild(s);
//		lineBreaker(node);
	},

	an: function() {
		var an = document.createElement('div');
		an.id = 'anav';
		an.innerHTML = $('an').value;
		$('container').appendChild(an);
	},

	checkBrowser: function () {
		var ua = navigator.userAgent;
		var browser = null;

		(!!window.ActiveXObject)  && (browser = 'msie');
		(ua.match('Gecko')) 	  && (browser = 'mozes');
		(ua.match('AppleWebKit')) && (browser = 'safari');
		(!!window.opera)		  && (browser = 'opera');
		(ua.match('Konqueror'))   && (browser = 'konqueror');

		return browser;
	}
}


var common;
Event.observe(window, 'load', function(){
	common = new CommonClass();
}, false);












/*
Initialisation of a CookieManager object:

var manager = new CookieManager();
var manager = new CookieManager({shelfLife:30});

Using IE's userData behaviour instead of cookies in IE:

var manager = new CookieManager({userData:true});

Using the cookie manager:

manager.setCookie("myCookie", aVariable);
var cookieValue = manager.getCookie("myCookie");
manager.clearCookie("myCookie")
*/


/* Browser Detection
----------------------------------------------------------------------------- */
var _BROWSER_IS_IE =
	(document.all
	 && window.ActiveXObject
	 && navigator.userAgent.toLowerCase().indexOf("msie") > -1
	 && navigator.userAgent.toLowerCase().indexOf("opera") == -1);

/**
 * I hate navigator string based browser detection too, but when Opera alone
 * chokes on cookies containing double quotes...
 */
var _BROWSER_IS_OPERA =
	(navigator.userAgent.toLowerCase().indexOf("opera") != -1);

/* CookieManager Object
----------------------------------------------------------------------------- */
/**
 * Provides a simple interface for creating, retrieving and clearing cookies.
 *
 * @author Jonathan Buchanan
 * @version 0.8
 * @dependencies $() in Core.js
 */
CookieManager = Class.create();
CookieManager.prototype =
{
	/**
	 * Determines if this object will use IE's proprietary userData behaviour
	 * instead of cookies for storage.
	 */
	userDataForIE: false,

	initialize: function(userDataForIE)
	{
		this.cookieShelfLife = 365;
		this.userDataForIE = userDataForIE;

		// Internet Explorer has a cookie handling bug - if the *combined size*
		// of all cookies stored for a given domain is greater than 4096 bytes,
		// document.cookie will return an empty string. Until this is fixed , we
		// will fall back on IE's proprietary userData behaviour.
		if (_BROWSER_IS_IE && this.userDataForIE)
		{
			this.IE_CACHE_NAME = "storage";
			if ($(this.IE_CACHE_NAME) == null)
			{
				var div = document.createElement("DIV");
				div.id = this.IE_CACHE_NAME;
				document.body.appendChild(div);
			}
			this.store = $(this.IE_CACHE_NAME);
			this.store.style.behavior = "url('#default#userData')";
		}
	},

	/**
	 * Returns the value of a cookie with the given name, or <code>null</code>
	 * if no such cookie exists.
	 */
	getCookie: function(aCookieName)
	{
		var result = null;
		if (_BROWSER_IS_IE && this.userDataForIE)
		{
			this.store.load(this.IE_CACHE_NAME);
			result = this.store.getAttribute(aCookieName);
		}
		else
		{
			for (var i = 0; i < document.cookie.split('; ').length; i++)
			{
				var crumb = document.cookie.split('; ')[i].split('=');
				if (crumb[0] == aCookieName && crumb[1] != null)
				{
					result = crumb[1];
					break;
				}
			}
		}

		if (_BROWSER_IS_OPERA && result != null)
		{
			result = result.replace(/%22/g, '"');
		}
		return result;
	},

	/**
	 * Sets a cookie with the given name and value.
	 */
	setCookie: function(aCookieName, aCookieValue)
	{
		if (_BROWSER_IS_IE && this.userDataForIE)
		{
			this.store.setAttribute(aCookieName, aCookieValue);
			this.store.save(this.IE_CACHE_NAME);
		}
		else
		{
			if (_BROWSER_IS_OPERA)
			{
				aCookieValue = aCookieValue.replace(/"/g, "%22");
			}
			var date = new Date();
			date.setTime(date.getTime() + (this.cookieShelfLife * 24*60*60*1000));
			var expires = '; expires=' + date.toGMTString();
			document.cookie = aCookieName + '=' + aCookieValue + expires + '; path=/';
		}
	},

	/**
	 * Clears the cookie with the given name.
	 */
	clearCookie: function(aCookieName)
	{
		if (_BROWSER_IS_IE && this.userDataForIE)
		{
			this.store.load(this.IE_CACHE_NAME);
			this.store.removeAttribute(aCookieName);
			this.store.save(this.IE_CACHE_NAME);
		}
		else
		{
			document.cookie =
				aCookieName + '=;expires=Thu, 01-Jan-1970 00:00:01 GMT; path=/';
		}
	}
}

