function initStyle(){
	if(typeof(doLoaded) != "undefined"){doLoaded();}


	preinsertHTML('banner-body', 'h1', '<div style="width:1px;height:272px;overflow:hidden;float:left;"></div>');

	insertidHTML('calendar', 'caption', '<img src="http://template.cocolog-nifty.com/000010/two_column_left/component/calender.gif" width="27" height="25" align="absmiddle" alt="カレンダー" style="margin:0px 8px 0px 0px" />', 0, '', 0);

	insertidHTML('syndicate', 'div', '<img src="http://template.cocolog-nifty.com/000010/two_column_left/component/syndicate.gif" width="27" height="25" align="absmiddle" alt="このサイトと連携する" style="margin:0px 8px 0px 0px" />', 0, '', 0);

	insertidHTML('profile', 'div', '<img src="http://template.cocolog-nifty.com/000010/two_column_left/component/profile.gif" width="27" height="22" align="absmiddle" alt="プロフィール" style="margin:0px 8px 0px 0px" />', 0, '', 0);

	insertidHTML('user-email', 'div', '<img src="http://template.cocolog-nifty.com/000010/two_column_left/component/user-email.gif" width="27" height="18" align="absmiddle" alt="メール送信" style="margin:0px 8px 0px 0px" />', 0, '', 0);

	insertidHTML('subscribe', 'div', '<img src="http://template.cocolog-nifty.com/000010/two_column_left/component/subscribe.gif" width="27" height="25" align="absmiddle" alt="このサイトをマイリストに追加" style="margin:0px 8px 0px 0px" />', 0, '', 0);

	insertidHTML('recent-entries', 'h2', '<img src="http://template.cocolog-nifty.com/000010/two_column_left/component/recent-entries.gif" width="27" height="21" align="absmiddle" alt="最近の記事" style="margin:0px 8px 0px 0px" />', 0, '', 0);

	insertidHTML('recent-comment', 'h2', '<img src="http://template.cocolog-nifty.com/000010/two_column_left/component/recent-comment.gif" width="27" height="19" align="absmiddle" alt="最近のコメント" style="margin:0px 8px 0px 0px" />', 0, '', 0);

	insertidHTML('recent-trackback', 'h2', '<img src="http://template.cocolog-nifty.com/000010/two_column_left/component/recent-trackback.gif" width="27" height="24" align="absmiddle" alt="最近のトラックバック" style="margin:0px 8px 0px 0px" />', 0, '', 0);

	insertidHTML('archive-datebased', 'h2', '<img src="http://template.cocolog-nifty.com/000010/two_column_left/component/archive-datebased.gif" width="27" height="21" align="absmiddle" alt="archive-datebased" style="margin:0px 8px 0px 0px" />', 0, '', 0);

	insertidHTML('archive-category', 'h2', '<img src="http://template.cocolog-nifty.com/000010/two_column_left/component/archive-category.gif" width="27" height="22" align="absmiddle" alt="カテゴリー" style="margin:0px 8px 0px 0px" />', 0, '', 0);

	insertidHTML('gallery', 'h2', '<img src="http://template.cocolog-nifty.com/000010/two_column_left/component/gallery.gif" width="27" height="27" align="absmiddle" alt="マイフォト" style="margin:0px 8px 0px 0px" />', 0, '', 0);

	insertidHTML('update-list', 'h2', '<img src="http://template.cocolog-nifty.com/000010/two_column_left/component/update-list.gif" width="27" height="27" align="absmiddle" alt="更新順ココログ一覧" style="margin:0px 8px 0px 0px" />', 0, '', 0);

	insertClassHTML('list', 'div', 'h2', '<img src="http://template.cocolog-nifty.com/000010/two_column_left/component/list.gif" width="27" height="23" align="absmiddle" alt="マイリスト" style="margin:0px 8px 0px 0px" />', 0, '', 0);

	insertClassHTML('entry-trackback', 'div', 'h2', '<img src="http://template.cocolog-nifty.com/000010/two_column_left/component/entry-trackback.gif" width="42" height="45" align="absmiddle" alt="トラックバック" style="margin:0px 8px 0px 0px" />', 0, '', 0);

	insertClassHTML('comment-list', 'div', 'h2', '<img src="http://template.cocolog-nifty.com/000010/two_column_left/component/comment-list.gif" width="42" height="44" align="absmiddle" alt="コメント" style="margin:0px 8px 0px 0px" />', 0, '', 0);

	insertClassHTML('comment-form', 'div', 'h2', '<img src="http://template.cocolog-nifty.com/000010/two_column_left/component/comment-form.gif" width="42" height="38" align="absmiddle" alt="コメントを書く" style="margin:0px 8px 0px 0px" />', 0, '', 0);

	insertClassHTML('comment-preview', 'div', 'h2', '<img src="http://template.cocolog-nifty.com/000010/two_column_left/component/comment-preview.gif" width="42" height="41" align="absmiddle" alt="コメントの確認" style="margin:0px 8px 0px 0px" />', 0, '', 0);

	insertClassHTML('comment-list-previous', 'div', 'h2', '<img src="http://template.cocolog-nifty.com/000010/two_column_left/component/comment-list-previous.gif" width="42" height="41" align="absmiddle" alt="これまでのコメント" style="margin:0px 8px 0px 0px" />', 0, '', 0);

	insertClassHTML('comment-error', 'div', 'h2', '<img src="http://template.cocolog-nifty.com/000010/two_column_left/component/comment-error.gif" width="42" height="39" align="absmiddle" alt="問題が発生しました" style="margin:0px 8px 0px 0px" />', 0, '', 0);

	insertClassHTML('contact-list', 'div', 'h2', '<img src="http://template.cocolog-nifty.com/000010/two_column_left/component/contact-list.gif" width="42" height="29" align="absmiddle" alt="コンタクト" style="margin:0px 8px 0px 0px" />', 0, '', 0);

	insertClassHTML('minibio', 'div', 'h2', '<img src="http://template.cocolog-nifty.com/000010/two_column_left/component/minibio.gif" width="42" height="34" align="absmiddle" alt="1行紹介" style="margin:0px 8px 0px 0px" />', 0, '', 0);

	insertClassHTML('bio', 'div', 'h2', '<img src="http://template.cocolog-nifty.com/000010/two_column_left/component/bio.gif" width="42" height="43" align="absmiddle" alt="自己紹介" style="margin:0px 8px 0px 0px" />', 0, '', 0);

	insertClassHTML('interests', 'div', 'h2', '<img src="http://template.cocolog-nifty.com/000010/two_column_left/component/interests.gif" width="42" height="35" align="absmiddle" alt="興味のあること" style="margin:0px 8px 0px 0px" />', 0, '', 0);

}



function insertClassHTML(insertClass, targetTag, insertTag, insertString, index, targetId, insertNumber){
	var classTag = targetTag;
	var classId = targetId;
	var insertNum = insertNumber;

	if(insertTag.length == 0){
		return;
	}
	if(targetTag.length == 0){
		classTag = 'div';
	}
	if(!targetId || targetId.length == 0){
		classId = '';
	}
	if(insertNumber == ''){
		insertNum = 0;
	}

	var oElement = getByTagName(classTag);
	if(!oElement){
		return;
	}
    var len = oElement.length;
    var tagcount = 0;
    var num;
    var tmpIndex;
    for (num=0; num<len; num++) {
		if(oElement[num] != null){
		    var element = oElement[num];
	        if (element.className == insertClass) {
	        	pLen = element.childNodes.length;
	        	var p;
	        	var pnum;
	        	for(pnum=0; pnum<pLen; pnum++){
	        		if(pnum == 0){
			        	p = element.firstChild;
						changeString(p, insertTag, insertString, 2, index, targetId, insertNumber);
	        		}
	        		p = p.nextSibling;
	        	}
    	    }
    	}
	}

}

function insertidHTML(insertID, insertTag, insertString, index){
	var oElement = document.getElementById(insertID);
	if(!oElement){
		return;
	}
	if(index == null){
		index = 0;
	}

    var len = oElement.length;
    var tagcount = 0;
    var tmpIndex;
    if (oElement.id == insertID) {
		p = oElement.firstChild;
		changeString(p, insertTag, insertString, 2, index);
    }
}

function preinsertHTML(replaceID, replaceTag, tag){
	var oElement = document.getElementById(replaceID);
	if(!oElement){
		return;
	}
	var regpre = new RegExp("<"+replaceTag, "i");
	var replen = replaceTag.length+1;

	var begin;
	var tmpbegin;
	if ((begin = oElement.innerHTML.search(regpre)) != -1) {
		var pre = oElement.innerHTML.substring(0, begin);
		oElement.innerHTML = pre + tag + oElement.innerHTML.substring(begin);
	}
}

function replaceId(replaceID, insertTag){
	var oElement = document.getElementById(replaceID);
	if(!oElement){
		return;
	}
	oElement.innerHTML = insertTag;
}

// inner function
function getclassBrowser(){
	var ua=navigator.userAgent;
	var classname;
    if(ua.match(/MSIE/) != null){
		classname = 'className';
	}
	else{
		classname = 'class';
	}
	return classname;
}

function changeString2(node, tag, string, whichcase, insertIndex, id){

	var classId = id;
    var tagcount = 0;
    var tmpIndex=0;
    
	if(!id || id.length == 0){
		classId = '';
	}

	while(node){
		if(node.firstChild){
			if(node.id == classId){
				if(changeString2(node.firstChild, tag, string, whichcase, insertIndex, id) == -1){
					return -1;
				}
			}
		}
		// 入れ替え対象タグ
		if(node.nodeName.toLowerCase() == tag.toLowerCase()){
			changestr(node, string, whichcase, insertIndex);
			return -1;
		}
		node = node.nextSibling;
    }
}

function changeString(node, tag, string, whichcase, insertIndex, id){

	var classId = id;
    var tagcount = 0;
    var tmpIndex=0;
    
	if(!id || id.length == 0){
		classId = '';
	}

	while(node){
		if(node.firstChild){
			if(node.id == classId){
				changeString(node.firstChild, tag, string, whichcase, insertIndex, id);
			}
		}
		// 入れ替え対象タグ
		if(node.nodeName.toLowerCase() == tag.toLowerCase()){
			changestr(node, string, whichcase, insertIndex);
		}
		node = node.nextSibling;
    }
}


function changestr(node, string, whichcase, insertIndex){

	// replace
	if(whichcase == 1){
		node.innerHTML =string;
	}
	// insert
	else{
    	tmpIndex=insertIndex;
		if(insertIndex == -1 || insertIndex > node.innerHTML.length){
			tmpIndex = node.innerHTML.length;
		}
		var str = node.innerHTML;
       	node.innerHTML =str.substring(0, tmpIndex) + string + str.substring(tmpIndex);
	}
}


// Common Javascript
var themeBaseURI = 'http://exaple.org/specialstyles';

// put image and flash files to themeBaseURI/THEME/
//  filename should be THEME-CLASSNAME.gif or THEME-ID.swf.
//  like mybow-comment.gif and mybow-recent-updates.swf

function insertFlashMovie (theme, divs) {
    for (i in divs) {
        var swfURL = themeBaseURI + '/' + theme + '/' + theme + '-' + divs[i] + '.swf';
        insertHTML(divs[i], '<embed src="' + swfURL + '" PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" TYPE="application/x-shockwave-flash" </embed>');
    }
}

function insertHTML (divID, tag) {
    var e = getByID(divID);
    e.innerHTML = tag + e.innerHTML;
}

function replaceHTML (divID, tag) {
  var e = getByID(divID);
	if(!e){
		return;
	}
  e.innerHTML = tag;
}

function replaceImage (theme, divs) {
    for (i in divs) {
        var imageURL = themeBaseURI + '/' + theme + '/' + theme + '-' + divs[i] + '.gif';        
        var tag = '<img src="' + imageURL + '" alt="' + divs[i] + '" />';
        replaceHTML(divs[i], tag);
    }
}

function replaceButton (theme, classes) {
    for (i in classes) {
        // alert(theme + '/' + theme + '-' + classes[i] + '.gif');
        doReplaceLinkToImage(classes[i], theme + '/' + theme + '-' + classes[i] + '.gif', '');
    }
}

function doReplaceLinkToImage (className, imageFilename, title) {
    if (title) {
        title = 'alt="' + title + '" ';
    } else {
        title = '';
    }
    var imageURL = themeBaseURI + '/' + imageFilename;
    var tag = '<img src="' + imageURL + '" ' + title + '/>';
    doReplaceLinkInnerHTML (className, tag);
}

function doReplaceLinkInnerHTML (className, str) {
    var e = getByTagName('a');
    var len = e.length;
    for (i=0; i<len; i++) {
        if (e[i].className == className) {
            e[i].innerHTML = str;
        }
    }
}

function eraseSeparator () {
    var e = getByTagName('span');
    var len = e.length;
    for (i=0; i<len; i++) {
        if (e[i].className == 'separator') {
            e[i].innerHTML = '';
        }
    }
}

function getByID (n) {
    var d = window.document;
    if (d.getElementById)
        return d.getElementById(n);
    else if (d.all)
        return d.all[n];
}

function getByTagName (n) {
    var d = window.document;
    if (d.getElementsByTagName)
        return d.getElementsByTagName(n);
    else if (d.all)
        return d.all[n];
}

