var activeObject = "";
var ie = ( document.all )? true : false;
var functions = [];
var pixel = new Image(1,1)
pixel.src = "images/pixel.gif";
var currentAnswer = "";


function keyPress( e )
{
	var Pressedkey = ( ie )? e.keyCode : (!e.keyIdentifier)? e.which : e.keyIdentifier;
	
//	if ( Pressedkey == 13 )
//	{
//		event.cancelBubble = true;
//		event.returnValue = false;
//    }
}



function ShowAnswer(id)
{
    if (currentAnswer != "" && currentAnswer != id)
    {
        var ca = GetStyle(currentAnswer);
        ca.visibility = "hidden";
        ca.display = "none";
    }

	var o = GetStyle( id );
	
	if ( o )
	{
		if ( o.visibility != "visible" )
		{
			o.visibility = "visible";
			o.display = "";
		}
		else
		{
			o.visibility = "hidden";
			o.display = "none";
        }

        currentAnswer = id;
	}
}


function ShowMenu( id )
{
	// Position submenu
	var s = GetStyle( id + "Links" );
	
	if ( s )
	{
		s.top = GetYPos( id + "Img" ) + 6;
		s.left = GetXPos( id + "Img" ) - 14;
	}


	HideActiveMenu();


	// Set select color
	var o = GetStyle( id );
	if ( o )
		o.backgroundColor = "#600";

	// Show submenu
	Show( id + "Links" );
}


function HideActiveMenu()
{
	if ( activeObject.length > 0 )
	{
		var id = activeObject.substring(0,activeObject.length - 5);
		var o = GetStyle( id );

		// Set default color
		if ( o )
			o.backgroundColor = "#903";
	}
		
	// Hide submenu
	Hide( activeObject );
}

    


function GetObject( id )
{
	return document.getElementById( id );
}

function GetStyle( id )
{
	var o = GetObject( id );

	var ret = null;

	if ( o )
		ret = o.style; //( ie )?  : o.item( 0 ).style;

	return ret;
}

function GetHeight( id )
{
	var img = ( ie ) ? document.images( id ) : document.images.namedItem( id );
	return ( img )? img.height : 0;
}

 

function FlipIMG( id )
{
	var imgCurrent = ( ie ) ? document.images( id ) : document.images.namedItem( di );
	var imgNormal = ( ie ) ? document.images( id + "Normal" ) : document.images.namedItem( id + "Normal" );
	var imgInverse = ( ie ) ? document.images( id  + "Inverse" ) : document.images.namedItem( id + "Inverse" );
	imgCurrent.src = ( imgCurrent.src == imgInverse.src )? imgNormal.src : imgInverse.src;
}

 

function GetXPos( id )
{
	var x = 0;

	var parent = GetObject( id );

	//if ( !ie )
	//	parent = parent.item( 0 ).offsetParent;
	
	if ( parent )
	{
		while( parent.offsetParent )
		{
			x += parent.offsetLeft;
			parent = parent.offsetParent;
		}
	}
	
	return x;
}


function GetYPos( id )
{
	var y = 0;

	var parent = GetObject( id );

	if ( parent )
	{
		while( parent.offsetParent )
		{
			y += parent.offsetTop;
			parent = parent.offsetParent;
		}
	}
	
	return y;
}


function Show( id )
{
	var o = GetStyle( id );

	if ( o )
		o.visibility = "visible";

	activeObject = id;
}


function Hide( id )
{
	var o = GetStyle( id );

	if ( o )
		o.visibility = "hidden";

	activeObject = "";
}


function AddFunc( func )
{
	functions[ functions.length + 1 ] = func;
}


function ExecFunc()
{
	for ( var i = 0 ; i < functions.length ; i++ )
		eval( functions[i] );
}
