var avatars = [];
var DOMLoaded = false;

document.observe('dom:loaded', function(){
	DOMLoaded = true;
	DOMLoader();
})

function DOMLoader(){
	avatars.each(function(av,i){
		$('twitter_avatars').innerHTML += '<li><a href="http://twitter.com/'+av['user']+'/statuses/'+av['id']+'" target="LPTTwitter" title="'+av['user']+'" rel="http://theclassicspresents.com/images/twitter/'+av['pic_large_filename']+'"><img src="http://theclassicspresents.com/images/twitter/'+av['pic_thumb_filename']+'"/></a></li>';
	});
	$('twitter_avatars').insert({bottom:'<div id="twitter_preview"></div>'});
	$('twitter_avatars').observe('mousemove', function(e){
		newX = (e.pointerX()+20);
		newY = (e.pointerY()-30);
		if(img = $('twitter_preview').select('img')[0]){
			windowBottom = document.viewport.getScrollOffsets()['top'] + window.innerHeight;
			imgSize = img.getHeight();
			if((newY + imgSize) > windowBottom){
				newY = windowBottom - imgSize;
			}			
		}
		$('twitter_preview').style.left = newX+'px';
		$('twitter_preview').style.top = newY+'px';
	});
	$$('#twitter_avatars li img').each(function(img,i){
		img.observe('mouseover', function(){
			a = $(img.parentNode);
			$('twitter_preview').innerHTML = '<img src="'+a.getAttribute('rel')+'"/>';
		}.bind(this));
	});
	// Make sure all of the links are jumping out of the iframe		
	$$('a').each(function(link,index){
		if(!link.getAttribute('target')){
			link.setAttribute('target', '_top');
		}
	});
}

function loadLPDAvatars(avatarArray)
{
	avatars = avatarArray;
	// Re-call the DOM Loader if the tweets were loaded after the DOM
	if(DOMLoaded){
		DOMLoader();
	}
}