// gestione schede itinerario

function skipTag( str )
{
	var tmp = str;
	str = "";
	offTagFlag = 1;
	for( i=0; i<tmp.length; i++ )
	{
		if( tmp.charAt(i) == '<' )
			offTagFlag = 0;
		if( tmp.charAt(i-1) == '>' )
			offTagFlag = 1;
		if( offTagFlag == 1 )
			str += tmp.charAt(i);
	}
	
	return( str );
}

function onMseOvrStr( ImgFileName, Dida, W )
{
	if( W > 270 ) W = 270;

	Dida = unescape( Dida );
	top.title.document.picture.src=ImgFileName;
	top.title.document.picture.width=W; 

	// get text element containing dida from menu frame
	tmp = top.title.document.getElementById('dida').firstChild;
	var dida = skipTag( Dida );
	tmp.replaceData(0, tmp.length, dida );
}

function onMseOutStr( )
{
	top.title.document.picture.src='../../img/noimage.gif';
	top.title.document.picture.removeAttribute('width');
	
	// get text element containing dida from menu frame
	tmp = top.title.document.getElementById('dida').firstChild;
	tmp.replaceData(0, tmp.length, 'Nessuna immagine selezionata' );
}

function onMseOvrIdx( Idx )
{
	// for delay in loading page; prevent errors
	if( typeof( eval( 'document.img'+Idx ) ) != "undefined" )
	{
		W = eval( 'document.img'+Idx+'.width' );
		onMseOvrStr( Img[Idx], Dida[Idx], W );
		txt = Idx+' '+'document.img'+Idx+'.width';
	}
}

function onMseOutIdx( )
{
	onMseOutStr();
}


// link from itinerari
function SetImgLink( Idx )
{
  Idx--;

  text = '<a href="" ';
  text += 'onMouseOver="onMseOvrIdx('+Idx+'); return false;" ';
  text += 'onClick="return false;" ';
  text += 'onMouseOut="onMseOutIdx('+Idx+'); return false;">';
  text += '<img src="../img/pict.gif" border="0"></a>';
  text = text+'<span style="font-size:8pt">'+(Idx+1)+'</span>';
  document.write(text);
  return false;
}


function ItiRand()
{
	var Valley = new Array(
		'valletanaro|17',
		'vallemongia|0',
		'vallecasotto|5',
		'vallecorsaglia|7',
		'vallemaudagna|3',
		'valleellero|7',
		'vallepesio|9',
		'vallejosina|0',
		'vallecolla|1',
		'vallevermenagna|7',
		'vallegesso|25',
		'vallestura|24',
		'vallegrana|6',
		'vallemaira|16',
		'vallevaraita|16',
		'vallebronda|0',
		'vallepo|7',
		'valleinfernotto|0'
	);

	var ValleyName, ValleyNum, TrailNum;
	var numiti;
	
	// select the valley
	do
	{
		idx = randInRange( Valley.length );
		buf = Valley[idx].split("|");
		ValleyName = buf[0];
		numiti = buf[1];
	}
	while( numiti == 0);
	
	idx++;
	if( idx < 10 )
		ValleyNum = '0'+idx;
	else
		ValleyNum = idx;

	// select the trail
	idx = randInRange( numiti );
	idx++;
	if( idx < 10 )
		TrailNum = '0'+idx;
	else
		TrailNum = idx;
			
	Link = ValleyName+'/index'+ValleyNum+TrailNum+'.htm';
	
	text = '<a href="itinerari/'+Link+'" class="lnk" target="_top">';
	
	return( text );
}

function randInRange( Range )
{
	rand = Math.random();
	rand *= (Range-0.0001);
	rand = Math.floor( rand );
	return rand;
}


