/******************
blinkhash.js
ver. 2010-1119_1.1
(C) 2005-2010 Wataru Kanzaki, Wings-Winds, http://wi-wi.jp/
http://home.wi-wi.jp/software/js_blinkhash/
arranged 2010-1122 Wataru Kanzaki
******************/
var BLINK=(function(){
	this.BlinkSpeed     = 200;
	this.BlinkTimes     = 3;
	this.Bar            = ['h1','h2','h3','h4','h5','h6','h7','caption'];
	this.HighlightStyle = {'background-color':'#ff0000',color:'#009900'};
	this.ScrollPixels   = 150;
	this.ScrollSpeed    = 50;
	this.ConstLeft      = 0;
	this.ConstTop       = false;
	this.UseParent      = true;

	//do not change;
	this.DefaultStyle={};
	return this;
})();

function _Blink(){
	var wlo=window.location || document.location;
	this.host=wlo.host;
	this.protocol=wlo.protocol;
	this.agt=navigator.userAgent.toLowerCase();
	this.platform=navigator.platform.toLowerCase();
	this.path=GetPath(wlo.pathname);
	this.filename=GetFilename(wlo.pathname);
	this.location=this.protocol+"//"+this.host+this.path+this.filename;
	this.tim=null;
	this.toX=0;
	this.toY=0;
	this.scrollx=0;
	this.scrolly=0;
	this.lights=0;
	this.hash=null;
	this.target=window;
	this.bar=null;

	this.doClick=function(e){
		e=e||window.event;
		Blink._Do(e);
		return false;
	};
	this.doKeydown=function(e){
		e=e||window.event;
		if(e.keyCode!=13){return true;}
		Blink._Do(e);
		return false;
	};
	this._Do=function(e){
		var tar=e.target||e.srcElement;
		while(!!tar && (tar.nodeName!='A')){
			tar=tar.parentNode;
		}
		if(!tar)return;
		Blink.hash=GetHash(tar);
		if(!Blink.hash)
			return true;
		Blink.target=GetWindow(tar.target);
		if(!Compare(tar, Blink.location, Blink.target.location.href)){
			StopEvent(e);
			Blink.target.location.href=MakePath(GetHref(tar), Blink.location)+'#'+Blink.hash;
			
			return false;
		}

		var ha=GetElement(Blink.hash, Blink.target);
		if(!ha)
			return;
		StopEvent(e);
		if(Blink.tim){Blink.Reset();Blink.tm=clearTimeout(Blink.tim);}
		Blink.scrollx=GetScrollLeft();
		Blink.scrolly=GetScrollTop();
		var p;
		if(window.opera && ha.nodeName.toUpperCase()=='A' && ha.innerHTML==''){
			var ns=ha.nextSibling;
			while(!!ns && ns.nodeType!=1){
				ns=ns.nextSibling;
			}
			if(!!ns){
				p=Pos(ns);
			}else{
				return;
			}
		}else{
			p=Pos(ha);
		}
		Blink.toX=GetScrollToX(p);
		Blink.toY=GetScrollToY(p);
		SEARCHBAR:do{
		if(BLINK.UseParent && ha.nodeName && ha.nodeName.toUpperCase()=='A'){
			var b=ha.parentNode;
			var nodeName=b.nodeName.toUpperCase();
			for(i=0;i<BLINK.Bar.length;i++){
				if(nodeName==BLINK.Bar[i]){
					o=b;
					break SEARCHBAR;
				}
			}
			b=ha.nextSibling;
			while(b && b.nodeType!=1){
				b=b.nextSibling;
			}
			if(!!b){
				var nodeName=b.nodeName.toUpperCase();
				for(i=0;i<BLINK.Bar.length;i++){
					if(nodeName==BLINK.Bar[i]){
						o=b;
						break SEARCHBAR;
					}
				}
			}
		}
		for(i=0;i<BLINK.Bar.length;i++){
			if(!ha.getElementsByTagName)break SEARCHBAR;
			var b=ha.getElementsByTagName(BLINK.Bar[i]);
			if(!b){continue;}
			o=b[0];
			if(!!o)break SEARCHBAR;
		}
		}while(false);
		if(!o){o=ha;}
		Blink.bar=o;
		for(var i in BLINK.HighlightStyle){
			BLINK.DefaultStyle[i]=GetStyle(o, i);
		}
		Blink._Scroll();
	};
	this.Scroll=function(arg){
		if(!arg)
			arg={};
		if(arg.hash){
			Blink._Do({target:{href:arg.hash,nodeName:'A',target:arg.target||'_self'}});
		}else{
			if(Blink.tim){Blink.Reset();clearTimeout(Blink.tim);}
			Blink.hash='';
			Blink.target=GetWindow(arg.target||'_self');
			Blink.scrollx=GetScrollLeft();
			Blink.scrolly=GetScrollTop();
			var p={y:arg.y||Blink.scrolly,x:arg.x||Blink.scrollx};
			Blink.toX=GetScrollToX(p);
			Blink.toY=GetScrollToY(p);
			Blink.bar=null;
			Blink._Scroll();
		}
	};
	this._Scroll=function(){
		clearTimeout(Blink.tim);
		if(Blink.scrolly==Blink.toY && Blink.scrollx==Blink.toX){
			Blink.lights=0;
			if(!Blink.usrscroll){
				Blink._Blink();
			}
			return;
		}
		if(Blink.scrolly==Blink.toY){
			;
		}else if(Blink.scrolly<Blink.toY){
			Blink.scrolly+=Math.min(Math.ceil((Blink.toY-Blink.scrolly)/2),BLINK.ScrollPixels);
		}else{
			Blink.scrolly-=Math.min(Math.ceil((Blink.scrolly-Blink.toY)/2),BLINK.ScrollPixels);
		}
		if(Blink.scrollx==Blink.toX){
			;
		}else if(Blink.scrollx<Blink.toX){
			Blink.scrollx+=Math.min(Math.ceil((Blink.toX-Blink.scrollx)/2),BLINK.ScrollPixels);
		}else{
			Blink.scrollx-=Math.Max(Math.ceil((Blink.scrollx-Blink.toX)/2),BLINK.ScrollPixels);
		}
		Blink.target.scrollTo(Blink.scrollx, Blink.scrolly);
		Blink.tim=setTimeout("Blink._Scroll()",BLINK.ScrollSpeed);
	};
	this._Blink=function(){
		clearTimeout(Blink.tim);
		if(Blink.lights>=BLINK.BlinkTimes){
			Blink.Reset();
			if(!Blink.hash.length)
				return;
			var elm=GetElement(Blink.hash, Blink.target);
			if(!elm)
				return;
			var tid=elm.id, tnm=elm.name;
			if(tid)elm.id='';
			if(tnm)elm.name='';
			Blink.target.location.hash=Blink.hash;
			if (this.agt.indexOf('opera 8.01') != -1) {
				var doc=Blink.target.documentElement||Blink.target.document;
				doc.location.reload();
			}
			if(tid)elm.id=tid;
			if(tnm)elm.name=tnm;
			Blink.target.scrollTo(Blink.scrollx, Blink.scrolly);
			return;
		}
		if(++Blink.lights%2!=0){
			Blink.Highlight();
		}else{
			Blink.Reset();
		}
		Blink.tim=setTimeout("Blink._Blink()",BLINK.BlinkSpeed);
	};
	this.Reset=function(){
		try{
		if(!Blink.bar||!Blink.bar.style)return false;
		var os=Blink.bar.style;
		for(var i in BLINK.DefaultStyle){
			os[i]=BLINK.DefaultStyle[i];
		}
		}catch(e){return false;}
		return true;
	};
	this.Highlight=function(){
try{
		if(!Blink.bar||!Blink.bar.style)return false;
		var os=Blink.bar.style;
		for(var i in BLINK.HighlightStyle){
			os[i]=BLINK.HighlightStyle[i];
		}
}catch(e){return false;}
		return true;
	};
	function GetScrollToX(p){
		if(BLINK.ConstLeft===true){
			return Blink.scrollx;
		}else if(BLINK.ConstLeft===false){
			var docw=GetDocumentWidth();
			var winw=(document.all && !window.opera)?Max(document.documentElement.offsetWidth):Max(Blink.target.innerWidth);
			if(doch==winh){
				return p.x;
			}else{
				var n=docw-winw;
				return (n<p.x)?n:p.x;
			}
		}else{
			return BLINK.ConstLeft;
		}
	}
	function GetScrollToY(p){
		if(BLINK.ConstTop===true){	
			return Blink.scrolly;
		}else if(BLINK.ConstTop===false){
			var doch=GetDocumentHeight();
			var winh=(document.all && !window.opera)?Max(document.documentElement.offsetHeight):Max(Blink.target.innerHeight);
			if(doch==winh){
				return p.y;
			}else{
				var n=doch-winh;
				return (n<p.y)?n:p.y;
			}
		}else{
			return BLINK.ConstTop;
		}
	}
	function GetPath(url){
		var str=url.toString();
		var agt=(!this.agt)?navigator.userAgent.toLowerCase():this.agt;
		var platform=(!this.platform)?navigator.platform.toLowerCase():this.platform;
		if((platform.indexOf('mac')!=-1) && (agt.indexOf('msie')!=-1)){
			var RE=/(.*\/)([^\/]+)$/;
			if(RE.test(str)){
				return RegExp.$1;
			}
		}else{
			var RE=RegExp("(.*\/)([^\/]+)$", "");
			if(RE.exec(str)){
				return RegExp.$1;
			}
		}
		return str;
	}
	function GetLocation(url){
		return url.toString().replace(/#.*/, "").replace(/\?.*/, "");
	}
	function GetHash(anc){
		if(!anc)
			return '';
		var url=GetHref(anc);
		var p=url.indexOf('#');
		return (p==-1)?'':url.substring(p+1);
	}
	function GetFilename(url){
		var str=url.toString();
		var agt=(!this.agt)?navigator.userAgent.toLowerCase():this.agt;
		var platform=(!this.platform)?navigator.platform.toLowerCase():this.platform;
		if((platform.indexOf('mac')!=-1) && (agt.indexOf('msie')!=-1)){
			var RE=/([^\/]+)$/;
			if(RE.test(str)){
				return RegExp.$1;
			}
		}else{
			var RE=RegExp("([^/]+)$","");
			if(RE.exec(str)){
				return RegExp.$1;
			}
		}
		return "";
	}
	function Max() {
		var mx=0;
		for(var i=0;i<arguments.length;i++){
			if(isNaN(arguments[i]))continue;
			if(mx<arguments[i]){
				mx=arguments[i];
			}
		}
		return mx;
	}
	function GetStyle(el, prop){
		if(!!el.style && el.style[prop]){
			return el.style[prop];
		}else if(document.defaultView && document.defaultView.getComputedStyle){
			prop=prop.replace(/([A-Z])/g, "-$1");
			prop=prop.toLowerCase();
			return document.defaultView.getComputedStyle(el,"").getPropertyValue(prop);
		}else if(el.currentStyle){
//			return el.currentStyle[prop];
			return el.currentStyle[prop]||'';
		}else{
//			return null;
			return '';
		}
	}
	function Pos(id){
		var el=GetElement(id);
		var pos={x:0,y:0,w:0,h:0};
		var platform=(!this.platform)?navigator.platform.toLowerCase():this.platform;
		if(el.getBoundingClientRect){
			var rect=el.getBoundingClientRect();
			var top=GetScrollTop();
			var left=GetScrollLeft();
			var width=Max(rect.width,el.clientWidth);
			var height=Max(rect.height,el.clientHeight);
			pos={x:parseInt(left+rect.left),y:parseInt(top+rect.top),w:parseInt(width),h:parseInt(height)};
		}else if(document.getBoxObjectFor){
			var rect=document.getBoxObjectFor(el);
			var top=Max(parseInt(GetStyle(el, "borderTopWidth")),0);
			var left=Max(parseInt(GetStyle(el, "borderLeftWidth")),0);
			var width=Max(rect.width,el.clientWidth);
			var height=Max(rect.height,el.clientHeight);
			pos={x:parseInt(rect.x-left),y:parseInt(rect.y-top),w:parseInt(width),h:parseInt(height)};
		}else{
			pos.w=parseInt(el.clientWidth);
			pos.h=parseInt(el.clientHeight);
			while (el) {
				pos.x += el.offsetLeft||el.left||0;
				pos.y += el.offsetTop||el.top||0;
				el = el.offsetParent;
			}
			if(document.body){
				pos.x-=document.body.offsetLeft;
				pos.y-=document.body.offsetTop;
			}
			if (platform.indexOf("mac")!=-1 && !!document.body){
				pos.x+=document.body.offsetLeft;
				pos.y+=document.body.offsetTop;
			}
			pos.x=parseInt(pos.x);
			pos.y=parseInt(pos.y);
		}
		return pos;
	}
	function GetWindow(tar, win) {
		if(tar=='_self')
			return window;
		if(tar=='_top')
			return window.top;
		if(tar=='_parent')
			return window.parent;
		if(tar=='_blank')
			return null;
		win=win||window.top;
		var base=document.getElementsByTagName('base');
		var baseTar='';
		for(var i=0,t;i<base.length;i++){
			t=base[i].getAttribute('target');
			if(!t||!t.length)
				continue;
			baseTar=t;
			break;
		}
		if(!tar||tar=='')
			tar=baseTar;
		if(!tar)
			return window;
		var frms=[];
		for(var i=0;i<win.frames.length;i++){
			frms.push(win.frames[i]);
		}
		for(var i=0;win=frms[i];i++){
			if(win.name==tar || win.id==tar){
				break;
			}
			for(var k=0;k<win.frames.length;k++)
				frms.push(win.frames[k]);
			var doc=win.document||win.documentElement;
			if(doc.getElementsByTagName)
				for(var k=0,fs=doc.getElementsByTagName('iframe');k<fs.length;k++)
					frms.push(fs[k]);
		}
		return win;
	}
	function GetElement(en, win) {
		if(typeof en != 'string'){ return en; }
		if(!document.getElementById || !document.getElementsByName){
			return GetElementByLayer(en, win);
		}
		var doc;
		if(win){
			doc=win.documentElement||win.document;
		}else{
			doc=document;
		}
		if(!doc)
			return null;
		var els=doc.getElementById(en);
		if(!!els){return els;}
		var els=doc.getElementsByName(en);
		if(!els){
			return null;
		}else if(!!els.length){
			return els[0];
		}else if(!!els.item){
			return els.item(0);
		}else{
			return null;
		}
	}
	function GetElementByLayer(en, doc){
		var el;
		if(document.all){
			el=document.all[en];
		}else if(document.layers){
			doc=doc||document;
			el=doc[en];
			for(var i=0;!el&&i<doc.layers.length;i++){
				el=GetElementByLayer(en, doc.layers[i].document);
			}
		}
		for(var i=0;!el&&i<doc.forms.length;i++){
			el=doc.forms[i][en];
		}
		return el;
	}
	this.Create=function(){
		if(!!window.RemoveEventListener){
			window.RemoveEventListener('load', Blink.Create, false);
		}else if(!!window.dettachEvent){
			window.dettachEvent('onload', Blink.Create);
		}

		if(document.getElementsByTagName){
			var base=document.getElementsByTagName('base');
			if(base && base.length){
				var href=base[0].getAttribute('href');
				if(href){
					Blink.location=href;
					var p=href.match(/\/\/([^\/]+)\//);
					if(p)
						Blink.host=p[1];
					var p=href.match(/^(.+:)\/\//);
					if(p)
						Blink.protocol=p[1];
					href=href.replace(/^.+:\/\//, '').replace(/^.+?\//, '');
					Blink.path=GetPath(href);
					Blink.filename=GetFilename(href);
				}
			}
		}
		Parse(document);
		BLINK.BlinkTimes*=2;
		if(window.location.hash && window.location.hash.length){
			Blink._Do({target:{href:location.href,nodeName:'A',target:'_self'}});
		}
	};
	function MakePath(location, base){
		var loc='';
		location=GetLocation(location);
		if(!location.length)
			return base; //anchor='#xxx', same as the document
		if(location.indexOf('://')>=0){ //absolute url
			loc=location;
		}else{
			var host='',protocol='http:';
			var p=base.match(/\/\/([^\/]+)\//);
			if(p)
				var host=p[1];
			var p=base.match(/^(.+:)\/\//);
			if(p)
				protocol=p[1];

			if(location.indexOf('/')==0){ //absolute path
				loc=protocol+'//'+host+location;
			}else{
				if(base.lastIndexOf('/')!=base.length){
					base=base.replace(/[^/]+$/,'');
				}
				base=base.replace(/^(.+:)\/\//,'');
				base=base.replace(/^([^\/]+)\//,'');
				var dirs=base.split('/');
				var udirs=location.split('/');
				for(var i=0;i<udirs.length;i++){
					if(udirs[i]=='..'){
						dirs.length--;
					}else if(udirs[i]=='.'){
						; // none
					}else{
						dirs[dirs.length-1]=udirs[i];
					}
				}
				loc=protocol+'//'+host+'/'+dirs.join('/');
			}
		}
		return loc;
	};
	function GetHref(anchor){
		return (anchor.getAttribute)?anchor.getAttribute('href'):(anchor.href)?anchor.href:'';
	}
	function Compare(anchor, base, location){
		if(!location)
			location=Blink.location;
		location=GetLocation(location);
		var href=MakePath(GetHref(anchor), base||window.location.href);
		location=location.replace(/^.*?:\/\/\/?/,'');
		href=href.replace(/^.*?:\/\/\/?/,'');
		return (href==location);
	}
	function Parse(o){
		for(var i=0,a;i<o.links.length;i++){
			a=o.links[i];
			if(GetHash(a)==''){continue;}
			if(!!a.addEventListener){
				a.addEventListener('click', Blink.doClick, false);
				a.addEventListener('keydown', Blink.doKeydown, false);
			}else if(!!a.attachEvent){
				a.attachEvent('onclick', Blink.doClick);
				a.attachEvent('onkeydown', Blink.doKeydown);
			}else{
				if(a.onclick){
					var f=a.onclick;
					a.onclick=function(e){f(e);Blink.doClick(e);}
				}else{
					a.onclick=Blink.doClick;
				}
				if(a.onkeydown){
					var f=a.onkeydown;
					a.onkeydown=function(e){f(e);Blink.doClick(e);}
				}else{
					a.onkeydown=Blink.doKeydown;
				}
			}
		}
	}//
	function GetScrollTop(){
		var w=Blink.target;
		var doc=w.documentElement||w.document;
		var db=(doc.body)?doc.body.scrollTop:0;
		var de=(doc.documentElement)?doc.documentElement.scrollTop:0;
		return Max(db,de,w.scrollY,w.scrollTop,w.pageYOffset);
	}//
	function GetScrollLeft(){
		var w=Blink.target;
		var doc=w.documentElement||w.document;
		var db=(doc.body)?doc.body.scrollLeft:0;
		var de=(doc.documentElement)?doc.documentElement.scrollLeft:0;
		return Max(db,de,w.scrollX,w.scrollLeft,w.pageXOffset);
	}//
	function GetDocumentWidth(){
		var w=Blink.target;
		var doc=w.documentElement||w.document;
		if (doc.body){
			return Max(doc.width,doc.body.offsetWidth,doc.body.clientWidth);
		}else{
			return Max(doc.width);
		}
	}
	function GetDocumentHeight(){
		var w=Blink.target;
		var doc=w.documentElement||w.document;
		if(doc.body){
			return Max(doc.height,doc.body.offsetHeight,doc.body.clientHeight);
		}else{
			return Max(doc.height);
		}
	}
	function StopEvent(e){
		if(e.preventDefault){
			e.preventDefault();
			e.stopPropagation();
		}else{
			e.returnValue=false;
			e.cancelBubble=true;
		}
		return false;
	}
}//_Blink
_Blink.prototype.BlinkInit=function(){
	var RE=new RegExp("(.*)\-([a-z])(.*)");
	for(var i in BLINK.HighlightStyle){
		var v=i;
		while(RE.test(v)){
			v=RegExp.$1+RegExp.$2.toUpperCase()+RegExp.$3;
		}
		BLINK.HighlightStyle[v]=BLINK.HighlightStyle[i];
	}
	for(i=0;i<BLINK.Bar.length;i++){
		BLINK.Bar[i]=BLINK.Bar[i].toUpperCase();
	}
	if(!!window.addEventListener){
		window.addEventListener('load', Blink.Create, false);
	}else if(!!window.attachEvent){
		window.attachEvent('onload', Blink.Create);
	}else{
		setTimeout('Blink.Create()', 1000);
	}
	return true;
};

var Blink=new _Blink();
Blink.BlinkInit();

