var currentscrolltop;

function showimage(description, size, image){

	if (!get('absolute')){ return; }
	if (image == ''){
		get('absolute').style.display = 'none'; undobody();
		return;
	}
	
	var galleryimage = get('galleryimage');
	if (galleryimage){

		var sizes = size.split('x');
		
		var theimage = document.createElement('img');
		theimage.setAttribute('src',image);
		theimage.setAttribute('id','gallerypic');
		theimage.style.opacity = '0';
		theimage.alt = '';


		var closelink = document.createElement('span');
		closelink.innerHTML = '(close)';
		closelink.setAttribute('id','closelink');
		
		var thegallerydescription = document.createElement('div');
		thegallerydescription.style.opacity = '0';
		thegallerydescription.setAttribute('id','gallerydescription');
		
		var thedescription = document.createElement('p');
		thedescription.className = 'gallerydescription';
		thedescription.innerHTML = description;
		
		if (browser.isIE){
			theimage.style.filter = 'alpha(opacity=0)';
			thegallerydescription.style.filter = 'alpha(opacity=0)';
		}
		
		galleryimage.innerHTML = '';
		galleryimage.appendChild(theimage);
		thegallerydescription.appendChild(thedescription);
		thegallerydescription.appendChild(closelink);
		galleryimage.appendChild(thegallerydescription);

		get('absolute').style.display = 'block'; 
		galleryimage.style.height = '10px';
		galleryimage.style.width = '10px';
		
		dobody(); 
		
		get('gallerycontainer').style.width = (parseInt(sizes[0])+20)+'px';
		resize(parseInt(sizes[0])+20,parseInt(sizes[1])+45);
		
	}

}


function undobody(){
	document.body.style.height = '';
	document.body.style.overflow = '';
	document.documentElement.scrollTop = currentscrolltop;
}
function dobody(){
	currentscrolltop = document.documentElement.scrollTop;
	document.documentElement.scrollTop = 0;
	document.body.style.height = '100.1%';
	document.body.style.overflow = 'hidden';
}
function get(elementID){
	if (document.getElementById(elementID)){ return document.getElementById(elementID); }
	else { return false; }
}

function fadein(){
	
	var theblock = get('gallerypic');
	if (!theblock){ return; }
	
	var opacity = parseFloat(theblock.style.opacity);
	if (opacity < 1){
		switch (opacity){
			case 0:		theblock.style.opacity = 0.3;	break;
			case 0.3:	theblock.style.opacity = 0.5;	break;
			case 0.5:	theblock.style.opacity = 0.7;	break;
			case 0.7:	theblock.style.opacity = 0.8;	break;
			case 0.8:	theblock.style.opacity = 0.9;	break;
			case 0.9:	theblock.style.opacity = 1;		break;		
			
		}
		setTimeout('fadein()','100');
		return;
	}
	
	var theblock = get('gallerydescription');
	if (!theblock){ return; }
	
	var opacity = parseFloat(theblock.style.opacity);
	if (opacity < 1){
		switch (opacity){
			case 0:		theblock.style.opacity = 0.3;	break;
			case 0.3:	theblock.style.opacity = 0.5;	break;
			case 0.5:	theblock.style.opacity = 0.7;	break;
			case 0.7:	theblock.style.opacity = 0.8;	break;
			case 0.8:	theblock.style.opacity = 0.9;	break;
			case 0.9:	theblock.style.opacity = 1;		break;		
			
		}
		
		setTimeout('fadein()','100');
		return;
	}
	
}

function fadeinIE(){
	
	var theblock = get('gallerypic');
	if (!theblock){ return; }
	
	var opacity = parseInt(theblock.style.filter.replace('alpha(opacity=',''));
	if (opacity < 100){
		switch (opacity){
			case 0:			theblock.style.filter = 'alpha(opacity=30)';	break;
			case 30:		theblock.style.filter = 'alpha(opacity=50)';	break;
			case 50:		theblock.style.filter = 'alpha(opacity=70)';	break;
			case 70:		theblock.style.filter = 'alpha(opacity=80)';	break;
			case 80:		theblock.style.filter = 'alpha(opacity=90)';	break;
			case 90:		theblock.style.filter = 'alpha(opacity=1000)';	break;
		}
		setTimeout('fadeinIE()','100');
		return;
	}
	
	var theblock = get('gallerydescription');
	if (!theblock){ return; }
	
	var opacity = parseInt(theblock.style.filter.replace('alpha(opacity=',''));
	if (opacity < 1){
		switch (opacity){
			case 0:			theblock.style.filter = 'alpha(opacity=30)';	break;
			case 30:		theblock.style.filter = 'alpha(opacity=50)';	break;
			case 50:		theblock.style.filter = 'alpha(opacity=70)';	break;
			case 70:		theblock.style.filter = 'alpha(opacity=80)';	break;
			case 80:		theblock.style.filter = 'alpha(opacity=90)';	break;
			case 90:		theblock.style.filter = 'alpha(opacity=100)';	break;
		}
		
		setTimeout('fadeinIE()','100');
		return;
	}
	
}

function oldresize(desiredWidth, desiredHeight){
	
	var theblock = get('galleryimage');
	if (!theblock){ return; }
	
	var thewidth = parseInt(theblock.style.width);
	var theheight = parseInt(theblock.style.height);
	
	
	if (thewidth < desiredWidth){
		
		if (thewidth < (desiredWidth * 0.2) || thewidth > desiredWidth * 0.8){ 		rate = 8;	}
		else if (thewidth < (desiredWidth * 0.4) || thewidth > desiredWidth * 0.6){	rate = 16;	}
		else {																		rate = 32;	}
		
		if (thewidth+rate > desiredWidth){ thewidth = desiredWidth - rate; }
		theblock.style.width = (thewidth+rate)+'px';
		
	}
	else if (theheight < desiredHeight){
		
		if (theheight < (desiredHeight * 0.2) || theheight > desiredHeight * 0.8){		rate = 8;	}
		else if (theheight < (desiredHeight * 0.4) || theheight > desiredHeight * 0.6){	rate = 16;	}
		else {																			rate = 32;	}
		
		if (theheight+rate > desiredHeight){ theheight = desiredHeight - rate; }
		theblock.style.height = (theheight+rate)+'px';
		
	}
	else if (desiredWidth == thewidth && desiredHeight == theheight){
		get('gallerypic').style.display = 'block';
		if (browser.isIE){	fadeinIE();	}
		else {				fadein();	}
		return;
	}
	else {
		
		theblock.style.width = '0px';
		theblock.style.height = '0px';
		
	}
	
	setTimeout('resize('+desiredWidth+','+desiredHeight+')', 10);

}
var theblock = '';
function doresize(wid, hei){
	if (wid != ''){
		theblock.style.width = wid+'px';
	}
	else {
		theblock.style.height = hei+'px';
	}
}

function resize(desiredWidth, desiredHeight){
	
	var delay = 0;
	var speed = 15;
	theblock = get('galleryimage');
	if (!theblock){ return; }
	
	var thewidth = parseInt(theblock.style.width);
	var theheight = parseInt(theblock.style.height);

	while (thewidth < desiredWidth){
		delay += speed;
		if (thewidth < (desiredWidth * 0.2) || thewidth > desiredWidth * 0.8){ 		
			rate = 8;	
		}
		else if (thewidth < (desiredWidth * 0.4) || thewidth > desiredWidth * 0.6){	
			rate = 16;	
		}
		else {																		
			rate = 32;	
		}
		thewidth += rate;
		if (thewidth > desiredWidth){ thewidth = desiredWidth; }
		setTimeout('doresize(\''+thewidth+'\',\'\')',delay);
	}
	while (theheight < desiredHeight){
		delay += speed;		
		if (theheight < (desiredHeight * 0.2) || theheight > desiredHeight * 0.8){ 		
			rate = 8;	
		}
		else if (theheight < (desiredHeight * 0.4) || theheight > desiredHeight * 0.6){	
			rate = 16;	
		}
		else {																		
			rate = 32;	
		}
		theheight += rate;
		if (theheight > desiredHeight){ theheight = desiredHeight; }
		setTimeout('doresize(\'\',\''+theheight+'\')',delay);
	}
	delay += 100;
	get('gallerypic').style.display = 'block';
	if (browser.isIE){	setTimeout('fadeinIE()',delay);	}
	else {				setTimeout('fadein()', delay);	}
	return;
	
}

function Browser(){
	var ua, s, i;
	this.isIE    = false;
	this.isNS    = false;
	this.version = null;
	ua = navigator.userAgent;
	
	s = "MSIE";
	if ((i = ua.indexOf(s)) >= 0){
		this.isIE = true;
		this.version = parseFloat(ua.substr(i + s.length));
		return;
	}
	
	s = "Netscape6/";
	if ((i = ua.indexOf(s)) >= 0) {
		this.isNS = true;
		this.version = parseFloat(ua.substr(i + s.length));
		return;
	}
	
	s = "Gecko";
	if ((i = ua.indexOf(s)) >= 0) {
		this.isNS = true;
		this.version = 6.1;
		return;
	}
}

var browser = new Browser();
