



function showPhoto(that) {
	var p = $('photo_medium');

	p.setAttribute( 'medium_href', that.getAttribute('medium_href') );
	p.setAttribute( 'medium_width', that.getAttribute('medium_width') );
	p.setAttribute( 'medium_height', that.getAttribute('medium_height'));

	p.setAttribute( 'large_href', that.getAttribute('large_href') );
	p.setAttribute( 'large_width', that.getAttribute('large_width') );
	p.setAttribute( 'large_height', that.getAttribute('large_height'));


	p.effect('opacity', {
			duration: 500,
			onComplete: function() {
				_startShowPhoto();
			}
		}
	).custom(1, 0.01);


}

function _startShowPhoto() {
	var p = $('photo_medium');

	p.setAttribute( 'width', p.getAttribute('medium_width') );
	p.setAttribute( 'height', p.getAttribute('medium_height') );

	p.style.width = p.getAttribute('medium_width') + 'px';
	p.style.height = p.getAttribute('medium_height') + 'px';

	p.src = p.getAttribute('medium_href');
	_showPhotoLoading(p.id, '_startShowPhoto');

	var img = new Image();
	img.src = p.getAttribute('medium_href');

	img.onload = function() {
		_doShowPhoto();
	}

}

function _doShowPhoto() {
	var p = $('photo_medium');

	_hidePhotoLoading();

	p.effect('opacity', {
			duration: 1000,
			onBegin: function() {

			},
			onComplete: function() {

			}
		}
	).custom(0.01, 1);
}


function showPhotoLarge(p) {
	var p = $(p);

	var div = $('_divPhotoLarge');
	if(!div) {
		with(div = document.createElement('div')) {
			id = '_divPhotoLarge';
			style.position = 'absolute';
			style.background = '#ffffff';
			style.border = 'solid #A4A254 1px';
			style.display = 'none';
			style.padding = '0px 10px 10px 10px';
		}

		var buf = ''
		+ '<table width="100%" cellpadding="0" cellspacing="0">'
		+ '<tr><td align="right" style="padding:5px 0px 0px 0px;">'
		+ '<img id="_imgHidePhotoLarge" src="assets/images/close.png" width="47" height="16" border="0" style="cursor:pointer;">'
		+ '</td></tr>'
		+ '</table>'
		+ '';

		div.innerHTML = buf;

		var divimg;
		with(divimg = document.createElement('img')) {
			id = 'imgPhotoLarge';
			style.width = '1px';
			style.height = '1px';
			style.border = 'solid #A4A254 1px';
			style.margin = '0px 0px 0px 0px';
		}
		div.appendChild(divimg);


		document.body.appendChild(div);
	}
	div.style.width = (p.offsetWidth) + 'px';
	div.style.height = (p.offsetHeight) + 'px';
	div.style.left = p.getLeft() + 'px';
	div.style.top = p.getTop() + 'px';

	divimg = $('imgPhotoLarge');
	divimg.src = p.getAttribute('large_href');
	divimg.style.width = (p.offsetWidth) + 'px';
	divimg.style.height = (p.offsetHeight) + 'px';

	divimg.onclick = function() { hidePhotoLarge(p.id); }
	$('_imgHidePhotoLarge').onclick = function() { hidePhotoLarge(p.id); }

	_showPhotoLoading(p.id, 'showPhotoLarge');

	var img = new Image();
	img.src = p.getAttribute('large_href');

	img.onload = function() {
		_startShowPhotoLarge(p.id);
	}

}


function _startShowPhotoLarge(p) {


	var p = $(p);
	p.style.visibility = 'hidden';

	$('_divPhotoLarge').style.display = 'block';
	new Fx.Style('_divPhotoLarge', 'opacity').set(1);

	_hidePhotoLoading();

	var divsizeto = new Object();
	divsizeto.width = ( (p.getAttribute('large_width')*1) + 0 );
	divsizeto.height = ( (p.getAttribute('large_height')*1) + 20 );
	divsizeto.top = ( ( document.body.clientHeight - divsizeto.height ) / 2 ) + document.body.scrollTop ;
	divsizeto.left = ( ( document.body.clientWidth - divsizeto.width ) / 2 ) + document.body.scrollLeft ;


	var imgsizeto = new Object();
	imgsizeto.width = p.getAttribute('large_width');
	imgsizeto.height = p.getAttribute('large_height');


	new Fx.Styles('_divPhotoLarge', {
			duration: 300,
			transition: Fx.Transitions.linear,
			onComplete: function() {
				//_doShowLocationPhotoLarge();
			}
		}
	).start(
		{
	    	'height': divsizeto.height,
	    	'width': divsizeto.width,
			'top': divsizeto.top,
			'left': divsizeto.left
		}
	);

	new Fx.Styles('imgPhotoLarge', {
			duration: 300,
			transition: Fx.Transitions.linear,
			onComplete: function() {
				//_doShowLocationPhotoLarge();
			}
		}
	).start(
		{
	    	'height': imgsizeto.height,
	    	'width': imgsizeto.width
		}
	);
}


function hidePhotoLarge(p) {


	p = $(p);

	var divsizeto = new Object();
	divsizeto.width = ( (p.getAttribute('width')*1) );
	divsizeto.height = ( (p.getAttribute('height')*1) );

	divsizeto.top = p.getTop();
	divsizeto.left = p.getLeft();


	var imgsizeto = new Object();
	imgsizeto.width = ( (p.getAttribute('width')*1) );
	imgsizeto.height = ( (p.getAttribute('height')*1) );


	new Fx.Styles('_divPhotoLarge', {
			duration: 300,
			transition: Fx.Transitions.linear,
			onComplete: function() {

			}
		}
	).start(
		{
	    	'height': divsizeto.height,
	    	'width': divsizeto.width,
			'top': divsizeto.top,
			'left': divsizeto.left
		}
	);

	new Fx.Styles('imgPhotoLarge', {
			duration: 300,
			transition: Fx.Transitions.linear,
			onComplete: function() {
				$('_divPhotoLarge').style.display = 'none';
				$(p).style.visibility = 'visible';
			}
		}
	).start(
		{
	    	'height': imgsizeto.height,
	    	'width': imgsizeto.width
		}
	);

}




function _showPhotoLoading(anchor, iefixfunc) {
	var p = $(anchor);
	var d = $('divloading');

	if(!d) {
		with(d = document.createElement('div')) {
			id = 'divloading';
			style.position = 'absolute';
			style.backgroundColor = '#ffffff';
			style.display = 'none';
			style.zIndex = 99;
		}
		d.innerHTML = ''
			+ '<table width="100%" height="100%" cellpadding="0" cellspacing="0">'
			+ '<tr><td align="center" valign="middle" height="100%">'
			+ '<img align="absmiddle" src="assets/images/loading.gif"> &nbsp; '
			+ '<span class="h1">Loading ...</span>'
			+ '</td></tr>'
			+ '</table>'
			+ '';

		document.body.appendChild(d);
	}

	d.style.left = p.getLeft() + 'px';
	d.style.top = p.getTop() + 'px';
	d.style.width = (p.offsetWidth + 2) + 'px';
	d.style.height = (p.offsetHeight + 2) + 'px';

	// prevents the loading screen from blinking if the image is cached or loads quickly
	window._divloading_timer = setTimeout("$('divloading').style.display = '';", 50);

	// sometimes IE doesnt fire the img onload event for some reason
	var callback = iefixfunc+'(\\\''+p.id+'\\\');';
	var callback = "_imgloading_IEFIX('"+callback+"');";
	window._imgloading_IEFIX_timer = setTimeout(callback, 5000);
}

function _hidePhotoLoading() {
	clearTimeout(window._imgloading_IEFIX_timer);
	clearTimeout(window._divloading_timer);

	if($('divloading')) $('divloading').style.display = 'none';
}


function _imgloading_IEFIX(func) {
	if(func) eval(func);
}







