function shotdownloads(){
	xmlhttp = new XMLHttpRequest();
	//xmlhttp.open("GET", "downloads/"+((location.href.indexOf('?')!=-1)?location.href.substr(location.href.indexOf('?'),location.href.length):''),true);
	xmlhttp.open("GET", "downloads/"+((location.href.indexOf('?')!=-1)?location.href.substr(location.href.indexOf('?'),location.href.length):''),true);
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {
			filelist=xmlhttp.responseText.match(/[^"]*-small\.jpg"/g);
			filelistHTML=''
			for(file=0;file<filelist.length;file++){
				filelistHTML=filelistHTML+
				'<div>'+
				'<a href="downloads/'+filelist[file].replace(/-small/,"")+'">'+
				'<img onmousemove="shotpopup(\'\',event)" onmouseout="shotpopup(\'\',event)" onclick="shotpopup(\''+filelist[file].replace(/-small\.jpg"/,".jpg")+'\',event);return false" src="downloads/'+filelist[file]+' />'+
				'</a>'+
				'<br />'+
				'<a class="presetlink" href="downloads/'+filelist[file].replace(/-small\.jpg/,".avs")+'">'+
				filelist[file].replace(/-small.jpg"/,"").replace(/%20/g,' ')+
				'<img class="linkicon" src="/images/icons/disk.png" width="16" height="16" />'+
				'</a>'+
				'</div>'
			}
			filelistHTML=filelistHTML+'<hr />'

			document.getElementById('downloads').innerHTML=document.getElementById('downloads').innerHTML+filelistHTML
		}
	}
	xmlhttp.send(null)
}


function shotpopup(img,e){
	 var e = e || window.event;
	
	//Create popup image if needed
	if(!document.getElementById('popup')){
		popup=document.createElement('img')
		popup.id='popup'
		popup.style.display='none'
		document.getElementById('downloads').appendChild(popup)
	}
	
	var popup=document.getElementById('popup')

	if(e.type=="mouseout"){
		popup.style.display='none'
	}
	else{
		//Get Mouse positions
		 var cursor={x:0,y:0};
		 if(e.pageX||e.pageY){
			  cursor.x=e.pageX;
			  cursor.y=e.pageY;
		 }
		 else{
			  cursor.x=e.clientX+
					(document.documentElement.scrollLeft||document.body.scrollLeft)-
					document.documentElement.clientLeft;
			  cursor.y=e.clientY+
					(document.documentElement.scrollTop||document.body.scrollTop)-
					document.documentElement.clientTop;
		 }
		
		if(e.type=="click"){
			if(popup.style.display=='block'){
				popup.style.display='none'
			}
			else{
				popup.src='/images/transparent/white.png'
				popup.src='downloads/'+img
				popup.style.display='block'
			}
		}
		else if(e.type=="mousemove"){
			var width=window.innerWidth||document.body.clientWidth
			popup.style.top=(cursor.y +10)+'px'
			if(cursor.x<(width/2)){
				popup.style.left=(cursor.x+10)+'px'
				popup.style.right='auto'
			}
			else{
				popup.style.left='auto'
				popup.style.right=(width-cursor.x+10)+'px'
			}
		}
	}
}

function linkiconadd(){
	var icon=document.createElement('img'),iconlink=document.createElement('a'),links=document.body.getElementsByTagName('a')
	iconlink.classname='linkicon'
	icon.alt=''
	icon.width=16
	icon.height=16
	icon.className='linkicon'
	function add(where,alt,src,href,x,y){
		var i=icon.cloneNode(1)
		i.src='/images/icons/'+src+'.png'
		i.alt=alt
		if(x) i.width=x
		if(y) i.height=y
		i.title=alt
		where.appendChild(i)
	}
	for(var x=links.length;--x>=0;){
		if(links[x].href){
			var lnk=links[x],href=lnk.href.split('?')[0],prot=href.split(':')[0]
			//File Extensions
			switch(href.replace(/\?.*/,'').split('.').pop()){
				case "asv":add(lnk,'Advanced Visualization Studio','disk',href);break;
				case "rar":add(lnk,'RAR Archive','disk',href);break;
			}
		}
	}
}