/*
 *  ExifInfo - Display information on the image in a tooltip.
 *
 *  (c) 2009, C. Vagnetoft <noccy@chillat.net>
 *  Built for dreamerartworx.com and MetaGallery
 *
 *  Distributed under the GNU GPL
 */

var cache = [];

function showInfo(el,file) {
	var $el = $(el);
	if ($el.childNodes.length > 1) {
		if (Element.getStyle($el.lastChild,'opacity') == 0.0) {
			new Effect.Opacity($el.lastChild, { from: 0.0, to:0.8, duration:0.2 });
		} else if (Element.getStyle($el.lastChild,'opacity') < 0.8) {
			setTimeout(function() {
				showInfo($el,file);
			},500);
		}
	} else {
		var exif = new Element('div',{
			class:'infotip'
		});
		exif.update('<b>Image Title</b><br>1280 x 968<br>Shot with xxxx yy zz');
		$el.appendChild(exif);
		new Effect.Opacity(exif, { from: 0.0, to: 0.8, duration: 0.2 });
	}
}

function hideInfo(el,timed) {
	var $el = $(el);
	if (Element.getStyle($el.lastChild,'opacity') == 0.8) {
		new Effect.Opacity($el.lastChild, { from: 0.8, to: 0.0, duration: 0.2 });
	} else if (Element.getStyle($el.lastChild,'opacity') > 0.0) {
		setTimeout(function() {
			hideInfo($el)
		},500);
	}
}

function reveal(el) {
	new Effect.Opacity(el, { from: 0.0, to: 1.0, duration: 0.8 });
}

function showTip(e) {
	var pointer = { x:e.pointerX(), y:e.pointerY() };
	$tip.setStyle({
		left:(pointer.x+25)+'px',
		top:(pointer.y+10)+'px',
		display:''
	});
	$tip.update(cache[this.id]);
	$tip.show();
}
function hideTip(e) {
	$tip.hide();
}

function setHooks() {
	$$('div.thumb').each(function(el){
		el.observe('mouseover',showTip);
		el.observe('mousemove',showTip);
		el.observe('mouseout',hideTip);
	});
	// TODO: Hook all the images	
}

Event.observe(window,'load',function() {
	setHooks();
});

var $tip = new Element('div',{ class:'infotip' }).setStyle({ display:'none' }).update('Tip');
document.documentElement.appendChild($tip);