tog = new Array();

$(document).ready(function()
{
	bigwidth = $('#img-container').width();
	
	bigwidth = (bigwidth == null) ?
		1 : parseInt(bigwidth) - 18;
	
	$('#img-container').css('width', bigwidth);
});

/*
<object type='audio/mpeg' data='http://www.we-have-iuav.com/files/racconti.mp3' width='200' height='20'><param name='src' value='http://www.we-have-iuav.com/files/racconti.mp3'><param name='autoplay' value='true'><param name='autoStart' value='0'>alt : <a href='http://www.we-have-iuav.com/files/racconti.mp3'>http://www.we-have-iuav.com/files/racconti.mp3</a></object>
*/

function toggleImg(id, width, height, thwidth)
{
	$('div').remove('#once');
	var thiswidth = 0;
	
	$('.grow em').html('');
	
	if ((!tog[id]) || (tog[id] == false))
	{
		o = document.getElementById('img'+id);
		var yo = o.id;

		if (o)
		{
			tog[id] = true;
			
			// IE wants these
			o.getElementsByTagName('div')[0].style.width = width + 'px';
			o.getElementsByTagName('div')[0].style.height = height + 10 + 'px';

			o.getElementsByTagName('a')[0].style.width = width + 'px';
			o.getElementsByTagName('a')[0].style.height = height + 10 + 'px';
			
			o.getElementsByTagName('img')[0].style.width = width + 'px';
			o.getElementsByTagName('img')[0].style.height = height + 'px';
			
			preloadImage(path + o.getElementsByTagName('img')[0].alt);
			
			o.getElementsByTagName('em')[0].style.display = 'block';
			
			var insert = $('#img' + id + ' .audio').html();
			
			if (insert != '')
			{
				var html = "<object type='audio/mpeg' data='http://www.we-have-iuav.com/files/audio_portraits/" + insert + "' width='200' height='20' style='text-align: center; display: inline;'><param name='src' value='http://www.we-have-iuav.com/files/audio_portraits/" + insert + "'><param name='autoplay' value='true'><param name='autoStart' value='0'>alt : <a href='http://www.we-have-iuav.com/files/audio_portraits/" + insert + "'>http://www.we-have-iuav.com/files/audio_portraits/" + insert + "</a></object>";
				
				//alert(html);
				
				$('#img' + id + ' em').html(html);
				
				//$('#play_audio').css('display', 'block');
				//$('#play_audio').html(html);
			}
		}
		
	}
	else
	{
		o = document.getElementById('img'+id);
		var yo = o.id;
		
		if (o)
		{
			tog[id] = false;
			
			// IE wants these
			o.getElementsByTagName('div')[0].style.width = thwidth + 20 + 'px';
			o.getElementsByTagName('div')[0].style.height = thwidth + 20 + 'px';
			
			o.getElementsByTagName('em')[0].style.display = 'none';
	
			o.getElementsByTagName('a')[0].style.width = '';
			o.getElementsByTagName('a')[0].style.height = '';
			
			d = path + 'th-' + o.getElementsByTagName('img')[0].alt;
			
			// back to the thumbnail - use natural size
			o.getElementsByTagName('img')[0].style.width = '';
			o.getElementsByTagName('img')[0].style.height = '';
			
			o.getElementsByTagName('img')[0].src = d;
			
			o.getElementsByTagName('em')[0].style.display = 'none';
			
			
			$('#img' + id + ' em').html('');
			//$('#play_audio').html('');
		}
	}
	
	$('div.grow').each(function()
	{
		var thewidth = $(this).width();
		thiswidth = parseInt(thiswidth) + parseInt(thewidth);
		
		if (thiswidth > bigwidth)
		{
			var help = $(this).prev('div.grow').attr('id');
			$(this).prev('div.grow').after("<div id='once'><!-- --></div>");
			thiswidth = thewidth;
		}
	});
}

function preloadImage(image)
{
	preload = new Image();
	preload.src = image;
	o.getElementsByTagName('img')[0].src = preload.src;
}
