
var curWidth = 0;
var curHeight = 0;

function showLImage(thespan,filename,width,height)
{
	
	xlim = tt_Int((tt_db && tt_db.clientWidth)? tt_db.clientWidth : window.innerWidth) +
			 -(tt_n4? 21 : 0) - 30;
	ylim = tt_Int(window.innerHeight || tt_db.clientHeight) +
			 - tt_offY;
	
	twidth = Math.min(xlim-8,width);
	theight = Math.min(ylim-8,height);
	
	wratio = twidth / width;
	hratio = theight / height;
	
	useratio = Math.min(wratio,hratio);
	
	usewidth = Math.floor(width*useratio);
	useheight = Math.floor(height*useratio);
	
	inner = "<img src='"+filename+"' style='width: "+(usewidth)+"px; height: "+(useheight)+"px;'>";
	
	//tt_Hide(true);
   	//tip(thespan,inner,true);
   	
   
	box = document.getElementById('imagecont');
	box.innerHTML = inner;
	box.className = 'shown';
	box.style.width = usewidth+"px";
	box.style.height = useheight+"px";
	box.style.left = Math.floor( (xlim - usewidth)/2)+"px";
	box.style.top = Math.floor( (ylim - useheight)/2)+"px";

}

function hideLImage()
{
	box = document.getElementById('imagecont');
	box.innerHTML = '';
	box.className = 'hidden';
	box.style.width = box.style.height = 0;
}

function iconMouseOver(id)
{
	//alert('mouse over for '+id);
	//document.getElementById(id).style.visibility = 'visible';
}

function iconMouseOut(id)
{
	//document.getElementById(id).style.visibility = 'hidden';
	//alert('mouse out for '+id);
}

function setImage(gname,cname,file,w,h,id,ext)
{
	img = document.getElementById('medimagesrc');
	img.className = 'hidden';
	
	boxw = 455;
	boxh = 368;
	//height: 373px;
	//width: 430px;
	//alert('w '+img.width+' h '+img.height);
	if( w > h )
	{
		ratio = boxw / w;
		img.width = boxw;
		img.height = Math.floor(h * ratio);
		
		
	}
	else
	{
		ratio = boxh / h;
		img.height = boxh;
		img.width = Math.floor(w * ratio);
	
	}
	
	//alert('h: '+img.height+' w: '+img.width);
	document.getElementById('currid').value = id;
	img.style.marginLeft = Math.floor((boxw - Math.floor(w * ratio))/2)+'px';
	img.style.marginTop = Math.floor((boxh - Math.floor(h * ratio))/2)+'px';
	img.src = 'img/galleries/'+gname+'/'+cname+'_'+file+'_med.'+ext;
	document.getElementById('instruct').className = 'hidden';
	img.className = 'shown';

}

function setPImage(cfile,file,w,h,id,d)
{
	cont = document.getElementById('medimagec');
	img = document.getElementById('medimagesrc');
	img.src = cfile;
	img.className = 'hidden';
	
	boxw = 455;
	//height: 373px;
	//width: 430px;
	//alert('w '+img.width+' h '+img.height);
	if( w > h )
	{
		cont.className = 'medimagewide';
		boxh = 338;
		ratio = boxw / w;
		img.width = boxw;
		img.height = h * ratio;
		
		
	}
	else
	{
		cont.className = 'medimagetall';
		boxh = 373;
		ratio = boxh / h;
		img.height = boxh;
		img.width = w * ratio;
	
	}

	document.getElementById('caption').className = 'shown';
	
	document.getElementById('currid').value = id;
	margin=Math.floor((boxw - img.width)/2)+'px';
	img.style.marginLeft = Math.floor((boxw - img.width)/2)+'px';
	//alert(boxw+" "+img.width+" "+img.style.marginLeft+"|"+Math.floor((boxw - img.width)/2)+'px');

	
	//alert(id);
	document.getElementById('caption').innerHTML = d;
	document.getElementById('instruct').className = 'hidden';
	img.className = 'shown';
}

function largeImage()
{
	var pid = document.getElementById('currid').value;
	window.open('?misc/pic&pid='+pid,'largepic','width='+curWidth+', height='+curHeight+', menubar=no, toolbar=no, location=no, directories=no, status=no, scrollbars=yes, resizable=yes');

}

function largePImage()
{
	var pid = document.getElementById('currid').value;
	//alert(pid);
	window.open('?misc/pic&ppid='+pid,'largepic','width='+curWidth+', height='+curHeight+', menubar=no, toolbar=no, location=no, directories=no, status=no, scrollbars=yes, resizable=yes');

}

function showPhoto(src,w,h)
{
	ip = document.getElementById('innerphoto');
	ip.className='shown';
	ip.style.width = (w)+'px';
	ip.style.height = (h)+'px';
	//ip.style.top = '10px';
	//ip.style.left = '10px';
	//	left: 283px;
	//top: 192px;
	//width: 556px;
	//height: 375px;
	ip.style.marginTop = Math.floor( (375-h)/2 )+'px';
	ip.style.marginLeft = Math.floor( (385-w)/2 )+'px';
	document.getElementById('innerphotoimg').src = src;
	document.getElementById('entries').className = 'greyed';
}

function closePhoto()
{
	document.getElementById('innerphoto').className='hidden';
	document.getElementById('entries').className = '';
}