/**
*	tooltip functionality
*/
btc.tooltip =
{
	/**
	*	property used to reference used objects and internal timer
	*/
	mainMenu : null,	
	compatibilityTable : null,	
	timer : null,
	activeMainMenuPopup : null,
	activeCompatibilityTablePopup : null,
	
	/**
	*	function used to initialize wanted behaviour
	*/
	init : function ()
	{
		btc.tooltip.compatibilityTable = document.getElementById( 'btconn-compatibility-table' );
		btc.tooltip.mainMenu = document.getElementById( 'btconn-header' );
		btc.tooltip.attachHandlersForMainMenu ();		
		btc.tooltip.attachHandlersForCompatibilityTable ();	
	},
	
	/**
	*	generic eventhandler attachment function
	*/
	attachHandlers : function (spans, what)
	{
		if(spans)
		{				
			var length = spans.length;
			
			for( var i = 0; i < length; i++ )
			{
				var span = spans[i];
										
				if( btc.element.getAttr( span , 'class' ) == "info" )
				{
					if(span.style.styleFloat == undefined)
					{
						span.style.display = 'inline';
					}	
					else
					{
						span.style.display = 'inline-block';
					}			
					
					btc.event.register (span, 'mouseover', what.mouseover);
					btc.event.register (span, 'mouseout', what.mouseout);				
				}
			}			
		}
	},
	
	/**
	*	attaches eventhandlers for the mainmenu popups
	*/
	attachHandlersForMainMenu : function ()
	{
		
		if(btc.tooltip.mainMenu)
		{
			var spans = btc.tooltip.mainMenu.getElementsByTagName( 'span' );
			btc.tooltip.attachHandlers (spans, btc.tooltip.eventHandlers.mainMenu)
		}
	},
		
	/**
	*	attaches eventhandlers for the compatibilitytable popups
	*/
	attachHandlersForCompatibilityTable : function ()
	{		
		
		if(btc.tooltip.compatibilityTable)
		{		
			var header = btc.tooltip.compatibilityTable.getElementsByTagName( 'thead' )[0];
			if(header)
			{
				var spans = header.getElementsByTagName( 'span' );
				btc.tooltip.attachHandlers (spans, btc.tooltip.eventHandlers.compatibilityTable);
			}
		}
	},
	
	/**
	*	object containing all eventhandlers used
	*/
	eventHandlers :
	{
		compatibilityTable :
		{			
			mouseover : function ( e )
			{
				e = e || window.event;
				
				if ( e )
				{					
					var target = e.target || e.srcElement;	
					var spans = target.parentNode.getElementsByTagName( "span" );
					
					if( spans.length >= 3 ) 
					{			
						var balloon = target.parentNode.getElementsByTagName( "span" )[2];
						
						if(btc.tooltip.activeCompatibilityTablePopup)
						{
							btc.tooltip.activeCompatibilityTablePopup.style.display = 'none';
						}
					
						window.clearTimeout( btc.tooltip.timer );
						btc.tooltip.timer = setTimeout( function( ){ balloon.style.display = 'block'; } , 10 );
			
						balloon.style.left = (balloon.className.indexOf( "right" ) == -1 ? (btc.element.getX( target )-25) : (btc.element.getX( target )-313)) + 'px'; 
						balloon.style.top = (btc.element.getY( target )+20) + 'px';
						
						btc.event.register (balloon, 'mouseover', btc.tooltip.eventHandlers.balloon.mousemoveover);
						btc.event.register (balloon, 'mousemove', btc.tooltip.eventHandlers.balloon.mousemoveover);
						
						balloon.onmouseout = function ()
						{
								btc.tooltip.timer = window.setTimeout (function ()
								{
									btc.tooltip.activeCompatibilityTablePopup.style.display = 'none';
								}, 10)
						};
						
						btc.tooltip.activeCompatibilityTablePopup = balloon;
					}
				}
			},
			
			mouseout : function ( e )
			{
				e = e || window.event;
				if ( e )
				{					
					var target = e.target || e.srcElement;	
					var spans = target.parentNode.getElementsByTagName( "span" );
					
					if( spans.length >= 3 ) 
					{						
						var balloon = spans[2];
						window.clearTimeout( btc.tooltip.timer );
						btc.tooltip.timer = setTimeout( function( )
						{ 
							btc.tooltip.activeCompatibilityTablePopup.style.display = 'none'; 
						}, 10);
					}
				}
			}
		},
	
							
						
		mainMenu : 
		{
			mouseover : function( e )
			{
				e = e || window.event;
				if ( e )
				{
					var target = e.srcElement || e.target;		
					
					if(btc.tooltip.activeMainMenuPopup)
					{
						btc.tooltip.activeMainMenuPopup.style.display = 'none';
					}
						
					var balloon = target.parentNode.parentNode.nextSibling;			
					window.clearTimeout (btc.tooltip.timer);
					btc.tooltip.timer = window.setTimeout (function (){balloon.style.display = 'block';}, 10);
					balloon.style.left = (btc.element.getX( target )-25) + 'px';
					balloon.style.top = (btc.element.getY( target )+20) + 'px';
					btc.event.register (balloon, 'mouseover', btc.tooltip.eventHandlers.balloon.mouseout);
					balloon.onmouseout = function( ){ btc.tooltip.activeMainMenu.style.display = 'none'; };
					
					btc.tooltip.activeMainMenu = balloon;
				}
			},
			
			mouseout : function( e )
			{
				e = e || window.event;
				if ( e )
				{
					var target = e.srcElement || e.target;		
					
					window.clearTimeout( btc.tooltip.timer);
					btc.tooltip.activeMainMenu.style.display = 'none';
				}
			}
		},
		
		balloon :
		{			
			mouseout : function ( e )
			{
				var e = e || window.event;
				if(e)
				{
					btc.tooltip.timer = window.setTimeout (function ()
					{
						btc.tooltip.activeMainMenu.style.display = 'none';
					}, 10)
				}				
			},
			
			mousemoveover : function ()
			{
				window.clearTimeout (btc.tooltip.timer);
			}
		}
	}
};


/**
*	print button functionality
*/
btc.print =
{
	/**
	*	properties, buttons
	*/
	buttons : [document.getElementById( 'btconn-print-top' ), document.getElementById( 'btconn-print-bottom' )],
	
	/**
	*	init function called to attach all wanted functionality
	*/
	init : function ( e )
	{
		btc.print.attachHandlerForPrintButton ();
	},
	
	/**
	*	attaches event handlers to
	*/
	attachHandlersForPrintButton : function ()
	{
		btc.event.register ( btc.print.buttons, 'click',  btc.print.eventHandlers.click);
	},
	
	/**
	*	object containing function to be used as eventhandlers
	*/
	eventHandlers :
	{
		click : function ( e )
		{
			btc.event.cancel ( e );
			window.print ();
		}
	}
};