/**
 * Author: Moacir L. Ferreira Jr.
 */

var browserIE = (window.navigator.userAgent.indexOf("MSIE")!=-1 || window.document.all)?true:false;

var urlPathBase = window.document.location.href;
var index;
if((index=urlPathBase.lastIndexOf('/'))!=-1){
	urlPathBase = urlPathBase.substring(0, index);
}
urlPathBase+='/';

var theme = 'scripts/popcalendar'; //calendar

self.arrayImages=[];
self.arrayWins=[];
var suffixes = ['_bw.png','_cl.png'];

var getImage= function(imgName){
	var arrayImages = self.arrayImages?self.arrayImages:self.opener.arrayImages;
	var image = arrayImages[imgName];
	if(!image){
		alert('Image not found: '+imgName);
	}
	if(image.src2 && image.src2!=image.src){
		image.src = image.src2; //lazy loading
	}
	return image;
}

var changeBW = function(img){
	if(!img || !img.src){
		img = this;
	}
	var imgName = img.src.substring(img.src.lastIndexOf('/')+1);
	if(imgName.indexOf('_cl.')!=-1){
		img.src = getImage(imgName.replace(/_cl\./,'_bw.')).src;
	}else
	if(imgName.indexOf('_bw.')!=-1){
		img.src = getImage(imgName.replace(/_bw\./,'_cl.')).src;
	}
}

var showImage = function(code){
	var imgName;
	if(code && typeof(code)=='string'){
		imgName = 'fig_'+code+suffixes[1];
	}else{
		imgName = this.src.substring(this.src.lastIndexOf('/')+1);
	}
	var image = getImage(imgName);
	var imgWidth = image.width;
	var imgHeight = image.height;
	var offsetWidth = 38;
	var offsetHeight = 110;
	var width = imgWidth + offsetWidth;
	var height = imgHeight + offsetHeight;
	var ratio = width / height;
	if(screen.width < width){
		width = screen.width;
		height = Math.round(width / ratio);
		imgWidth = width - offsetWidth;
		imgHeight = Math.round(imgWidth / ratio);
	}
	if(screen.height < height){
		height = screen.height;
		width = Math.round(height * ratio);
		imgHeight = height - offsetHeight;
		imgWidth = Math.round(imgHeight * ratio);
	}
	var title = imgName.substring(0, imgName.lastIndexOf('_')).toUpperCase().replace(/_/,'. ');
	var top = ((screen.height-height)/2);
	var left = ((screen.width-width)/2);
	var winName = title.replace(/[ _\.]/g,'');
	var win = self.arrayWins[winName];
	if(browserIE && win && !win.closed){
		win.close();
	}
	win = self.open('about:blank', winName,
                    'scrollbars=Yes,menubar=0,location=0,'+
                    'resizable=Yes,toolbar=0,status=0,'+
                    'width='+width+',height='+height+','+
                    'top='+top+','+
                    'left='+left);
	if(browserIE){
		self.arrayWins[winName] = win;
	}
	var html = '<html><head><title>'+title+'</title></head><body><img src="'+image.src+'" width="'+imgWidth+'" height="'+imgHeight+'" onclick="self.opener.changeBW(this)" ondblclick="self.close();" style="cursor: pointer; cursor: hand;"><script>self.document.images[0].src=opener.getImage("'+imgName+'").src</script></body></html>';
	win.document.open('text/html', 'replace');
    win.document.write(html);
	win.document.close();
	win.focus();
	return false;
}


function showLink(link, width, height, hideLocationToolBar){
	width  = (width ?width :640);
	height = (height?height:480);
	var ltb = hideLocationToolBar?0:1;

	var top = ((screen.height-height)/2);
	var left = ((screen.width-width)/2);
	var win = self.open(link, 'showLink',
                    'scrollbars=Yes,menubar=0,location='+ltb+',toolbar='+ltb+','+
                    'resizable=Yes,status=0,'+
                    'width='+width+',height='+height+','+
                    'top='+top+','+
                    'left='+left);
	win.focus();
}

var arrayVideos=[];
//YouTube
arrayVideos['01_ytb']='XLt7PBEkuZI';
arrayVideos['02_ytb']='WKJ3aG37UZs';
arrayVideos['03_ytb']='FV4n4r9PxS4';
arrayVideos['04_ytb']='YXLshYYsK8I';
arrayVideos['05_ytb']='oqHFowOge_M';
arrayVideos['06_ytb']='9ScAHXN_kAY'; //'15kg-GU-gE4'
//Google
arrayVideos['05_ggl']='-6885121142086326496';

var writeVideo = function(id, width, height, document, autoplay){
	var tmp;
	if((tmp = arrayVideos[id+'_ytb'])){
		id = tmp;
	}else if((tmp = arrayVideos[id+'_ggl'])){
		id = tmp;
	}
	autoplay = autoplay?true:false;
	
	//if(!autoplay && cookieGet("autoplayed")!="true"){
	//	cookieSet("autoplayed", "true");
	//	autoplay = true;
	//}
	
	if(!document){
		document = window.document;
	}
	width  = (width ?width :600);	//width="480" height="385"
	height = (height?height:485);	//&amp;hl=en&amp;fs=1&amp;ap=%2526fmt%3D18
	var html = '<object width="'+width+'" height="'+height+'">\n'+
			   '  <param name="movie" value="http://www.youtube.com/v/'+id +'&ap=%2526fmt%3D18&hl=en&rel=0&fs=1'+(autoplay?'&autoplay=1':'')+'">\n'+ 
			   '  <param name="allowFullscreen" value="true">\n'+
			   '  <param name="AllowScriptAccess" value="always">\n'+
			   '  <param name="wmode" value="transparent"></param>\n'+
			   ' <embed src="http://www.youtube.com/v/'+id +(!browserIE?'&ap=%2526fmt%3D18':'')+'&hl=en&rel=0&fs=1'+(autoplay?'&autoplay=1':'')+'" \n'+ 
			   '        type="application/x-shockwave-flash" \n'+
			   '        allowFullscreen="true"\n'+
			   '        AllowScriptAccess="always"\n'+
			   '        wmode="transparent"\n'+
			   '        width="'+width+'" height="'+height+'">\n'+
			   '</object>\n';	
	
	document.writeln(html);
	//alert(html);
	//'<embed id="VideoPlayback" type="application/x-shockwave-flash"\n'+ 
	//'	    src="http://video.google.com/googleplayer.swf?docid=-6885121142086326496&amp;hl=en&amp;fs=true"\n'+
	//'     style="width: 600px; height: 476px;" allowfullscreen="true" allowscriptaccess="always">\n' 
}

var showVideo = function(id, width, height){
	width  = (width ?width :600);  //width="480" height="385"
	height = (height?height:485);
	var tmp;
	if((tmp = arrayVideos[id+'_ytb'])){
		id = tmp;
	}else if((tmp = arrayVideos[id+'_ggl'])){
		id = tmp;
	}
	var offsetWidth = 40;
	var offsetHeight = 40;
	var winWidth = width + offsetWidth;
	var winHeight = height + offsetHeight;
	var ratio = width / height;
	if(screen.width < winWidth){
		winWidth = screen.width;
		winHeight = Math.round(winWidth / ratio);
		width = winWidth - offsetWidth;
		height = Math.round(width / ratio);
	}
	if(screen.height < winHeight){
		winHeight = screen.height;
		winWidth = Math.round(winHeight * ratio);
		height = winHeight - offsetHeight;
		width = Math.round(height * ratio);
	}
	var top = ((screen.height-winHeight)/2);
	var left = ((screen.width-winWidth)/2);
	var winName = id.replace(/[^a-zA-Z0-9]/g,'');
	var win = self.arrayWins[winName];
	if(browserIE && win && !win.closed){
		win.close();
	}
	win = self.open('about:blank', winName,
                    'scrollbars=Yes,menubar=0,location=0,'+
                    'resizable=Yes,toolbar=0,status=0,'+
                    'width='+winWidth+',height='+winHeight+','+
                    'top='+top+','+
                    'left='+left);
	if(browserIE){
		self.arrayWins[winName] = win;
	}
	win.document.open('text/html', 'replace');
    win.document.write('<html><head><title>'+id+'</title></head><body><center>');
	writeVideo(id, width, height, win.document, true);
    win.document.write('</center></body></html>');
	win.document.close();
	win.focus();
	return false;
}

function getDocument(source){
	return source.contentDocument?source.contentDocument:(source.document?source.document:source.ownerDocument);
}

function getElement(source, id){
	return getDocument(source).getElementById(id);
}

function getForm(frame){
	var form = frame.document.forms['FORM'];
	if(!form){
		frame.alert('form "FORM" not found!');
	}
	return form;
}

function getField(frame, fieldName){
	var form = getForm(frame);
	var field = eval('form.elements["'+fieldName+'"]');
	if(!field){
		alert('Field "'+fieldName+'" not found!');
	}
	return field;
} 

function clearSearch(frame){
	var elements = getForm(frame).elements;
	for(var i=0; i<elements.length; i++){
		var field = elements[i];
		if(field && typeof(field)=='object' && (field.type || field.length)){
			var type = (field.length && !field.options?field[0]:field).type.toLowerCase();
			if(canHaveFocus(field.length && !field.options?field[0]:field)){
				if(type=='checkbox' || type=='radio'){
					fieldCheckAll(field, false);
				}else if(field.options){
					field.selectedIndex = -1;
					fieldSelectAll(field, false);
				}else {
					field.value = '';
				}
			}else if(type=='hidden'){
				var display = getElement(frame, 'popUpDisplay_'+field.name);
				if(display){
					field.value = '';
					display.innerHTML = 'search...';
				}
			}
		}
	}
}

function canHaveFocus(field){
	return !field.disabled && !field.readOnly && field.style && field.style.display!='none' && 
			field.style.visibility!='hidden' && field.type && field.type.toLowerCase()!='hidden';
}

function focusSafe(field){
	try{
		field.focus();
	}catch(e){
	}
}

function fieldCheckAll(field, bool){
	if(!field.length){
		field.checked = bool;	
		return;
	}
    for (var i = field.length-1; i>=0; i--){
		field[i].checked = bool;
    }
}

function fieldSelectAll(field, bool){
    for (var i = field.options.length-1; i>=0; i--){
    	if(field.options[i]){
			field.options[i].selected = bool;
		}
    }
}

function formatDonation(field, event){
	var keyCode = event.keyCode?event.keyCode:event.which;
	if ( ( (keyCode < 48 || keyCode > 57 || (keyCode==48 && field.value.length==0)) && keyCode!=45 && keyCode!=8 && keyCode!=37 && keyCode!=39 && keyCode!=46) ){
		return false;
	}
	return true;
}

var trimEnds = function(string){
	return string.replace(/^([ \n\r\t]+)/,'').replace(/([ \n\r\t]+)$/,'');
}


/**
 *    <<< Cookies >>>
 */
var cookieExpiresDays = 730; // <-02 years
var cookieExpiresTime = new Date(new Date().getTime() + (cookieExpiresDays * 24 * 60 * 60 * 1000));

var cookieGet = function(name) {
	var arg = name + "=";
	var alen = arg.length;
	var clen = this.document.cookie.length;
	var i = 0;
	while (i < clen) {
		var j = i + alen;
		if (this.document.cookie.substring(i, j) == arg)
			return this.cookieGetVal(j);
		i = this.document.cookie.indexOf(" ", i) + 1;
		if (i == 0)
			break;
	}
	return null;
}

var cookieSet = function(name, value) {
	var argv = cookieSet.arguments;
	var argc = cookieSet.arguments.length;
	var expires = (argc > 2) ? argv[2] : cookieExpiresTime;
	var path = (argc > 3) ? argv[3] : null;
	var domain = (argc > 4) ? argv[4] : null;
	var secure = (argc > 5) ? argv[5] : false;
	this.document.cookie =
		name
			+ "="
			+ escape(value)
			+ ((expires == null) ? "" : ("; expires=" + expires.toGMTString()))
			+ ((path == null) ? "" : ("; path=" + path))
			+ ((domain == null) ? "" : ("; domain=" + domain))
			+ ((secure == true) ? "; secure" : "");
}

var cookieDelete = function(name) {
	var exp = new Date();
	exp.setTime(exp.getTime() - 1);
	var cval = cookieGet(name);
	this.document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}

var cookieGetVal = function(offset) {
	var endstr = this.document.cookie.indexOf(";", offset);
	if (endstr == -1)
		endstr = this.document.cookie.length;
	return unescape(this.document.cookie.substring(offset, endstr));
}

function copyHtmlToTextArea(index){
	var html = window.document.getElementById('html'+index).innerHTML;
	html = trimEnds(html).replace(/[\n\r]/g, '').replace(/ +/g, ' ');
	html = html.replace(/(="images\/)([^"])/gi,'="'+urlPathBase+'images/$2');
	var textarea = window.document.getElementById('textarea'+index);
	if(browserIE){
		textarea.innerText = html;
	}else{
		textarea.innerHTML = html;
	}
}

limitTextArea = function(textArea, maxLength){
    if(maxLength!=-1 && textArea.value.length>maxLength){
		textArea.value =  textArea.value.substring(0, maxLength);
		alert('Limit of '+maxLength+' characters exceeded!');
    	return false;
    }
	return true;
}  

function submitDonation(form){
	var fieldNotifyUrl = form['notify_url'];
	if(fieldNotifyUrl.value.indexOf(urlPathBase)==-1){
		fieldNotifyUrl.value = urlPathBase + fieldNotifyUrl.value;
	}
	var fieldReturn = form['return'];
	if(fieldReturn.value.indexOf(urlPathBase)==-1){
		fieldReturn.value = urlPathBase + fieldReturn.value;
	}
	var fieldCancel = form['cancel_return'];
	if(fieldCancel.value.indexOf(urlPathBase)==-1){
		fieldCancel.value = urlPathBase + fieldCancel.value;
	}

	if(!parseInt(form.amount.value)){
		alert('Please Enter an Amount.');
		return false;
	}
	var flags = (form.listName.checked?1:0) | (form.listComment.checked?2:0) | (form.listAmount.checked?4:0);
	form.custom.value = form.comment.value + flags;

	//alert('fieldNotifyUrl='+fieldNotifyUrl.value+'\nfieldReturn='+fieldReturn.value+'\nfieldCancel='+fieldCancel.value
	//		+'\n\ncomment:\n'+form.custom.value
	//		+'\n\nflags='+flags);
        
	return true;
}

function showDonations(){
	showLink('donations.php',false,false,true);
	return false;
}

var updatePage = function(){
	var links = window.document.links;
	for(var i=0; i<links.length; i++){
		var link = links[i];
		if(link.target=="showLink" && !link.onclick){
			link.onclick = new Function("showLink('" + link.href.replace(/'/,"\\'") + "')");
		}
	}
}

var lazyLoadImage = true;
var notSoLazy = true;

var loadImages = function(){
	var images = window.document.images;
	if(images && images.length!=0){
		var arrayTmp = [];
		for(var i=0; i<images.length; i++){
			var image = images[i];
			if(image.src.indexOf('_bw.')!=-1 || image.src.indexOf('_cl.')!=-1){
				if(!image.onclick){
					image.onclick = changeBW;
					image.style.cursor = browserIE?'hand':'pointer';
				}
				if(!image.ondblclick){
					image.ondblclick = showImage;
				}
				var imgName = image.src;
				imgName = imgName.substring(imgName.lastIndexOf('/')+1);
				arrayTmp[imgName] = image;
				if(notSoLazy){
					var bw = image.src.indexOf('_bw.')!=-1;
					imgName = image.src.replace((bw?'_bw.':'_cl.'),(bw?'_cl.':'_bw.'));
					var image = new Image();
					image.src = imgName;
					imgName = imgName.substring(imgName.lastIndexOf('/')+1);
					arrayTmp[imgName] = image;
				}
			}
		}

		var pathImages = images[0].src.substring(0, images[0].src.lastIndexOf('/'));
		var thruster = (window.document.location.href.indexOf('thruster')!=-1);
		var codes;
		if(!thruster){
			codes= ['01','02','03','04','05','06','07','08','9A','9B','10','11','12','13','14','15','15_fusion_reactor','9B_fusion_reactor','03_fusion_reactor'];
		}else{
			codes= ['01_thruster','02_thruster','03_thruster','04_thruster','05_thruster','06_thruster','07_thruster','08_thruster','01_impulse_drive','03_array_impulse_drives','06_linear_thruster_single_loop'];
		}
		for(var i=0; i<codes.length; i++){
			for(var j=0; j<suffixes.length; j++){
				var image = new Image();
				image.src2 = pathImages+'/fig_'+codes[i]+suffixes[j];
				var imgName = image.src2;
				imgName = imgName.substring(imgName.lastIndexOf('/')+1);
				var imgTmp = arrayTmp[imgName];
				if(imgTmp){
					image.src = imgTmp.src; 
				}else if(!lazyLoadImage){
					image.src = image.src2;//force loading...
				}
				if(!self.arrayImages[imgName]){
					self.arrayImages[imgName] = image;
				}
			}
		}
		loadMyPhotos(true);
	}
	updatePage();
}

function loadMyPhotos(lazyLoadImage){
	var images = window.document.images
	var pathImages = images[0].src.substring(0, images[0].src.lastIndexOf('/'));
	for(var i=0; i<3; i++){
		var image = new Image();
		image.src2 = pathImages+'/myphoto0'+(i+1)+'_sm2.png';
		var imgName = image.src2;
		imgName = imgName.substring(imgName.lastIndexOf('/')+1);
		if(!lazyLoadImage){
			image.src = image.src2;//force loading...
		}
		if(!self.arrayImages[imgName]){
			self.arrayImages[imgName] = image;
		}
	}
}

function myPhoto(){
	document.writeln('<img alt=\"Moacir L. Ferreira Jr. Inventor of CrossFire Fusor\" '+
		              'src=\"../images/myphoto02_sm2.png\" '+
		              'style=\"border: 1px solid ; margin: 0px 0px 4px 8px; cursor: pointer; width: 112px; height: 112px; float: right;\" '+
		              'title=\"Moacir L. Ferreira Jr. Inventor of CrossFire Fusor\" '+
		              'onclick=\"clickPhoto(this);\">');
	loadMyPhotos(false);
}

function clickPhoto(image){
	if(!image.photoIndex){
		image.photoIndex=2;
	}
	image.photoIndex=(++image.photoIndex%3)+1;
	var imgName =image.src.replace(/(myphoto0)(\d)/,'$1'+image.photoIndex);
	imgName = imgName.substring(imgName.lastIndexOf('/')+1);
	image.src=self.getImage(imgName).src
}

function writeHeader(){
	document.writeln('  <table width="100%" border="0" cellpadding="1" cellspacing="0"  style="color:midnightblue;">');
	document.writeln('   <tr>');
	document.writeln('    <td width="1%" rowspan="2">');
	document.writeln('     <img title="FIG. 9B - Core" style="width:114px;height:120px; border: 0px solid;" alt="FIG. 9B - Core" src="../images/fig_9B_fusion_reactor_cl.png">');
	document.writeln('    </td>');
	document.writeln('    <td valign="middle" align="center" style="font-size:200%">');
	document.writeln('     CrossFire Fusion Reactor');
	//document.writeln('     <br>');
	//document.writeln('     <span style="font-size:70%">Aneutronic Nuclear Fusion Reactor</span>');
	document.writeln('    </td>');
	document.writeln('    <td width="1%" rowspan="2">');
	document.writeln('     <img title="FIG. 15 - Power Plant" style="width:140px;height:120px; border: 0px solid;" alt="FIG. 15 - Power Plant" src="../images/fig_15_fusion_reactor_cl.png">');
	document.writeln('    </td>');
	document.writeln('   </tr>');
	document.writeln('   <tr> ');
	document.writeln('    <td valign="middle" align="center">');
	document.writeln('     <span style="font-size:60%;">MAGNETIC AND ELECTROSTATIC NUCLEAR FUSION REACTOR</span>');
	document.writeln('     <br>');
	document.writeln('     <a href="http://en.wikipedia.org/wiki/Patent_pending" target="showLink" style="font-size:70%; font-weight:bold; color:crimson; font-style:italic;">Patent Pending</a>');
	document.writeln('     <span style="font-size:60%; color:black">PCT/IB2008/054254</span>');
	document.writeln('    </td>');
	document.writeln('   </tr>');
	document.writeln('   <tr>');
	document.writeln('    <td colspan="3">');
	document.writeln('     <hr style="color:darkblue; background-color:darkblue; height:2px;">');
	document.writeln('    </td>');
	document.writeln('   </tr> ');
	document.writeln('  </table>');
}

var arrayContents = [
						['overview.html'            ,'Overview'               ],
						['background.html'          ,'Background'             ],
						['history.html'             ,'History'                ],
						['summary.html'             ,'Summary'                ],
						['detailed_description.html','Detailed Description'   ],
						['operation_invention.html' ,'Operation of Invention' ],
						['power_plant.html'         ,'Power Plant for Testing'],
						['calculations.html'        ,'Calculations'           ],
						['videos.html'              ,'Videos'                 ],
						['related_links.html'       ,'Related Links'          ],
						['support_project.html'     ,'Support Project'        ]
					];

function writeContents(){
	document.writeln('  <table style="border: 1px solid rgb(204, 204, 204); font-size: 95%; background-color: rgb(249, 249, 249); width: 1%; float:right; margin: 30px 0px 30px 30px;" cellpadding="1" cellspacing="0">');
	document.writeln('   <tr>');
	document.writeln('    <td colspan="2" style="font-weight: bold; text-align: center; font-size: 95%;">Contents</td>');
	document.writeln('   </tr>');

	for(var i=0; i<arrayContents.length; i++){
		if(i==(arrayContents.length-1)){
			document.writeln('   <tr><td colspan="2" style="font-size: 30%;">&nbsp;</td></tr>');
		}
		document.writeln('   <tr>');
		document.writeln('    <td style="font-size: 95%;" align="right">'+((i==10)?'&nbsp;':(i+1)+'.')+'</td>');
		document.writeln('    <td style="font-size: 95%;" nowrap="nowrap"><a href="'+arrayContents[i][0]+'">'+arrayContents[i][1]+'</a></td>');
		document.writeln('   </tr>');
	}
	document.writeln('  </table>');
}

function writeNavigation(index){
    index-=1;
	document.writeln('  <table width="100%">');
	document.writeln('   <tr>');
	document.writeln('    <td align="right" nowrap>');
	if((index-1)>=0){
		document.writeln('     <span style="font-size:70%; vertical-align:middle;">Previous:&nbsp;</span><a href="'+arrayContents[index-1][0]+'">'+arrayContents[index-1][1]+'</a>');
		document.writeln('     &nbsp;&nbsp;&nbsp;&nbsp;');
	}
	if((index+1)<arrayContents.length){
		document.writeln('     <span style="font-size:70%; vertical-align:middle;">Next:&nbsp;</span><a href="'+arrayContents[index+1][0]+'">'+arrayContents[index+1][1]+'</a>');
	}
	document.writeln('    </td>');
	document.writeln('   </tr>');
	document.writeln('  </table> ');
}

function writeFooter(){
	document.writeln('  <br>');
	document.writeln('  <hr style="color:darkblue; background-color:darkblue; height:2px;">');
	document.writeln('  <input style="float:left" alt=\"PayPal - The safer, easier way to pay online\" name=\"submit\" src=\"http://www.paypal.com/en_US/i/btn/x-click-but21.gif\" onclick=\"window.open(\'donate.html\');\" title=\"PayPal - The safer, easier way to pay online\" type=\"image\">');
	document.writeln('  <div style="text-align: right;font-size:80%">');
	document.writeln('   <a href="faq.html" target="showLink">FAQ</a>');
	document.writeln('   &nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;');
	document.writeln('   <a href="privacy_policy.html" target="showLink" rel="noindex,nofollow">Privacy Policy</a>');
	document.writeln('   &nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;');
	document.writeln('   <a href="&#109;&#097;&#105;&#108;&#116;&#111;:&#112;&#114;&#111;&#106;&#101;&#099;&#116;&#064;&#099;&#114;&#111;&#115;&#115;&#102;&#105;&#114;&#101;&#102;&#117;&#115;&#105;&#111;&#110;&#046;&#099;&#111;&#109;">Contact Us</a>');
	document.writeln('  </div>');
	document.writeln('  <br>');
	document.writeln('  <br>');
	document.writeln('  <br>');
}

function showReference(ref, idReferences){
	ref.style.textDecoration = 'underline';
	if(!ref.onmouseout){
		ref.onmouseout = function(){
			this.style.textDecoration = 'none';
		}
	}
	if(!ref.onclick){
		var idx = parseInt(ref.innerHTML.replace(/[^\d]/g, ''));
		var references = getElement(self, idReferences?idReferences:'ol_references');
		for(var i=0, index=1; i<references.childNodes.length; i++){
			if(references.childNodes[i].innerHTML!=undefined){
				var child = references.childNodes[i];
				for(var j=0; j<child.childNodes.length; j++){
					var node = child.childNodes[j];
					if(index==idx && node.href){
						ref.nodeReference = node;
						ref.onclick = function(){
							if(browserIE){
								this.nodeReference.click();
							}else{
								if(!HTMLElement.prototype.click){
									HTMLElement.prototype.click = function() {
										var evt = this.ownerDocument.createEvent('MouseEvents');
										evt.initMouseEvent('click', true, true, this.ownerDocument.defaultView, 1, 0, 0, 0, 0, false, false, false, false, 0, null);
										this.dispatchEvent(evt);
									}
								}
								this.nodeReference.click();
							}
						}
						ref.title = ref.alt = trimEnds(child.innerHTML.replace(/<\/?[^>]+>/gi,''));
						break;
					}
				}
				index++;
			}
		}
	}
}
