/*--------------------------------------------------------------------------*
 *  
 *  wordBreak JavaScript Library for Opera & Firefox
 *  
 *  MIT-style license. 
 *  
 *  2008 Kazuma Nishihata 
 *  http://www.to-r.net
 *  
 *--------------------------------------------------------------------------*/

var CLASS_NAME = "menu_bk";
new function(){
	var wrapFlg;
	if(window.opera || navigator.userAgent.indexOf("Firefox") != -1){
		var wordBreak = function() {
			wrapFlg = chkWrapFlg();
			if ( wrapFlg == 0 ) {
				// 折り返さない
				if( document.styleSheets[0].addRule ){
					document.styleSheets[0].addRule(".menu_bk","white-space: nowrap");
				} else if ( document.styleSheets[0].insertRule ){
					document.styleSheets[0].insertRule(".menu_bk{white-space: nowrap}", document.styleSheets[0].cssRules.length );
				} else {
					return false;
				}
			} else {
				// 折り返す
				var wordBreakClass = "menu_bk";
				var div = document.getElementsByTagName("div");
				for(var i=0,len=div.length ; i<len ; i++){
					var tbClass = div[i].className.split(/\s+/);
					for (var j = 0; j < tbClass.length; j++) {
						if (tbClass[j] == wordBreakClass) {
							recursiveParse(div[i])
						}
					}
				}
			}
		}
		var recursiveParse = function(pNode) {
			var childs = pNode.childNodes;
			for (var i = 0; i < childs.length; i++) {
				var cNode = childs[i];
				if (childs[i].nodeType == 1) {
					recursiveParse(childs[i]);
				}else if(cNode.nodeType == 3) {
					if(cNode.nodeValue.match("[^\n ]")){
						var plTxt = cNode.nodeValue.replace(/\t/g,"");
						var spTxt = plTxt.split("");
						spTxt = spTxt.join(String.fromCharCode(8203));
						var chNode = document.createTextNode(spTxt);
						cNode.parentNode.replaceChild(chNode,cNode);
					}
				}
			}
		}
	}else{
		var wordBreak = function() {
			wrapFlg = chkWrapFlg();
			if ( wrapFlg == 0 ) {
				// 折り返さない
				if( document.styleSheets[0].addRule ){
					document.styleSheets[0].addRule(".menu_bk","white-space:nowrap");
				} else if ( document.styleSheets[0].insertRule ){
					document.styleSheets[0].insertRule(".menu_bk{white-space:nowrap}", document.styleSheets[0].cssRules.length );
				} else {
					return false;
				}
			} else {
				// 折り返す
				if( document.styleSheets[0].addRule ){
					document.styleSheets[0].addRule(".menu_bk","word-break:break-all");
				}else if( document.styleSheets[0].insertRule ){
					document.styleSheets[0].insertRule(".menu_bk{word-break:break-all}", document.styleSheets[0].cssRules.length );
				}else{
					return false;
				}
			}
		}
	}
	var addEvent = function(elm,listener,fn){
		try{
			elm.addEventListener(listener,fn,false);
		}catch(e){
			elm.attachEvent("on"+listener,fn);
		}
	}
	addEvent(window,"load",wordBreak);
}

// ********************************************************************************
//  _wrapflgの属性を参照(属性がない場合は1を返す)
//    @PRAM		:	NONE
//    @RETURN	:	0:折り返さない	1:折り返す
//    @DATE		:	2009/11/24
//    @AUTOR	:	inui
// ********************************************************************************
function chkWrapFlg() {
	var tags = document.getElementsByTagName("div");
	var flg;
	var tag;
	for (i = 0; i < tags.length; i++) {
		tag = tags[i];
		if (tag.className == CLASS_NAME){
			flg = tag.getAttribute("_wrapflg");
		}
	}
	if (flg == undefined) {
		flg = 1;			// 折り返す
	}
	return flg;
}