/*****************************************************
* ypSlideOutMenu
* 3/04/2001
* 
* a nice little script to create exclusive, slide-out
* menus for ns4, ns6, mozilla, opera, ie4, ie5 on 
* mac and win32. I've got no linux or unix to test on but 
* it should(?) work... 
*
* --youngpup--
*
* modified and adapted - 01/07/2007
*****************************************************/

ypSlideOutMenu.Registry = []
ypSlideOutMenu.aniLen = 200
ypSlideOutMenu.hideDelay = 500
ypSlideOutMenu.minCPUResolution = 10

function ypSlideOutMenu( id, dir )
{
	var d = document;
	if ( !d.getElementById ) return;
	
	this.td = d.getElementById( 'ctl00_' + id );
	this.tdClass = this.td.className;

	var table = d.getElementById( 'ctl00_' + id + 'Table' );
	this.width = table.offsetWidth > this.td.offsetWidth || dir == "right-top" || dir == "left-top" ? table.offsetWidth : this.td.offsetWidth;
	this.height = table.offsetHeight;
	table.style.width = this.width + "px";

	this.id = id;
	this.dir = dir;
	this.dirType = dir == "right-top" || dir == "left-bottom" ? "-" : "+";
	this.hideTimer = false;
	this.aniTimer = false;
	this.open = false;
	this.over = false;
	this.startTime = 0;
	this.gRef = "ypSlideOutMenu_" + id;
	eval( this.gRef + "=this" );
	ypSlideOutMenu.Registry[id] = this;

	d.write( '<div id="' + id + 'Shadow" style="visibility: hidden;position:absolute;background-color: #d0d0d0;z-index:100;width:0px;height:0px"></div>' );

	d.write( '<style type="text/css">' );
	d.write( '#' + this.id + 'Container { visibility:hidden; ' );
	d.write( 'overflow:hidden;z-Index:101;top:0px;left:0px }' );
	d.write( '#' + this.id + 'Container, #' + this.id + 'Content { position:absolute; ' );
	d.write( 'width:' + this.width + 'px; ' );
	d.write( 'height:' + this.height + 'px; ' );
	d.write( 'clip:rect(0 ' + this.width + ' ' + this.height + ' 0); ' );
	d.write( '}' );
	d.write( '</style>' );

	this.load();
}

ypSlideOutMenu.prototype.load = function() 
{
	var d = document;
	var obj1 = d.getElementById( this.id + "Container" );
	if ( obj1 ) var obj2 = d.getElementById( this.id + "Content" );
	if ( !obj1 || !obj2 ) 
		window.setTimeout( this.gRef + ".load()", 100 );
	else 
	{
		this.container = obj1;
		this.menu = obj2;
		this.shadow = d.getElementById( this.id + "Shadow" );
		
		this.homePosW = eval( "0" + this.dirType + this.width );
		this.homePosH = -this.height;
		this.outPos = 0;
		this.accelConstW = (this.outPos - this.homePosW) / ypSlideOutMenu.aniLen / ypSlideOutMenu.aniLen ;
		this.accelConstH = (this.outPos - this.homePosH) / ypSlideOutMenu.aniLen / ypSlideOutMenu.aniLen ;
		this.menu.onmouseover = new Function( "ypSlideOutMenu.showMenu('" + this.id + "')" );
		this.menu.onmouseout = new Function( "ypSlideOutMenu.hideMenu('" + this.id + "')" );
		this.endSlide();
	}
}

function getId( id )
{
	var iPos1 = id.lastIndexOf( 'X' );
	var iPos2 = id.lastIndexOf( '_' );
	return iPos1 == -1 || iPos2 > iPos1 ? id : id.substring( 0, iPos1 );
}

function elemInArrayShow( elem, id )
{
	return id.indexOf( elem ) != -1 || elem.indexOf( id ) != -1;
}

ypSlideOutMenu.showMenu = function( id )
{
	var reg = ypSlideOutMenu.Registry;
	var obj = ypSlideOutMenu.Registry[getId( id )];
	if ( !obj || !obj.container ) return;

	obj.over = true;
	for ( menu in reg ) 
		if ( !elemInArrayShow( menu, id ) ) ypSlideOutMenu.hide( menu );
		else if ( reg[menu].hideTimer ) reg[menu].hideTimer = window.clearTimeout( reg[menu].hideTimer );

	if ( !obj.open )
	{
		var coords = getPageCoords( obj.td );

		var left;
		var top;
		switch ( obj.dir )
		{
			case "right-top":
				left = coords.x + obj.td.offsetWidth;
				top = coords.y;
				break;
			case "left-top":
				left = coords.x - obj.width;
				top = coords.y;
				break;
			case "left-bottom":
				left = coords.x;
				top = coords.y + obj.td.offsetParent.offsetParent.offsetHeight;
				break;
			case "right-bottom":
				left = coords.x + obj.td.offsetWidth - obj.width - 2;
				top = coords.y + obj.td.offsetParent.offsetParent.offsetHeight;
				break;
		}

		obj.container.style.left = left + "px";
		obj.container.style.top = top + "px";
		
		if ( obj.dirType == "-" )
		{
			obj.shadow.style.left = (left + 2) + "px";
			obj.shadow.style.top = (top + 2) + "px";
		}
		else
		{
			obj.shadow.style.width = "0px";
			obj.shadow.style.height = "0px";
			obj.shadow.style.left = (coords.x + obj.td.offsetWidth + 2) + "px";
			obj.shadow.style.top = (top + 2) + "px";
		}
		
		if ( reg[id] != undefined ) reg[id].startSlide( true );
	 }
}

ypSlideOutMenu.hideMenu = function( id )
{
	var reg = ypSlideOutMenu.Registry;
	var obj = reg[getId( id )];
	if ( !obj || !obj.container ) return;
	
	for ( menu in reg ) 
	{
		if ( ypSlideOutMenu.Registry[menu].hideTimer ) window.clearTimeout( ypSlideOutMenu.Registry[menu].hideTimer );
		ypSlideOutMenu.Registry[menu].hideTimer = window.setTimeout( "ypSlideOutMenu.hide('" + menu + "')", ypSlideOutMenu.hideDelay );
	}
}

ypSlideOutMenu.hide = function( id )
{
	var obj = ypSlideOutMenu.Registry[id];
	obj.over = false;
	if ( obj.hideTimer ) window.clearTimeout( obj.hideTimer );
	obj.hideTimer = 0;
	if ( obj.open && !obj.aniTimer ) obj.startSlide( false );
}

ypSlideOutMenu.prototype.startSlide = function( open )  
{
	var bMain = this.id.indexOf( '_' ) == -1;
	this.td.className = open ? (bMain ? "hmenumainover" : "hmenuitemover") : (bMain ? this.tdClass : "hmenuitem");
	
	this[open ? "onactivate" : "ondeactivate"]()
	this.open = open;
	if ( open ) this.setVisibility( true );
	this.startTime = (new Date()).getTime();
	this.aniTimer = window.setInterval( this.gRef + ".slide()", ypSlideOutMenu.minCPUResolution );
}

ypSlideOutMenu.prototype.slide = function() 
{
	var elapsed = (new Date()).getTime() - this.startTime;
	if ( elapsed > ypSlideOutMenu.aniLen ) 
		this.endSlide();
	else
	{
		var dW = Math.round( Math.pow( ypSlideOutMenu.aniLen-elapsed, 2 ) * this.accelConstW );
		var dH = Math.round( Math.pow( ypSlideOutMenu.aniLen-elapsed, 2 ) * this.accelConstH );
		if ( this.open ) { dW = -dW; dH = -dH; }
		else if ( !this.open && this.dirType == "-" ) { dW = -this.width + dW; dH = -this.height + dH; }
		else { dW = this.width + dW; dH = -this.height + dH; }
		this.moveTo( dH, dW );
	}
}

ypSlideOutMenu.prototype.endSlide = function() 
{
	this.aniTimer = window.clearTimeout( this.aniTimer );
	this.moveTo( this.open ? this.outPos : this.homePosH, this.open ? this.outPos : this.homePosW );
	if ( !this.open ) this.setVisibility( false );
	if ( this.open && !this.over || !this.open && this.over )
		this.startSlide( this.over );
}

ypSlideOutMenu.prototype.setVisibility = function( bShow ) 
{ 
	this.container.style.visibility = bShow ? "visible" : "hidden";
	this.shadow.style.visibility = bShow ? "visible" : "hidden";
	if ( !bShow )
	{
		this.shadow.style.left = "0px";
		this.shadow.style.top = "0px";
	}
}

ypSlideOutMenu.prototype.moveTo = function( t, l ) 
{ 
	this.menu.style.top = t + "px";
	this.menu.style.left = l + "px";
	
	if ( this.dirType == "+" )
	{
		var left = this.container.style.left;
		left = left.substring( 0, left.length - 2 );
		if ( left != "" )
			this.shadow.style.left = (l != 0 ? (parseInt( left ) + l + 2) : (parseInt( left ) + 2)) + "px";
		this.shadow.style.width = (l != 0 || this.open ? this.width - l : this.width) + "px";
		var height = this.height + t;
		if ( height < 0 ) height = 0;
		this.shadow.style.height = height + "px";
	}
	else
	{
		var width = this.width + l;
		if ( width < 0 ) width = 0;
		this.shadow.style.width = width + "px";
		var height = this.height + t;
		if ( height < 0 ) height = 0;
		this.shadow.style.height = height + "px";
	}
}

ypSlideOutMenu.prototype.getPos = function( c ) 
{
	return parseInt( this.menu.style[c] );
}

ypSlideOutMenu.prototype.onactivate = function() 
{ 
}

ypSlideOutMenu.prototype.ondeactivate = function() 
{ 
}

function getPageCoords( element )
{ 
	var coords = {x: 0, y: 0} 
	while ( element ) 
	{ 
		coords.x += element.offsetLeft; 
		coords.y += element.offsetTop; 
		element = element.offsetParent; 
	} 
	return coords; 
} 

function getHref( obj )
{
	for ( var i = 0; i < obj.childNodes.length; i++ )
		if ( obj.childNodes[i].tagName == "A" )
			return obj.childNodes[i].href;
	return "";
}

function PrintMode()
{
	var main = document.getElementById( 'MainTable' );
	main.rows[0].style.display = 'none';
	main.rows[1].style.display = 'none';
	main.rows[2].cells[0].style.display = 'none';
	main.rows[2].cells[2].style.display = 'none';
	main.rows[3].cells[0].style.display = 'none';
	main.rows[4].style.display = 'none';
	main.width = '100%';
//	this.document.body.style.backgroundColor = '#f0f0f0';
	main.rows[2].cells[1].style.width = '';
	main.rows[2].cells[1].style.backgroundColor = '';
	
	var objs = document.getElementsByTagName( 'A' );
	for ( i = 0; i < objs.length; i++ )
	{
		objs[i].href = 'javascript:void(0)';
		objs[i].style.textDecoration = 'none';
		objs[i].style.cursor = 'default';
	}
	aspnetForm.onclick = function() { return false; }

	objs = document.getElementsByTagName( 'SELECT' )
	for ( i = 0; i < objs.length; i++ )
		objs[i].disabled = true;
}

function PrintPage( url )
{
	window.open( url, null, 'status=no,toolbar=yes,menubar=no,location=no' );
}

function sendTo()
{
	var mail = "mailto:xxchiocciolaxx.it";
	mail = mail.replace( /xx/g, "myjuve" );
	mail = mail.replace( /chiocciola/g, "@" );
	window.open( mail );
}

function urlFind()
{
	var txt = document.getElementById( 'ctl00_txtFindPlayer' );
	if ( txt.value == '' ) return '';

	return ctl00_menu9Table.rows[0].cells[0].childNodes[0].href + "?surname=" + txt.value;
}

function clickFind()
{
	var url = urlFind();
	if ( url != '' ) document.location.href = url;
}

function mouseOverFind()
{
	document.getElementById( 'ctl00_imgFindPlayer' ).style.cursor = document.getElementById( 'ctl00_txtFindPlayer' ).value == '' ? 'default' : 'pointer';
}

function keyPressFind()
{
	var e = window.event;
	if ( e.keyCode == 13 )
	{
		e.cancelBubble = true;
		if ( e.stopPropagation ) e.stopPropagation();
		e.keyCode = 10;
		clickFind();
	}
}