function REPORT(){
	this.ix=null;
	this.page=null;
	this.nav=null;
	this.content=null;
	this.header=null;
	this.fullPage=null;
	this.current;
	this.paginationTop;
	this.paginationBot;
	this.navTitle;
	this.navFoot;
	this.printWin;
	this.loading;
	this.ixLoaded=function(){
		if(!this.nav)return;
		this.fixLinks(window.ix);
		this.nav.innerHTML = window.ix.document.body.innerHTML;
	}
	
	this.loadingShow=function(){
		if(this.loading){
			//alert('show loading');
			this.loading.innerHTML = 'please wait...'
			this.loading.style.display = 'block';	
		}
	}

	this.loadingHide=function(){
		//alert('hide loading');
		if(this.loading){
			this.loading.innerHTML = 'please wait...'
			this.loading.style.display = 'none';	
		}
	}

	this.pageNav=function(){
		var _nav = '<a href="javascript:void(0)" onclick="report.prevPage()">&lt;back</a> | <a href="javascript:void(0)" onclick="report.printPage()">print</a> | <a href="javascript:void(0)" onclick="report.nextPage()">next&gt;</a>';
		if(this.paginationTop){
			this.paginationTop.innerHTML = _nav; 
		}
		if(this.paginationBot){
			this.paginationBot.innerHTML = _nav; 
		}
	}
	this.pageLoaded=function(){
		if(!this.content)return;
		this.fixLinks(window.page);
		this.fixImages(window.page);
		this.content.innerHTML = window.page.document.body.innerHTML;
		window.setTimeout('report.loadingHide()',400);
		var _href = window.page.document.location.href;
		var _sub = _href.split('#');
		if(_sub.length>1){
			_sub = _sub[1];
			this.navTo(_sub);
			//alert(_sub);
			/*
			var _targ = util.dE(_sub);
			if(_targ){
				//alert(_targ.offsetTop);
				//alert(window.document.body.offsetTop);			
				window.scrollTo(0,_targ.offsetTop);
				if(window.scrollY){
					this.nav.style.marginTop = window.scrollY+'px';
				}else if(document.documentElement.scrollTop){
					this.nav.style.marginTop = document.documentElement.scrollTop+'px';
				}
				alert(document.documentElement.scrollTop+':'+window.scrollY);			
			}else{
				window.open('#'+_sub,'_top');
			}
			*/
		}else{
			window.scrollTo(0,0);
			_sub = null;
		}
	}
	
	this.selectPage=function(_href){
		if(!_href){
			_href = window.page.document.location.href;
		}
		if(_href){
			var _targ = util.dE('LI'+_href);
			if(_targ){
				if(this.currentNav){
					if(_targ.id!=this.currentNav.id){
						this.currentNav.style.fontWeight = 'normal';
					}
				}
				this.currentNav=_targ;
				_targ.style.fontWeight= 'bold';
			}
		}
	}
	
	this.getFirstChild=function(_n){
		var _c = _n.childNodes;
		for(var i=0;i<_c.length;i++){
			//alert(_c[i].tagName+':'+_c[i].nodeType);
			if(_c[i].nodeType==1&&_c[i].tagName=='OL'){
				var _c2 = _c[i].childNodes;
				for(var j=0;j<_c2.length;j++){
					if(_c2[j].nodeType==1&&_c2[j].tagName=='LI'){
						return _c2[j];
					}
				}
				break;
			}
		}
	}

	this.getLastChild=function(_n){
		var _c = _n.childNodes;
		for(var i=0;i<_c.length;i++){
			//alert(_c[i].tagName+':'+_c[i].nodeType);
			if(_c[i].nodeType==1&&_c[i].tagName=='OL'){
				var _c2 = _c[i].childNodes;
				for(var j=_c2.length-1;j>=0;j--){
					if(_c2[j].nodeType==1&&_c2[j].tagName=='LI'){
						return _c2[j];
					}
				}
				break;
			}
		}
	}
	
	this.getNextNode=function(_node){
		var _n = _node.nextSibling;
		while(_n&&_n.nodeType!=1){
			_n = _n.nextSibling;
		}
		if(_n&&_n.tagName=='LI'){
			if(this.checkActiveNode(_n)){
				return _n;
			}else{
				return this.getNextNode(_n);
			}
		}else{
			var _n = _node.parentNode.parentNode;
			if(_n.tagName=='LI'){
				return this.getNextNode(_n);
			}
		}
	}

	this.getPrevNode=function(_node){
		var _n = _node.previousSibling;
		while(_n&&_n.nodeType!=1){
			_n = _n.previousSibling;
		}
		if(_n&&_n.tagName=='LI'){
			var _c = this.getLastChild(_n);
			if(_c){
				_n = _c;	
			}
			return _n;
		}else{
			var _n = _node.parentNode.parentNode;
			return _n;
		}
	}
	
	this.checkActiveNode=function(_node){
		var _c = _node.childNodes;
		for(var i=0;i<_c.length;i++){
			if(_c[i].nodeType==1&&_c[i].tagName=='A'){
				return true;
			}
		}
		return false;
	}
	
	this.nextPage=function(){
		if(this.currentNav){
			var _next;
			var _goDirect=false;
			var _l = [];
			var _n = this.currentNav;
			this.showChild(_n.parentNode);
			_next = this.getFirstChild(_n.parentNode);	
			if(!_next){
				_next = this.getNextNode(_n.parentNode);
			}
			if(_next){
				if(!_next.tagName){
					_next = _next.parentNode;
				}
				//alert(_next.tagName);
				var _c = _next.childNodes;
				for(var i=0;i<_c.length;i++){
					if(_c[i].tagName=='A'){
						this.showChild(_c[i]);
						_c[i].focus();
						this.clickItem(_c[i].href);
						break;
					}
				}
			}
		}
	
	}
	
	this.prevPage=function(){
		if(this.currentNav){
			var _next;
			var _goDirect=false;
			var _l = [];
			var _n = this.currentNav;
			this.showChild(_n.parentNode);
			_next = this.getPrevNode(_n.parentNode);
			if(_next){
				if(!_next.tagName){
					_next = _next.parentNode;
				}
				//alert(_next.tagName);
				var _c = _next.childNodes;
				for(var i=0;i<_c.length;i++){
					if(_c[i].tagName=='A'){
						//this.showChild(_c[i].parentNode.parentNode);
						_c[i].focus();
						this.clickItem(_c[i].href);
						break;
					}
				}
			}
		}
	
	}	
	
	this.navTo=function(_sub){
		this.selectPage();
		var _targ = util.dE(_sub);
		if(_targ){
			this.current = _sub;
			this.content.scrollTop = _targ.offsetTop			
			//alert(_targ.offsetTop);
			//alert(window.document.body.offsetTop);
			//this.content.scrollTo(0,_targ.offsetTop);
			/*
			if(this.content.scrollY){
				alert(this.content.scrollY);
//				this.nav.style.marginTop = window.scrollY-70+'px';
				if(window.scrollY-70>this.content.offsetTop){
					this.nav.style.marginTop = window.scrollY-70+'px';
				}else{
					this.nav.style.marginTop = '0px';
				}
			}else if(document.documentElement.scrollTop){
				if((document.documentElement.scrollTop-70)>=this.content.offsetTop*1){
					this.nav.style.marginTop = document.documentElement.scrollTop-70+'px';
				}else{
					this.nav.style.marginTop = '0px';
				}
//				this.nav.style.marginTop = document.documentElement.scrollTop-70+'px';
			}*/
			//alert(document.documentElement.scrollTop+':'+window.scrollY);			
		}/*else{
			window.open('#'+_sub,'_top');
		}*/
	}
	
	this.moveNavBar=function(){
		//if(!this.nav)return;
		if(window.scrollY){
			if(window.scrollY-70>this.content.offsetTop){
				this.nav.style.marginTop = window.scrollY-70+'px';
			}else{
				this.nav.style.marginTop = '0px';
			}
		}else if(document.documentElement.scrollTop){
			//alert(document.documentElement.scrollTop-70+':'+this.content.offsetTop);
			if((document.documentElement.scrollTop-70)>=this.content.offsetTop*1){
				this.nav.style.marginTop = document.documentElement.scrollTop-70+'px';
			}else{
				this.nav.style.marginTop = '0px';
			}
		}
	}
	
	this.init=function(){
		this.ix = util.dE('ix');	
		this.page = util.dE('page');
		this.nav = util.dE('nav');
		this.content = util.dE('content');
		this.header = util.dE('header');
		this.fullPage = util.dE('fullPage');
		this.paginationTop = util.dE('paginationTop');
		this.paginationBot = util.dE('paginationBot');
		this.navTitle = util.dE('navTitle');
		this.navFoot = util.dE('navFoot');
		this.loading = util.dE('loading');
		if(this.loading){
			this.loading.innerHTML = 'please wait...'	
		}
		this.resizePage();
		this.pageNav();
		document.title='TIAC Report';
		//this.ix.onload=this.ixLoaded;	
		//this.page.onload=this.pageLoaded;
		window.open('ix.htm','ix');
		window.open('cover.html','page');
	}
	
	this.fixLinks=function(_targ){
		var _a = _targ.document.body.getElementsByTagName('A');
		for(var i=0;i<_a.length;i++){
			if(_a[i].parentNode.tagName=='LI'){
				_a[i].id = 'LI'+_a[i].href; 
				_a[i].target='page';
			}else{
				_a[i].id = _a[i].name;
				_a[i].target='page';
			}
			var _ext = _a[i].href.split('.');
			if(_ext.length>1){
				switch(_ext[1]){
					case 'pdf':_a[i].target='_blank';break;
					case 'ppt':_a[i].target='_blank';break;
					case 'doc':_a[i].target='_blank';break;
					case 'xls':_a[i].target='_blank';break;
				}
			}
		}
		//alert(_a.length);
	}
	
	this.fixImages=function(_targ){
		var _img = _targ.document.body.getElementsByTagName('IMG');
		for(var i=0;i<_img.length;i++){
			var _x = _img[i].src;
			if(_img[i].src.indexOf('nextbut.gif')>0){
				_img[i].style.display='none';
			}
			if(_img[i].src.indexOf('contbut.gif')>0){
				_img[i].style.display='none';
			}
			if(_img[i].src.indexOf('backbut.gif')>0){
				_img[i].style.display='none';
			}
			if(_img[i].src.indexOf('logotxt.gif')>0){
				_img[i].style.display='none';
			}
		}
	}
	
	this.resizePage=function(){
//		this.nav.style.width='2px';
		this.nav.style.height='2px';
		this.content.style.width='2px';
		this.content.style.height='2px';
		this.fullPage.style.width='2px';
		this.fullPage.style.height='2px';
		this.fullPage.style.height = document.documentElement.clientHeight-0+'px';
		this.fullPage.style.width = document.documentElement.clientWidth-4+'px';
		this.content.style.height = (this.fullPage.offsetHeight-this.header.offsetHeight-(this.paginationTop.offsetHeight+this.paginationBot.offsetHeight)-10)+'px';
		this.nav.style.height = (this.fullPage.offsetHeight-this.header.offsetHeight-(this.navTitle.offsetHeight+this.navFoot.offsetHeight)-8)+'px';
		this.content.style.width=(this.fullPage.offsetWidth-this.nav.offsetWidth-3)+'px';
		if(this.current){
			this.navTo(this.current);
		}
	}
	
	this.clickItem=function(_href){
		var _cur = window.page.document.location.href;
		_cur = _cur.split('#');
		var _link = _href.split('#');
		if(_cur[0]==_link[0]){
			if(_href.length>1){
				//alert(_link[1]);
				report.navTo(_link[1]);
				report.selectPage(_href);
			}
		}else{
			this.loadingShow();
			window.page.document.location.href = _href;
		}
	
	}

	this.checkClick=function(e){
		if(e){
			_source = e.target;
		}else{
			_source = window.event.srcElement;
		}
		
		var _href = window.page.document.location.href;
		_href = _href.split('#');
		var _link;
		switch(_source.tagName){
			case 'A':	if(_source.href=='javascript:void(0)')return;						
						report.showChild(_source.parentNode);
						_link = _source.href.split('#');
						if(_link[0]==_href[0]){
							if(_href.length>1){
								//alert(_link[1]);
								report.navTo(_link[1]);
								report.selectPage(_source.href);
							}
						}else{
							//alert('gabba');
							var _ext = _source.href.split('.');
							if(_ext.length>1){
								switch(_ext[1]){
									case 'pdf':break;
									case 'ppt':break;
									case 'xls':break;
									case 'doc':break;
									default:report.loadingShow();
											window.page.document.location.href = _source.href;
											break;
								}
							}else{
								report.loadingShow();
								window.page.document.location.href = _source.href;
							}
						}
						break;
		}	
	}
	
	this.showChild=function(_node){
		//alert(_node.tagName);
		var _c = _node.childNodes;
		for(var i=0;i<_c.length;i++){
			if(_c[i].tagName=='OL'||_c[i].tagName=='UL'){
				if(_c[i].style.display!='block'){
					_c[i].style.display='block';
				}else{
					_c[i].style.display='none';
				}
			}
		}
	}
	
	this.printPage=function(){
		this.printWin = window.open('../print.html','printWin','width=800,height=600,toolbar,location,menubar,scrollbars');	
	}
	
	this.printPageCreate=function(){
		try{
			var _targ = this.printWin.document;
			var _pc = _targ.getElementById('pageContent');
			if(_pc){
				_pc.innerHTML = this.content.innerHTML;	
				this.printWin.print();
			}
			
		}catch(e){
			this.printPage();
		}
	}

}
report = new REPORT();

function UTIL(){
	this.dE=function(_id){
		return document.getElementById(_id);
	}
	
}
util = new UTIL();

function gabba(){
	report.moveNavBar();
}

function resize(){
	report.resizePage();
}

document.onmousedown=report.checkClick;
//window.onscroll=gabba;
window.onresize=resize;