var TagOldLoad = window.onload;
window.onload=function(){
	if (typeof TagOldLoad == 'function') {TagOldLoad();}
	if (typeof fontStyle == 'undefined') {var fontStyle = 'Verdana, Geneva, sans-serif';}
	if (typeof bgColor == 'undefined') {var bgColor = '#eaf2f8';}
	if (typeof linkColor == 'undefined') {var linkColor = '#6493c2';}
	if (typeof linkColorHover == 'undefined') {var linkColorHover = '#ff6600';}
	if (typeof borderColor == 'undefined') {var borderColor = '#6493c2';}
	var tagList=document.getElementsByTagName("*");
	var kwd,id, m;
	var id_pattern = new RegExp('(^|\\\\s)rcsb_id_tag(\\\\s|$)');
	var author_pattern = new RegExp('(^|\\\\s)rcsb_author_tag(\\\\s|$)');
	var kwd_pattern = new RegExp('(^|\\\\s)rcsb_keyword_tag(\\\\s|$)');
	var menu_pattern = new RegExp('(^|\\\\s)rcsb_menu_tag(\\\\s|$)');
	var localmol_pattern = new RegExp('(^|\\\\s)rcsb_mol_tag(\\\\s|$)');

        var localdef_pattern = new RegExp('(^|\\\\s)rcsb_def_tag(\\\\s|$)');
	if ( tagList.length > 0) {
		for (i = 0, j = 0; i < tagList.length; i++) {
			if ( ( id_pattern.test(tagList[i].className) ) || ( kwd_pattern.test(tagList[i].className) ) || ( menu_pattern.test(tagList[i].className) ) || ( author_pattern.test(tagList[i].className) ) ) {
				tagList[i].style.display = 'inline-block';
				tagList[i].style.borderBottom = '1px dotted ' + borderColor;
				tagList[i].style.cursor = 'pointer';
			}
			if ( id_pattern.test(tagList[i].className) ) {
				tagList[i].onclick = function(){
					var id = this.getAttribute('rel');
					if (id == null) {
						id = this.innerHTML.replace(/^\s+|\s+$/g,"");
					}
					window.open("http://www.rcsb.org/pdb/search/navbarsearch.do?newSearch=yes&isAuthorSearch=no&radioset=All&sgProjectSelect=&inputQuickSearch="+id+"&image=Search");
				}
				tagList[i].onmouseover = function() {
					var id = this.getAttribute('rel');
					if (id == null) {
						id = this.innerHTML.replace(/^\s+|\s+$/g,"");
					}
					var title = this.getAttribute('title');
					if ( title == null ) {
						title ="";
					} else {
						title = title + "<br />";
					}
					tooltip.show("<img src='http://www.rcsb.org/pdb/images/"+id+"_bio_r_250.jpg' /><h2 style='margin:0;padding:0;'>"+id+"</h2>"+title+"(click for structure explorer page)", borderColor, bgColor, fontStyle);
				}
				tagList[i].onmouseout = function() {
					tooltip.hide();
				}
			}
			
			
			
			
if ( ( localmol_pattern.test(tagList[i].className) ) || ( kwd_pattern.test(tagList[i].className) ) || ( menu_pattern.test(tagList[i].className) ) || ( author_pattern.test(tagList[i].className) ) ) {
				tagList[i].style.display = 'inline-block';
				tagList[i].style.borderBottom = '1px dotted ' + borderColor;
				tagList[i].style.cursor = 'pointer';
			}
			
			


			if ( localmol_pattern.test(tagList[i].className) ) {
				tagList[i].onclick = function(){
					var id = this.getAttribute('rel');
					if (id == null) {
						id = this.innerHTML.replace(/^\s+|\s+$/g,"");
					}
					window.open("molecules/"+ id + ".pdb");
				}
				tagList[i].onmouseover = function() {
					var id = this.getAttribute('rel');
					if (id == null) {
						id = this.innerHTML.replace(/^\s+|\s+$/g,"");
					}
					var title = this.getAttribute('title');
					if ( title == null ) {
						title ="";
					} else {
						title = title + "<br />";
					}
					tooltip.show("<img src='molecules/"+id+".jpg' /><h2 style='margin:0;padding:0;'>"+id+"</h2>"+title+"(click for structure explorer page)", borderColor, bgColor, fontStyle);
				}
				tagList[i].onmouseout = function() {
					tooltip.hide();
				}
			}

                          if ( ( localdef_pattern.test(tagList[i].className) ) || ( kwd_pattern.test(tagList[i].className) ) || ( menu_pattern.test(tagList[i].className) ) || ( author_pattern.test(tagList[i].className) ) ) {
				tagList[i].style.display = 'inline-block';
				tagList[i].style.borderBottom = '1px dotted ' + borderColor;
				tagList[i].style.cursor = 'pointer';
			}
                        
                        			if ( localdef_pattern.test(tagList[i].className) ) {
				tagList[i].onclick = function(){
					var id = this.getAttribute('rel');
					if (id == null) {
						id = this.innerHTML.replace(/^\s+|\s+$/g,"");
					}
					window.open("words/"+ id + ".htm");
				}
				tagList[i].onmouseover = function() {
					var id = this.getAttribute('rel');
					if (id == null) {
						id = this.innerHTML.replace(/^\s+|\s+$/g,"");
					}
					var title = this.getAttribute('title');
					if ( title == null ) {
						title ="";
					} else {
						title = title + "<br />";
					}
					tooltip.show("<IFRAME src='words/"+id+".htm?tt=yes' /></iframe>", borderColor, bgColor, fontStyle);
				}
				tagList[i].onmouseout = function() {
					tooltip.hide();
				}
			}



			if ( kwd_pattern.test(tagList[i].className) ) {
				tagList[i].onclick = function(){
					var id = this.getAttribute('rel');
					if (id == null) {
						id = this.innerHTML.replace(/^\s+|\s+$/g,"");
					}
					window.open("http://www.rcsb.org/pdb/search/navbarsearch.do?newSearch=yes&isAuthorSearch=no&radioset=All&sgProjectSelect=&inputQuickSearch="+id+"&image=Search");
				}
				tagList[i].onmouseover = function(e) {
					var id = this.getAttribute('rel');
					if (id == null) {
						id = this.innerHTML.replace(/^\s+|\s+$/g,"");
					}
					tooltip.show("RCSB PDB Keyword Search for: " + id, borderColor, bgColor, fontStyle);
				}
				tagList[i].onmouseout = function() {
					tooltip.hide();
				}
			}
			if ( author_pattern.test(tagList[i].className) ) {
				tagList[i].onclick = function(){
					var auth = this.getAttribute('rel');
					if (auth == null) {
						auth = this.innerHTML.replace(/\s+/,"+");
					}
					auth = auth.replace(/\s+/,"+");
					auth = auth.replace(",", "%2C")
					window.open("http://www.rcsb.org/pdb/search/navbarsearch.do?newSearch=yes&exactMatch=y&isAuthorSearch=yes&radioset=Authors&sgProjectSelect=&inputQuickSearch="+auth+"&image=Search ");
				}
				tagList[i].onmouseover = function(e) {
					var auth = this.getAttribute('rel');
					if (auth == null) {
						auth = this.innerHTML
					}
					tooltip.show("RCSB PDB Exact Author Search for: " + auth, borderColor, bgColor, fontStyle);
				}
				tagList[i].onmouseout = function() {
					tooltip.hide();
				}
			}
			if ( menu_pattern.test(tagList[i].className) ) {
				tagList[i].style.position = 'relative';
				tagList[i].style.background = 'url(http://www.rcsb.org/pdb/skins/web20/default/images/downArrow.png) right no-repeat';
				tagList[i].style.paddingRight = '10px';
				if (tagList[i].getAttribute('rel') == null) {
					tagList[i].appendChild(rcsb_menu.create(tagList[i].innerHTML, i, borderColor, bgColor, fontStyle, linkColor, linkColorHover));
				} else {
					tagList[i].appendChild(rcsb_menu.create(tagList[i].getAttribute('rel'), i, borderColor, bgColor, fontStyle, linkColor, linkColorHover));
				}
				tagList[i].onmouseover = function() {
					var float = 'left';
					var screen = getScreenSize();
					var ePos = this.offsetLeft;
					if ( ePos > (screen[0] - 180)) {
						float = 'right';
					}
					if (float == 'left') {
						this.getElementsByTagName("div")[0].style.left = '0px';
						this.getElementsByTagName("div")[0].style.right = '';
					} else {
						this.getElementsByTagName("div")[0].style.left = '';
						this.getElementsByTagName("div")[0].style.right = '0px';
					}
					this.getElementsByTagName("div")[0].style.display = 'block';
				}
				tagList[i].onmouseout = function() {
					this.getElementsByTagName("div")[0].style.display = 'none';
				}
			}
		}
	}
}

var rcsb_menu=function(){
	return {
		create:function(mid, id, bc, bgc, fs, lc, lch) {
			var p = document.createElement('div');
			p.setAttribute('id',id+'_div');
			p.style.top = '100%';
			p.style.width = '175px';
			p.style.display = 'none';
			p.style.position = 'absolute';
			p.style.zIndex = '10000';
			p.style.padding = '2px';
			p.style.border = '1px solid ' + bc;
			p.style.backgroundColor = bgc;
			p.style.textAlign = 'left';
			p.style.fontFamily = fs;
			p.style.fontSize = '12px';
			p.style.fontStyle = 'normal';
			p.style.fontWeight = 'normal';
			p.style.lineHeight = '1.5';
			p.style.letterSpacing = '0pt';
			var v = document.createElement('a');
			v.href = "http://www.rcsb.org/pdb/explore/jmol.do?structureId="+mid;
			v.target = '_blank';
			v.innerHTML = 'View in 3D';
			v.style.color = lc;
			v.style.textDecoration = 'none';
			v.onmouseover = function() {
				v.style.color = lch;
			}
			v.onmouseout = function() {
				v.style.color = lc;
			}
			var exp = document.createElement('a');
			exp.href = "http://www.rcsb.org/pdb/explore/explore.do?structureId="+mid;
			exp.target = '_blank';
			exp.innerHTML = 'View Structure Summary';
			exp.style.color = lc;
			exp.style.textDecoration = 'none';
			exp.onmouseover = function() {
				exp.style.color = lch;
			}
			exp.onmouseout = function() {
				exp.style.color = lc;
			}
			var disp = document.createElement('a');
			disp.href = "http://www.rcsb.org/pdb/files/"+mid+".pdb";
			disp.target = '_blank';
			disp.innerHTML = 'Display PDB File';
			disp.style.color = lc;
			disp.style.textDecoration = 'none';
			disp.onmouseover = function() {
				disp.style.color = lch;
			}
			disp.onmouseout = function() {
				disp.style.color = lc;
			}
			var dl = document.createElement('a');
			dl.href = "http://www.rcsb.org/pdb/files/"+mid+".pdb.gz";
			dl.innerHTML = 'Download PDB File (gz)';
			dl.style.color = lc;
			dl.style.textDecoration = 'none';
			dl.onmouseover = function() {
				dl.style.color = lch;
			}
			dl.onmouseout = function() {
				dl.style.color = lc;
			}
			var brk1 = document.createElement('br');
			var brk2 = document.createElement('br');
			var brk3 = document.createElement('br');
			p.appendChild(v);
			p.appendChild(brk1);
			p.appendChild(exp);
			p.appendChild(brk2);
			p.appendChild(disp);
			p.appendChild(brk3);
			p.appendChild(dl);
			return p;
		}
	};
}();

var tooltip=function(){
	var id = 'rcsb_tt'; var top = 3; var left = 10; var speed = 20; var timer = 20; var endalpha = 100; var alpha = 0; var tt,c,h,w; var ie = document.all ? true : false;
	return{
		show:function(v, bc, bgc, fs, w){
			if(tt == null){
				tt = document.createElement('div');
				tt.setAttribute('id',id);
				c = document.createElement('div');
				c.setAttribute('id',id + 'cont');
				c.style.position = 'static';
				c.style.border = '1px solid ' + bc;
				c.style.backgroundColor = bgc;
				c.style.fontFamily = fs;
				c.style.fontSize = '12px';
				c.style.lineHeight = '1.5em';
				c.style.textAlign = 'center';
				c.style.padding = '2px';
				c.style.maxWidth = '260px';
				tt.appendChild(c);
				document.body.appendChild(tt);
				tt.style.position = 'absolute';
				tt.style.opacity = 0;
				tt.style.filter = 'alpha(opacity=0)';
				document.onmousemove = this.pos;
			}
			tt.style.display = 'block';
			c.innerHTML = v;
			tt.style.width = 'auto';
			clearInterval(tt.timer);
			tt.timer = setInterval(function(){tooltip.fade(1)},timer);
		},
		pos:function(e){
			var u = 0;
			var l = 0;
			var screen = getScreenSize();
			var offset = getScreenPosition();
			u = ie ? event.clientY + offset[1] : e.pageY;
			l = ie ? event.clientX + offset[0] : e.pageX;
			var isIE6 = navigator.userAgent.toLowerCase().indexOf('msie 6') != -1;
			if ( (u - offset[1]) >= (screen[1]/3) * 2 ) {
				tt.style.top = '';
				tt.style.bottom = (screen[1] - u) - 10 + 'px';
			} else {
				tt.style.top = u + 'px';
				tt.style.bottom = '';
			}
			if (isIE6) {
				tt.style.top = u + 'px';
				tt.style.bottom = '';
			}
			if ( (l - offset[0]) > screen[0]/2 ) {
				tt.style.left = '';
				tt.style.right = ((screen[0] - l) + 3) + 'px';
			} else {
				tt.style.right = '';
				tt.style.left = (l + left) + 'px';
			}
		},
		fade:function(d){
			var a = alpha;
			if((a != endalpha && d == 1) || (a != 0 && d == -1)){
				var i = speed;
				if(endalpha - a < speed && d == 1){
					i = endalpha - a;
				}else if(alpha < speed && d == -1){
					i = a;
				}
				alpha = a + (i * d);
				tt.style.opacity = alpha * .01;
				tt.style.filter = 'alpha(opacity=' + alpha + ')';
			}else{
				clearInterval(tt.timer);
				if(d == -1){
					tt.style.display = 'none'
				}
			}
		},
		hide:function(){
			clearInterval(tt.timer);
			tt.style.display = 'none';
		}
	};
}();

function getScreenSize() {
	var sw = 0, sh = 0; 
	if (typeof window.innerWidth != 'undefined') {
		// the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
		sw = window.innerWidth;
		sh = window.innerHeight;
	} else if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth != 0) {
		// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
		sw = document.documentElement.clientWidth;
		sh = document.documentElement.clientHeight;
	} else {
		// older versions of IE
		sw = document.getElementsByTagName('body')[0].clientWidth;
		sh = document.getElementsByTagName('body')[0].clientHeight;
	}
	return [ sw, sh ];
}

function getScreenPosition() {
	var px=0,py=0;
	if (self.pageYOffset) {
		// all except Explorer
		px = self.pageXOffset;
		py = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop) {
		// Explorer 6 Strict
		px = document.documentElement.scrollLeft;
		py = document.documentElement.scrollTop;
	} else if (document.body) {
		// all other Explorers
		px = document.body.scrollLeft;
		py = document.body.scrollTop;
	}
	return [ px, py ];
}

