
/*========== Script Contents ==========

	1. Open Window Setting
	2. Open Window Setting [Window Size Assignment]
	3. Smooth Scroll Setteing
	4. Justify a Box Height
	5. Copyright
	6. SwapImage
	7. Solical Book Marks Setteing

====================================== */





/*===== ■1. Open Window Setting =====*/
function externalLinks() {
	if (!document.getElementsByTagName) return;
		var anchors = document.getElementsByTagName("a");
	for (var i=0; i<anchors.length; i++) {
		var anchor = anchors[i];
	if (anchor.getAttribute("href") &&
		((anchor.getAttribute("rel") == "external nofollow") || (anchor.getAttribute("rel") == "nofollow external") || (anchor.getAttribute("rel") == "external")))
		anchor.target = "_blank";
		}
	}

window.onload = externalLinks;





/*===== ■2. Open Window Setting [Window Size Assignment] =====*/
function openWindow(theURL,winName,features) {
	window.open(theURL,winName,features);
}





/*===== ■3. Smooth Scroll Setteing =====*/
Scroller = {
	// control the speed of the scroller.
	// dont change it here directly, please use Scroller.speed=50;
	speed:10,

	// returns the Y position of the div
	gy: function (d) {
		gy = d.offsetTop
		if (d.offsetParent) while (d = d.offsetParent) gy += d.offsetTop
		return gy
	},

	// returns the current scroll position
	scrollTop: function (){
		body=document.body
		d=document.documentElement
		if (body && body.scrollTop) return body.scrollTop
		if (d && d.scrollTop) return d.scrollTop
		if (window.pageYOffset) return window.pageYOffset
		return 0
	},

	// attach an event for an element
	// (element, type, function)
	add: function(event, body, d) {
		if (event.addEventListener) return event.addEventListener(body, d,false)
		if (event.attachEvent) return event.attachEvent('on'+body, d)
	},

	// kill an event of an element
	end: function(e){
		if (window.event) {
			window.event.cancelBubble = true
			window.event.returnValue = false
	  		return;
		}
		if (e.preventDefault && e.stopPropagation) {
		  e.preventDefault()
		  e.stopPropagation()
		}
	},
	
	// move the scroll bar to the particular div.
	scroll: function(d){
		i = window.innerHeight || document.documentElement.clientHeight;
		h=document.body.scrollHeight;
		a = Scroller.scrollTop()
		if (d>a) {
			if (d>h-i) d = h-i;
			a += Math.ceil((d-a)/Scroller.speed);
		}
		else
			a = a+(d-a)/Scroller.speed;
		window.scrollTo(0,a)
	  	if(a==d || Scroller.offsetTop==a)clearInterval(Scroller.interval)
	  	Scroller.offsetTop=a
	},
	// initializer that adds the renderer to the onload function of the window
	init: function(){
		Scroller.add(window,'load', Scroller.render)
	},

	// this method extracts all the anchors and validates then as # and attaches the events.
	render: function(){
		a = document.getElementsByTagName('a');
		Scroller.end(this);
		window.onscroll
		for (i=0;i<a.length;i++) {
			l = a[i];
			p1 = l.href.replace(/#.*/, "");
			p2 = location.href.replace(/#.*/, "");
			if(l.href && l.href.indexOf('#') != -1 && ((p1==p2) || ('/'+p1==p2)) ){
				Scroller.add(l,'click',Scroller.end)
				l.onclick = function(){
					Scroller.end(this);
					l=this.hash.substr(1);
					a = document.getElementById(l);
					if (a) {
						clearInterval(Scroller.interval);
						Scroller.interval=setInterval('Scroller.scroll('+Scroller.gy(a)+')',10);
					}
				}
			}
		}
	}
}
// invoke the initializer of the scroller
Scroller.init();





/*===== ■4. Justify a Box Height =====*/
new function(){
	
	function HeightLine(){
	
		this.className="HeightLine";
		this.parentClassName="HeightLineParent"
		reg = new RegExp(this.className+"([a-zA-Z0-9-_]+)", "i");
		objCN =new Array();
		var objAll = document.getElementsByTagName ? document.getElementsByTagName("*") : document.all;
		for(var i = 0; i < objAll.length; i++) {
			var eltClass = objAll[i].className.split(/¥s+/);
			for(var j = 0; j < eltClass.length; j++) {
				if(eltClass[j] == this.className) {
					if(!objCN["main CN"]) objCN["main CN"] = new Array();
					objCN["main CN"].push(objAll[i]);
					break;
				}else if(eltClass[j] == this.parentClassName){
					if(!objCN["parent CN"]) objCN["parent CN"] = new Array();
					objCN["parent CN"].push(objAll[i]);
					break;
				}else if(eltClass[j].match(reg)){
					var OCN = eltClass[j].match(reg)
					if(!objCN[OCN]) objCN[OCN]=new Array();
					objCN[OCN].push(objAll[i]);
					break;
				}
			}
		}
		
		//check font size
		var e = document.createElement("div");
		var s = document.createTextNode("S");
		e.appendChild(s);
		e.style.visibility="hidden"
		e.style.position="absolute"
		e.style.top="0"
		document.body.appendChild(e);
		var defHeight = e.offsetHeight;
		
		changeBoxSize = function(){
			for(var key in objCN){
				if (objCN.hasOwnProperty(key)) {
					//parent type
					if(key == "parent CN"){
						for(var i=0 ; i<objCN[key].length ; i++){
							var max_height=0;
							var CCN = objCN[key][i].childNodes;
							for(var j=0 ; j<CCN.length ; j++){
								if(CCN[j] && CCN[j].nodeType == 1){
									CCN[j].style.height="auto";
									max_height = max_height>CCN[j].offsetHeight?max_height:CCN[j].offsetHeight;
								}
							}
							for(var j=0 ; j<CCN.length ; j++){
								if(CCN[j].style){
									var stylea = CCN[j].currentStyle || document.defaultView.getComputedStyle(CCN[j], '');
									var newheight = max_height;
									if(stylea.paddingTop)newheight -= stylea.paddingTop.replace("px","");
									if(stylea.paddingBottom)newheight -= stylea.paddingBottom.replace("px","");
									if(stylea.borderTopWidth && stylea.borderTopWidth != "medium")newheight-= stylea.borderTopWidth.replace("px","");
									if(stylea.borderBottomWidth && stylea.borderBottomWidth != "medium")newheight-= stylea.borderBottomWidth.replace("px","");
									CCN[j].style.height =newheight+"px";
								}
							}
						}
					}else{
						var max_height=0;
						for(var i=0 ; i<objCN[key].length ; i++){
							objCN[key][i].style.height="auto";
							max_height = max_height>objCN[key][i].offsetHeight?max_height:objCN[key][i].offsetHeight;
						}
						for(var i=0 ; i<objCN[key].length ; i++){
							if(objCN[key][i].style){
								var stylea = objCN[key][i].currentStyle || document.defaultView.getComputedStyle(objCN[key][i], '');
									var newheight = max_height;
									if(stylea.paddingTop)newheight-= stylea.paddingTop.replace("px","");
									if(stylea.paddingBottom)newheight-= stylea.paddingBottom.replace("px","");
									if(stylea.borderTopWidth && stylea.borderTopWidth != "medium")newheight-= stylea.borderTopWidth.replace("px","")
									if(stylea.borderBottomWidth && stylea.borderBottomWidth != "medium")newheight-= stylea.borderBottomWidth.replace("px","");
									objCN[key][i].style.height =newheight+"px";
							}
						}
					}
				}
			}
		}
		
		checkBoxSize = function(){
			if(defHeight != e.offsetHeight){
				changeBoxSize();
				defHeight= e.offsetHeight;
			}
		}
		changeBoxSize();
		setInterval(checkBoxSize,1000)
		window.onresize=changeBoxSize;
	}
	
	function addEvent(elm,listener,fn){
		try{
			elm.addEventListener(listener,fn,false);
		}catch(e){
			elm.attachEvent("on"+listener,fn);
		}
	}
	addEvent(window,"load",HeightLine);
}





/*===== ■5. Copyright =====*/
function WriteCopyYear() 
{
	document.write(new Date().getFullYear());
}





/*===== ■6. SwapImage Setteing ===== (検索フォーム用) */
function MM_swapImage() { //v3.0
var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}





/*===== ■7. Solical Book Marks Setteing =====*/
    var sbm_ary = {
        "explorer" : ["Explorer","",2],
        "hatena" : ["Hatena","http://b.hatena.ne.jp/add?mode=confirm&&url={url}&title={title}",3],
        "delicious" : ["Del.icio.us","http://del.icio.us/post?url={url}&title={title}",0],
        "livedoor_clip" : ["livedoorクリップ","http://clip.livedoor.com/redirect?link={url}&title={title}",0],
        "google_bmarks" : ["Google Bookmarks","http://www.google.com/bookmarks/mark?op=edit&bkmk={url}&title={title}",0],


/*         "yahoo_bmarks" : ["Yahoo!ブックマーク","http://bookmarks.yahoo.co.jp/bookmarklet/showpopup?t={title}&u={url}",0], */

         "yahoo_bmarks" : ["Yahoo!ブックマーク","https://login.yahoo.co.jp/config/login?.src=bmk2&.done=http%3A%2F%2Fbookmarks.yahoo.co.jp%2Fbookmarklet%2Fshowpopup%3Ft%3D%25E3%2583%25AC%25E3%2583%25B3%25E3%2582%25BF%25E3%2583%25AB%25E3%2582%25B5%25E3%2583%25BC%25E3%2583%2590%25E3%2583%25BC%25E6%25AF%2594%25E8%25BC%2583%25E3%2582%25B5%25E3%2582%25A4%25E3%2583%2588%2520%257C%2520%25E3%2581%2593%25E3%2581%25A0%25E3%2582%258F%25E3%2582%258A%25E6%25A4%259C%25E7%25B4%25A2%25E3%2581%25A7%25E3%2580%2581%25E3%2583%25AC%25E3%2583%25B3%25E3%2582%25BF%25E3%2583%25AB%25E3%2582%25B5%25E3%2583%25BC%25E3%2583%2590%25E3%2583%25BC%25E5%25BE%25B9%25E5%25BA%2595%25E6%25AF%2594%25E8%25BC%2583%25EF%25BC%2581%26amp%3Bu%3Dhttp%253A%252F%252Fwww.rental-server-search.jp%252F",0], 



        "pookmark" : ["pookmark","http://pookmark.jp/post?url={url}&title={title}",0],
        "fc2" : ["FC2ブックマーク","http://bookmark.fc2.com/user/post?url={url}&title={title}",0],
        "buzzurl" : ["Buzzurl","http://buzzurl.jp/entry/{url}",3],
        "newsing" : ["newsing","http://newsing.jp/add?url={url}&title={title}",0]
    /*    "bluedot" : ["Blue Dot","javascript:sbmBlueDot();",1], */
    /*    "bluedot" : ["Blue Dot","http://bluedot.us/Authoring.aspx?u={url}&title={title}",0], */
    /*    "blinklist" : ["blinklist","http://blinklist.com/index.php?Action=Blink/addblink.php&Url={url}&Title={title}",0], */
    /*    "blogmarks" : ["Blogmarks.net","http://blogmarks.net/my/new.php?mini=1&simple=1&url={url}&title={title}",0], */
    /*    "bookmarktracker" : ["BookmarkTracker","http://www.bookmarktracker.com/frame_add.cfm?url={url}&title={title}",0], */
    /*    "digg" : ["Digg","http://digg.com/submit?phase=2&url={url}&title={title}",0], */
    /*    "furl" : ["FURL","http://furl.net/storeIt.jsp?u={url}&t={title}",0], */
    /*    "hatena" : ["はてなブックマーク","http://b.hatena.ne.jp/append?{url}",2], */
    /*    "magnolia" : ["magnolia","http://ma.gnolia.com/bookmarklet/add?url={url}&title={title}",0], */
    /*    "netscape" : ["Netscape"," http://www.netscape.com/submit/?U={url}&T={title}",0], */
    /*    "nifty_clip" : ["niftyクリップ","http://clip.nifty.com/create?url={url}&title={title}",0], */
    /*    "newsvine" : ["Newsvine","http://www.newsvine.com/_wine/save?u={url}&h={title}",0], */
    /*    "reddit" : ["Reddit","http://reddit.com/submit?url={url}&title={title}",0], */
    /*    "tailrank" : ["Tailrank","http://tailrank.com/share/?link_href={url}&title={title}",0], */
    /*    "technorati" : ["Technorati","http://www.technorati.com/faves?add={url}",0], */
    /*    "windows_live" : ["Windows Live","https://favorites.live.com/quickadd.aspx?marklet=1&mkt=en-us&url={url}&title={title}&top=1",0], */
    };
    var sbm_ary_max="";
    for(key in sbm_ary){ sbm_ary_max++; }
    var    d=document;
    var ie=d.all?1:0
    var ns6=d.getElementById&&!d.all?1:0
    var opera=window.opera?1:0
    var shareID="SbmForm";

    function post_Share(share_name,en) {
        var _url=location.href;
        var _title=document.title;
        var url=encodeURIComponent(_url);
        var title=encodeURIComponent(_title);
        var base=sbm_ary[share_name][1];
        if(en=='en'){
            /* エンコード */
            base = base.replace('{url}', url);
            base = base.replace('{title}', title);
        }else{
            /* エンコードなし */
            base = base.replace('{url}', _url);
            base = base.replace('{title}', _title);
        }
        w=window.open(base,"w","top=0,left=0,scrollbars=yes,toolbar=yes");
        w.focus();
        return false;
    }
    function disp_Share() {
        if(ie || ns6 || opera){
            obj=ns6 ? d.getElementById(shareID) : d.all(shareID);
        }
    }
	function fnOpen() {
	document.getElementById("SbmForm").style.display = "block";
}
	function fnClose() {
	document.getElementById("SbmForm").style.display = "none";
}

	function addBookmark(title,url) {
     if (window.sidebar) {
         window.sidebar.addPanel(title, url,"");
     } else if( document.all ) {
         window.external.AddFavorite( url, title);
     } else if( window.opera && window.print ) {
         return true;
     }
 }
    function create_Share(){
        var cnt=1;
        var ofst=4; /* 折り返しする数 */
        var s="<div class='social'>";
        for(key in sbm_ary){
            if(cnt==1 || cnt%ofst==1){
                s+="<ul>";
            }
            if(sbm_ary[key][2]==1){ /* js */
                s+="<li><a href='"+sbm_ary[key][1]+"' class='"+key+"'>"+sbm_ary[key][0]+"<\/a><\/li>";
            }if(sbm_ary[key][2]==2){ /* js */
                s+="<li><a href='javascript:void(0);' class='"+key+"' onclick=\javascript:addBookmark('レンタルサーバー比較サイト','http://www.rental-server-search.jp');>"+sbm_ary[key][0]+"<\/a><\/li>";
            }else if(sbm_ary[key][2]==3){ /* URLエンコード不要 */
                s+="<li><a href='javascript:void(0);' class='"+key+"' onclick=\"post_Share('"+key+"',0)\">"+sbm_ary[key][0]+"<\/a><\/li>";
            }else{ /* URLエンコード */
                  s+="<li><a href='javascript:void(0);' class='"+key+"' onclick=\"post_Share('"+key+"','en')\">"+sbm_ary[key][0]+"<\/a><\/li>";
              }
              if(cnt==sbm_ary_max || cnt%ofst==0){
                s+="<\/ul>";
            }
            cnt++;
        }
        s+="<\/div>";
        document.write(s);
    }