// JavaScript Document
//document.write('<scr'+'ipt src="/js/callout/callout-1.0.js" type="text/javascr'+'ipt></sc'+'ript>');

function include( file ) {
var th = document.getElementsByTagName(arguments[1]||'head')[0];
var s = document.createElement('script');
s.setAttribute('type','text/javascript');
s.setAttribute('src',file);
th.appendChild(s);
}

include( '/js/callout/callout.min.js' );

function ALJ (){};
ALJ.load = function(){};
ALJ.js = function(){};

function getStyle(el,styleProp)
{
	var x = document.getElementById(el);
	if (x.currentStyle)
		var y = x.currentStyle[styleProp];
	else if (window.getComputedStyle)
		var y = document.defaultView.getComputedStyle(x,null).getPropertyValue(styleProp);
	return y;
}


function toggle ()
{
	if ( !arguments.length ) return;
	var el, ids = arguments;
	for( var i=0; i<ids.length; i++ )
	{
		if ( !(el = document.getElementById( ids[i] )) ) continue;
		
		if ( getStyle( el, 'display' ) == 'none' )
			el.style.display = '';
		else
			el.style.display = 'none';
	}
}


Event.observe(window,'load', function () {
	var m=$$('img.preview');i=m.length;
	preview = new Callout({arrow:false,opacity:.6,borderWidth:4,offset:{x:16}});
	while( i-- )
	{
		m[i].observe('mouseover',function(ev){
				var e=ev.findElement('img'), src;
				if ( /resize-(?:tn|sm|lg|fullsize)/.test(e.className) )
					src = e.src.replace(/\/(?:tn|sm|lg|fullsize)\//,'/'+e.className.replace(/^.*resize-(\w+).*/,'$1')+'/');
				else
					src = e.src;
				var im=new Element(e.tagName,{'src':src}).setStyle({display:'block'});
				var s=e.getStyle('position');
				if ( s=='absolute' || (s=='relative' && (e.getStyle('top') || e.getStyle('left') || e.getStyle('right') || e.getStyle('bottom'))) ) {
				var p=e.ancestors();
				for( var i=0, len=p.length; i<len; i++ ) if ( p[i].getStyle('position') != 'absolute') break;
					
				e = len<i? e : p[i];
				}
				
				if ( !im.width ) im.observe('load',function(){preview.open( ev,{'html':im,'target':e} ); });
				else preview.open( ev, {'html':im,'target':e} );
				
			});
		m[i].observe('mouseout',function(){ preview.close(); });
	}
	
	m=$$('.whentogo');i=m.length;
	while( i-- )
	{
		var tmp = new Callout({position:(m[i].getHeight()<m[i].getWidth()?'vertical':'horizontal'),padding:4,arrow:false});
		m[i].setStyle({cursor:'default'});
		m[i].observe('mouseover',function(ev){
				var e=ev.findElement('li');
				if ( !e || e=='undefined' ) return;
				var html='<b>'+e.title.replace(/\|\|/,'</b><br>');
				var o={borderColor:e.getStyle('backgroundColor')};
				var p=e.ancestors();
				for( var i=0, len=p.length; i<len; i++ ) if ( /whentogo/.test(p[i].className) ) { p=p[i]; break; }
				if ( Object.isElement(p) )
					o.width = p.getWidth();
				
				tmp.open( ev,{'html':html,'target':p,'options':o});
				
			});
		m[i].observe('mouseout',function(){ tmp.close(); });
	}
	
	m=$$('.activ img','img.activity');i=m.length;
	while( i-- )
	{
		var tmp2 = new Callout({width:200,offset:{x:-12}});
		m[i].observe('mouseover',function(ev) {
				var e=ev.findElement('img');
				var html = new Element('div').setStyle({padding:'4px',width:'100%',overflow:'auto'});
				var im=new Element('img',{src:e.src}).setStyle({marginRight:'4px','float':'left',width:'50px',height:'50px'});
				html.insert( im );
				html.insert( new Element('b').update(e.title) );
				html.insert( new Element('br') );
				html.insert( e.alt );
				tmp2.open( ev, {'html':html,'target':e, 'options':{opacity:.7}} );
				
			});
		m[i].observe('mouseout',function(){ tmp2.close(); });
	}

});
