if (window.adsIn!=1){adsIn=1
var adsCp=0,adsLo=location.href,adsInd=adsLo.indexOf('atwCrPr=')
if (adsInd>0)adsCp=1
var adsHt="http://ar.atwola.com",adsD=new Date(),adsTz="&TZ="+adsD.getTimezoneOffset(),adsScr=adsD.getTime()%0x3fffffff,adsTar='_top',adsTpSet=0,adsExt='aol',adsTp='J',adsSL="<SCRIPT LANGUAGE='JavaScript' SRC='"
var adsDel=0,adsDel1=0,adsOld=1,adsNMSG,adsNG,adsNM,adsSr="",adsScS='',adsOt='',adsSN='',adsESN='',adsWM='',adsIP=" SCROLLING=NO FRAMEBORDER=0 MARGINHEIGHT=0 MARGINWIDTH=0></IFRAME>"
var adsNv=navigator,adsAN=adsNv.appName,adsAVA=adsNv.appVersion,adsAV=parseInt(adsAVA),adsUA=adsNv.userAgent,adsLNm=0,adsLMN=new Array(),adsCo=new Array(),adsCN=0
var adsAH1="<A HREF='",adsAH2="/"+adsScr+ "/",adsOne=0,adsI1="<IMG SRC=",adsI2="/"+adsScr +"/",adsI3=" BORDER=0 ALT=\"Advertisement\"></A>",adsDOth='',adsTile=1,adsInt=0
var adsIE=(adsAN=="Microsoft Internet Explorer"),adsNS=(adsAN=="Netscape"),adsN4=(adsNS&&adsAV==4),adsN6=(adsNS&&adsAV>=5),adsOp=(adsUA.indexOf("Opera")!=-1)
var adsPage='',adsDivs=new Array(),adsFAd=''
var adsUAL=adsUA.toLowerCase(),adsAppVer=navigator.appVersion.toLowerCase(),adsMin='',adsMac=(adsUAL.indexOf("mac")!=-1),adsIEP=adsAppVer.indexOf('msie'),adsIE6=''
if (adsIEP!=-1){if(adsMac){adsIEP=adsUAL.indexOf('msie')
adsMin=parseFloat(adsUAL.substring(adsIEP+5,adsUAL.indexOf(';',adsIEP)))}else{
adsMin=parseFloat(adsAppVer.substring(adsIEP+5,adsAppVer.indexOf(';',adsIEP)))}}
if ((adsIE)&&(parseInt(adsMin)>=6)){adsIE6=1}
if (((adsNS||adsIE)&&adsAV>=4)&&!adsN4&&!adsOp){adsOld=0}
function adsClFn(z){if (window.adsCol0)return eval('window.adsCol'+z)
else return('<!---->')}
function adSetRotate(){}
function adSetDelay(v){if (!adsOp){adsDel=escape(v);if (adsDel>0){adsDel1=1}}}
function adSetBucketMN(){}
function adSetHtNm(v){adsHt=(v.indexOf('http')==-1?"http://"+v:v)
if (v.indexOf('ar5')>=0||v.indexOf('ar6')>=0||v.indexOf('ar7')>=0||v.indexOf('ar8')>=0||v.indexOf('ar9')>=0){if (!adsTpSet){adsTp=''};adsInt=1}}
function adSetTarget(v){adsTar=escape(v)}
function adSetSN(v){adsSN='&SN='+escape(v)}
function adSetWM(v){adsWM='&WM='+escape(v)}
function adSetNewMedia(v){adsNM=escape(v);adsNMSG=(v!=''?"NM="+adsNM:"")}
function adSetExt(v){adsExt=escape(v)}
function adSetOthDclk(v){if(adsDOth==''){adsDOth='&dclkOther='+escape(v)}else{
if ((adsDOth.indexOf('rsi')==-1)||(v.indexOf('rsi=')==-1)){adsDOth+=escape(v)}}}
function adRSI(x){var c=document.cookie,q="",b=c.indexOf('rsi_segs=')
if(b>=0){b=c.indexOf('=',b)+1
if(b>0){var e=c.indexOf(';',b)
if(e==-1)e=c.length
var s=c.substring(b,e).split('|')
for (j=0;j<Math.min(x,s.length);j++){
q+=s[j].replace(/.*_(.*)/,"rsi=$1;")}}}
if (q!="")adSetOthDclk(q)
b=c.indexOf('RSP_COOKIE=')
if(b>=0){b=c.indexOf('&name=',b)+6
if(b>0){var e=c.indexOf(';',b)
var e1=c.indexOf('&',b)
if (e1<e)e=e1
if(e==-1)e=c.length
adsESN='&ESN='+c.substring(b,e)}}}
adRSI(30)
function adSetSearch(v){if (v){v=v.replace(/\+/g,' ');adsSr=(v!=''?(window.encodeURIComponent)?"&search="+encodeURIComponent(v):"&search="+escape(v):"")}}
function adSetType(v){if (v==''&&!adsInt)v='J'
adsTp=v.toUpperCase()
adsTpSet=1}
function adSetOther(v){adsOt=v}
function adSetSearchCat(v){}
function adsCkPlg(){
var e='</',ie=0,dc=document,dl=dc.layers,da=dc.all,dg=dc.getElementById,n=navigator,db=dc.body
var cid='componentid',beh='url(#default#clientCaps)',ie5=da&&dg,go=(da||dl||(dg&&!da))
if (adsUA.indexOf('MSIE')!=-1&&adsUA.indexOf('Win')!=-1){ie=1
var d=document.writeln
d('<script language="VBscript">')
d('Dim adsVB,po')
d('adsVB=0')
d('If ScriptEngineMajorVersion >=2 then adsVB=1')
d('Function adsAX(aX)')
d('on error resume next')
d('If adsVB=1 then')
d('adsAX=False')
d('set po=CreateObject(aX)')
d('adsAX=IsObject(po)')
d('If (err) then adsAX=False')
d('Else')
d('adsAX=False')
d('End If')
d('End Function')
d(e+'script>')}
var i,u=0,dF='',fS,p=n.plugins
if (ie&&window.adsVB){u=0}else{u=1}
if (p){var l=p.length
if (l>1){var m=n.mimeTypes,fl=m['application/x-shockwave-flash']
if (m&&((fl&&fl.enabledPlugin&&(fl.suffixes.indexOf('swf')!=-1)))){
var ds,f="Flash ",nm
if (adsNS&&(n.appVersion.indexOf('4.0')!=-1)){
for(i in p){
ds=p[i].description,fS=ds.indexOf(f)
if (fS!=-1){if (ds.substring(fS+6,fS+7)>=6){dF='F'}}}}else{
for (i=0;i<l;i++){
ds=p[i].description,nm=p[i].name
fS=ds.indexOf(f)
fN=nm.indexOf(f)
if (fS!=-1){if (ds.substring(fS+6,fS+7)>=6){dF='F'}else if (fN!=-1){if (nm.substring(fN+6,fN+7)>=6){dF='F'}}}}}
if (fl==null)dF=''
}}else if(ie==1&&!u){if (!ie5||adsUA.indexOf('NT')!=-1){fS="ShockwaveFlash.ShockwaveFlash."
dF=(adsAX(fS+"6")?'F':'')
if (!dF){dF=(adsAX(fS+"7")?'F':'')}
if (!dF){dF=(adsAX(fS+"8")?'F':'')}}}else{dF=''}
}else{dF=''}
if (go){if (n.platform=='Win32'){
if (ie5&&(db!=null)){db.style.behavior=beh
var fC='{D27CDB6E-AE6D-11CF-96B8-444553540000}',fV=db.getComponentVersion(fC,cid)
if (fV.charAt(0)>=6){dF='F'}}}}
adsNMSG="SNM=HIBV"+((!adsN4&&dF)?'D':'')+dF}
function adsGetAdURL(w){var d=w.frameElement.parentNode
return d.adURL}
function adsLoadAd(){var ifr=document.createElement('iframe')
ifr.id="adFr"
ifr.marginWidth=0
ifr.marginHeight=0
ifr.frameBorder=0
ifr.scrolling="no"
ifr.width="1px";
ifr.height="1px"
ifr.divName=this.divName
this.appendChild(ifr)
ifr.src=this.adPage}
function adSetupDiv(w,h,adURL,dv1,adPage){
if (typeof(dv1)!='object')var dv=document.getElementById(dv1)
else var dv=dv1
dv.LoadAd=adsLoadAd
dv.adURL=adURL
dv.adPage=adPage
dv.divName=dv1
dv.w=w
dv.h=h
adsDivs[adsDivs.length]=dv}
function htmlAdWH(m,w,h,t,divName,fName){if (t)t=t.toLowerCase()
var d=document,ah=adsExt+"' TARGET="+adsTar+">",p=" WIDTH="+w+" HEIGHT="+h,l=adsAH1+adsHt+"/link/"+m+adsAH2+ah,c='adsCo'
var p1=adsTz+adsSr+adsSN+adsESN+adsWM+adsOt+adsDOth,i1=adsI1+adsHt+"/image/"+m+adsI2+adsExt+"?"+p1+"'"+p+adsI3,j,r=0
if (adsCp){var ca=adsLo.substr(adsInd+8).split('|'),cF=new Array(),cW=new Array(),cH=new Array(),cAd=new Array(),k=0
for (var i=0;i<ca.length;i=i+4){cF[k]=ca[i];cW[k]=ca[i+1];cH[k]=ca[i+2];cAd[k++]=ca[i+3]}
for (var i=0;i<cF.length;i++){if ((cW[i]==w&&cH[i]==h)||(cAd[i]==adsTile)){
if (adsTp!='J'){d.write('<IFRAME SRC="'+cF[i]+'.html" WIDTH='+w+' HEIGHT='+h+adsIP)}
else{d.write(adsSL+cF[i]+".js'></SCRIPT>")}r=1
break}}}
if (r==0){if (!adsOld){if (!adsNMSG){if (!adsNG){adsCkPlg()
adsNG=adsNMSG}else{adsNMSG=adsNG}}
var s=adsHt+"/html/"+m+"/"+adsScr+"/"+adsExt+"?"+adsNMSG+"&width="+w+"&height="+h+"&target="+adsTar+"&tile="+adsTile+p1+"&CT=",ie4=(adsAVA.indexOf('MSIE 4')!=-1)
j=c+adsCN
if ((((t=='c'||t=='text')&&((adsN6&&(adsUA.indexOf('rv:0')!=-1||adsUA.indexOf('Safari')!=-1))||ie4||(adsAVA.indexOf('MSIE 5.0')!=-1))))||(ie4&&t=='d')||adsN4||(t=='text'&&adsIE&&!adsIE6)){
adsTp='J',t=''}
if(t=='c'&&adsInt){d.write ('<IFRAME ID="'+j+'" NAME="'+j+'" SRC="about:blank" HEIGHT=0 WIDTH=0'+adsIP)
adsCo[adsCN++]=s+"|"+w+"|"+h}
else if(t=='d'&&adsInt){d.write('<DIV ID="'+j+'" NAME="'+j+'"></DIV>')
adsCo[adsCN++]=s+"|T"}
else if (t=='text'){adSetupDiv(w,h,s+"J&hw=docw",divName,fName)
adsDivs[adsDivs.length-1].LoadAd()}
else{if (adsTp!='J'&&!adsN4){var x="<IFRAME NAME='adsF"+adsLNm+"' ID='adsF"+adsLNm+"' SRC="
if (adsDel==0){d.write(x+s+"I"+p+adsIP)}else{d.write(x+"''"+p+adsIP)
adsLMN[adsLNm]="adsF"+adsLNm+"|"+s+"I"}adsLNm++
}else if(adsTp=='J'||(adsTp.indexOf('I')==-1&&adsN4)){
d.write(adsSL+s+"J&hw=docw'></SCRIPT>")}else{d.write(l+i1)}}}
else{d.write(l+i1)}}adsTile++}
function imageAdWH(m,w,h){var s=adsHt+"/image/"+m+adsI2+adsExt+"?"+adsTz+adsSr+adsSN+adsESN+adsWM+"&tile="+adsTile+adsOt+adsDOth,p=" HEIGHT="+h+" WIDTH="+w+adsI3,d=document
d.write(adsAH1+adsHt+"/link/"+m+adsAH2+adsExt+"' TARGET="+adsTar+">")
if (!adsDel||adsOld){d.write(adsI1+s+p)
}else{d.write(adsI1+adsHt+"/file/blank.gif NAME=adsImg"+adsLNm+p)
adsLMN[adsLNm]="adsImg"+adsLNm+"|"+s
adsLNm++}adsTile++}
function adsEndFn(){}}

var arrayDayNames = new Array("Domenica", "Luned&igrave;", "Marted&igrave;", "Mercoled&igrave;", "Gioved&igrave;", "Venerd&igrave;", "Sabato");
var arrayMonthNames = new Array("January", "February", "March", "April", "May", "June", "July", "Agosto", "Settembre", "Ottobre", "Novembre", "Dicembre"); 

tii_addEventHandlerOnElementLoad ( 'query', 'click', function (event){
			var qBox = typeof event.target != 'undefined' ? event.target : window.event.srcElement;				
			qBox.style.color = '#000';
																 }, false);
var keyevent = tii_issafari || tii_isie ? 'keydown' : 'keypress';
tii_addEventHandlerOnElementLoad ( 'query', keyevent, 
		function (event){
			var qBox = typeof event.target != 'undefined' ? event.target : window.event.srcElement;				
			qBox.style.color = '#000';
			}, false);

/* Start the setMover function on window load */
tii_callFunctionOnWindowLoad (function ()
{
	setMover ();
});


/* Begin Date function */
function getDateCurrent () {
    var today = new Date() 
    var day = (today.getDay());	
		
    var monthName_List = new Date()
    monthNumber = (today.getMonth());
	
    dayNumber=today.getDate();
    if(dayNumber < 10){
        dayNumber="0" + dayNumber;
    } 
    var yearNumber = today.getYear();
    if(yearNumber < 1000) {
        yearNumber+=1900;
    }
	if (document.getElementById('print'))
	{
	document.write(arrayMonthNames[monthNumber] + " " + dayNumber + ", " + yearNumber);
	}
	else
	{
    /* document.write(arrayDayNames[day] + ", " + arrayMonthNames[monthNumber] + " " + dayNumber + ", " + yearNumber);	*/
	document.write(arrayDayNames[day] + ", " + dayNumber + " " + arrayMonthNames[monthNumber] + " " + yearNumber);	
	}
} 
/* End Date function */

/* Begin Clear field function */
/* Clears input text on focus and resets to default text if no text is entered */
function clearField(status) 
{
	var srch = document.getElementById('query');
		if ((srch.value == srch.defaultValue) && (status == 'on'))
		{
			srch.value = '';
		}
		if ((srch.value == '') && (status == 'off'))
		{
			srch.value = srch.defaultValue;
		}
} 
/* End Clear field function */

/* Links the elements of the select tag to their specific URLs */
/* Begin Go To Specials function */
	function gotoSpecials() 
	{
	document.location.href = document.frmSpecials.selSpecials.options[document.frmSpecials.selSpecials.selectedIndex].value;
	}
/* Begin Go To Specials function */

/* Belt animation */

var moveTouts;

/* This function sets the belt mover. */
function setMover ()
{
	var toutsPerShow = 5;
	var moveDelay = 1;
	var widthTraversed = 0;
	var toutTracker = 0;
	var toutCount = 0;
	var directionChangeMultiplier;
	if (tii_isie)
	{
		directionChangeMultiplier = 20;
	}
	else
	{
		directionChangeMultiplier = 40;
	}

	var dotNumber = 2;
	
	var mover = document.getElementById ('mover');
	if (!mover)
	{
		return false;
	}
	mover.style.left = '0px';
	
	/* The next line assumes that all the child nodes of mover are touts. */
	tii_dom_removeWhitespaceTextNodes (mover);
	var beltTouts = mover.childNodes;
	var beltToutsLength = beltTouts.length;
	var beltToutWidth;
	if (beltToutsLength > 0)
	{
		beltToutWidth = beltTouts.item (0).offsetWidth;
	}
	else 
	{
		return false;
	}
	var visibleWidth = toutsPerShow * beltToutWidth;
	
	function moveBelt (event, directionChange)
	{
		if ((event.type == keyevent && event.keyCode != 13) || widthTraversed > 0)
		{
			return false;
		}
		
		function recirculateTouts ()
		{
			if (directionChange > 0)
			{
				if (Math.ceil (toutTracker / beltToutWidth) > 0 )
				{
					toutTracker = toutTracker - beltToutWidth;
					var clonedTout = beltTouts.item (beltToutsLength - 1).cloneNode (true);
					mover.insertBefore (clonedTout, mover.firstChild);
					mover.removeChild(beltTouts.item (beltToutsLength));
					toutCount++;
		}
			}
			if (directionChange < 0)
			{
				if (Math.floor (toutTracker / beltToutWidth) > 0)
				{
					toutTracker = toutTracker - beltToutWidth;
					var clonedTout = mover.childNodes[0].cloneNode (true);
					mover.appendChild (clonedTout);
					mover.removeChild (mover.childNodes[0]);
					mover.style.left = '0 px';
					toutCount++;
				}
			}
		}
		
		moveTouts = setInterval (function () 
		{
			widthTraversed = widthTraversed + directionChangeMultiplier;
			toutTracker = toutTracker + directionChangeMultiplier;
			
			//mover.style.left = (parseInt (mover.style.left) + directionChange * directionChangeMultiplier) + 'px';
			recirculateTouts ();
			if (toutCount >= toutsPerShow)
			{
				/* Stop the animation */
				clearInterval (moveTouts);
				
				/* Set the active button */
				if (dotNumber == 1)
				{
					dotNumber = 2;
				}
				else
				{
					dotNumber = 1;
				}
				
				var dot = document.getElementById ('dots')				
				if (!tii_isie){
					dot.style.background= 'url(http://img.timeinc.net/time/i/dots' + dotNumber + '.gif) 0px 0px no-repeat';
				}else{
					dot.style.backgroundPositionY =  (dotNumber*13 -26) + ' px';
				}

				/* Reinitialize the variables */
				mover.style.left = '0px';
				beltTouts = mover.childNodes;
				widthTraversed = 0;
				toutCount = 0;
			}
		}, moveDelay);
		
		tii_stopDefaultAction (event);
	}
	
	var leftArrow = document.getElementById ('leftArrow');
	var rightArrow = document.getElementById ('rightArrow');
	if (!leftArrow || !rightArrow)
	{
		return false;
	}
	leftArrow.href = 'javascript:{}';
	rightArrow.href = 'javascript:{}';
	var keyevent = tii_issafari || tii_isie ? 'keydown' : 'keypress';
	tii_addEventHandler (leftArrow, 'click', function (event) { moveBelt (event, 1)}, false);
	tii_addEventHandler (leftArrow, keyevent, function (event) { moveBelt (event, 1)}, false);
	tii_addEventHandler (rightArrow, 'click', function (event) { moveBelt (event, -1)}, false);
	tii_addEventHandler (rightArrow, keyevent, function (event) { moveBelt (event, -1)}, false);
}

function tiiQuigoSetEnabled(b) {
	_tiiQuigoEnabled = b;
}

function tiiQuigoIsEnabled() {
	if (typeof(_tiiQuigoEnabled) == "boolean") {
		return _tiiQuigoEnabled;
	}
	return true;
}

function tiiQuigoWriteAd(pid, placementId, zw, zh, ps) {
	if (tiiQuigoIsEnabled()) {
		qas_writeAd(placementId, pid, ps, zw, zh, 'ads.adsonar.com');
	}
}
//for ad tag migration
var adConfig = new TiiAdConfig("3475.tim"); 
adConfig.setCmSitename("cm.tim");

/* Attaching event handlers to elements */
var clickToggle = true; 
tii_addEventHandlerOnElementLoad ('bubbleLink', 'mouseover', function (event){displayBubble(event);}, false);
tii_addEventHandlerOnElementLoad ('bubbleLink', 'mouseout', function (event){hideBubble(event);}, false);
tii_addEventHandlerOnElementLoad ('bubbleLink', 'keypress' , function (event){displayBubble(event);}, false); 
tii_addEventHandlerOnElementLoad ('bubbleLink', 'blur', function (event){hideBubble(event);}, false);

/* Thought Bubble for The Ag */
function displayBubble(event){
	
	bubLink = document.getElementById('bubbleLink');
	bub = document.getElementById('bubble');
	var bubPos = new Array(2);
	bubPos = findPos(bubLink);

	/*  Check for IE */
	if (tii_isie) 
	{
		bub.style.left = (parseInt(bubPos[0]) - 162).toString() + 'px';
		bub.style.top = (parseInt(bubPos[1]) +  25).toString() + 'px';	
	}
	else
	{
		bub.style.left = (parseInt(bubPos[0]) - 176).toString() + 'px';
		bub.style.top = (parseInt(bubPos[1]) +  26).toString() + 'px';	
	}
	
	/* Display the bubble */
	bub.style.display = 'block';
	clickToggle = false;
}

/* Hides the bubble */
function hideBubble(event){
/*	alert ('test');*/
	var bub = document.getElementById('bubble');	
	bub.style.display = 'none';
	clickToggle = true;
}

/* Finds the position of an element on the page */
function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}

/* Begin TimeStamp function */
function renderTimestamp(year,month,day,hour,minutes,seconds) 
{
    var aYear = new String(year);
    var aMonth = new String(month);
    var aDay = new String(day);
    var aHour = new String(hour); 
    var aMinutes = new String(minutes);
    var aSeconds = new String(seconds); 
    articleUTC = Date.UTC(aYear, aMonth, aDay, aHour, aMinutes, aSeconds);

    /* this is EST timezone offset of 5 hours = 300 minutes
    all Time articles are published in EST */
    articleTZOffsetMS = 300 * 60 * 1000 ; 
    articleCorrectedMS = articleUTC + articleTZOffsetMS;

    localDate = new Date();
    localYear = localDate.getFullYear();
    localMonth = localDate.getMonth(); 
    localDay = localDate.getDate(); 
    localHour = localDate.getHours();
    localMinutes = localDate.getMinutes();
    localSeconds = localDate.getSeconds();
    localTZOffset = localDate.getTimezoneOffset();
    //localTZOffsetMS = localTZOffset * 1000* 60; 
    localTZOffsetMS = 300 * 1000* 60;    localUTC = Date.UTC(localYear, localMonth, localDay, localHour, localMinutes, localSeconds); 

    localCorrectedMS = localUTC + localTZOffsetMS;

    // calculate how many minutes between article utc and user utc 
    minuteDifferential = (localCorrectedMS - articleCorrectedMS)/(1000 * 60);
    ageInMinutes = Math.round(minuteDifferential);
 
 if (ageInMinutes < 0) { ageInMinutes = 0;} 

    if ( ageInMinutes < 15 ) {
        document.write("<span>UPDATED:</span> "+ ageInMinutes +" minutes ago"); 
    } else {
        if (hour >= 12) {
            if (hour != 12) {aHour = aHour - 12;} 
            ampm = "PM";
        } else {
            ampm = "AM";
        }
        if (aMinutes < 10) {aMinutes = "0" + aMinutes} 
        document.write(aHour+":" + aMinutes + ampm + " ET"); 
    }
}
/* End TimeStamp function */
/* Begin Main story module */
var currPic=0;
var timer1, timer2;
var paused = true;
var opacity = 100;
var msDivs = new Array(5);
var msButtons = new Array(5); 
var msWrap;
var button;
var position;
var currPosition;

function initPageComponents() {
 /*  Used to load all components on the page */
 msDivs[0] = document.getElementById('mainStory1');
 msDivs[1] = document.getElementById('mainStory2');
 msDivs[2] = document.getElementById('mainStory3');
 msDivs[3] = document.getElementById('mainStory4');
 msDivs[4] = document.getElementById('mainStory5');
 msButtons[0] = document.getElementById('a1'); 
 msButtons[1] = document.getElementById('a2');
 msButtons[2] = document.getElementById('a3');
 msButtons[3] = document.getElementById('a4');
 msButtons[4] = document.getElementById('a5'); 
 msWrap = document.getElementById('mainStoryWrap');
 initPausePlayEvents();
 var breakingNews = document.getElementById('breakingNewsImg'); 
 if (breakingNews == null)
 {
  paused = false; 
  timer1=setTimeout('timedStory()',7000);
 }
   doImageSwap();
}

function initPausePlayEvents() {
 /* add Event Handlers for the Photo Module */
 if (!document.getElementById || !document.getElementsByTagName) {
  return true;
 }
 /* checks for Javascript operability  */ 

 /*  get all the links in the photo module  */
 var topStories = document.getElementById('topStories');
 var links = topStories.getElementsByTagName('a');

 for (i=0;i < links.length; i++) {
  if (links.item(i).id.substring(0,1) == 'a'){  
   //filter the links for those that have a class name beginnig with 'a'
   //add the doNumber event handler for the number links
   links.item(i).href='javascript:{}';
   tii_addEventHandler (links [i], 'click', function (event)
   {
    doNumber (event);
   }, false);
  }
 }
 
 var playLink = document.getElementById('playLink');
  
 //add the doButton event handler for the play pause button 
 tii_addEventHandler ( playLink , 'click', function (event)
 {
  doButton (event);
 }, false);
}

/* helper function to deal specifically with images and the cross-browser differences in opacity handling */
function fader(opac) {
 if (msWrap.style.MozOpacity!=null) {  
  /* Mozilla's pre-CSS3 proprietary rule */ 
  msWrap.style.MozOpacity = (opac/100) - .001;
 } else if (msWrap.style.opac!=null) {
  /* CSS3 compatible */
  msWrap.style.opacity = (opac/100) - .001;
 } else if (msWrap.style.filter!=null) {
  /* IE's proprietary filter */ 
 if (opac==100){
  msWrap.style.filter = "none;";
 } else {
  msWrap.style.filter = "alpha(opacity="+opac+");";
      }
 }
}

function change(num, step) {
 /*fadeOut*/
 if (step == 1) {
  opacity -= 10;
  if (opacity > 0) {
   fader(opacity);
   timer2=setTimeout('change(' + num + ', 1)',50);
  }
  else { 
   change(num, 2);
  }
 }
 /*change picture*/
 else if (step == 2) {
  currPic = num;
  msDivs[0].style.display = (num == 0 ? "block" : "none"); 
  msDivs[1].style.display = (num == 1 ? "block" : "none"); 
  msDivs[2].style.display = (num == 2 ? "block" : "none");
  msDivs[3].style.display = (num == 3 ? "block" : "none");
  msDivs[4].style.display = (num == 4 ? "block" : "none"); 
  msButtons[0].className = (num == 0 ? "on" : "off");
  msButtons[1].className = (num == 1 ? "on" : "off");
  msButtons[2].className = (num == 2 ? "on" : "off"); 
  msButtons[3].className = (num == 3 ? "on" : "off");
  msButtons[4].className = (num == 4 ? "on" : "off");
  change(num, 3);
 }
 /*fadeIn*/
 else if (step == 3) { 
  opacity += 10;
  if (opacity <= 100) {
   fader(opacity);
   timer2=setTimeout('change(' + num + ', 3)',50);
  }
 }
}

/* change picture, wait 5 seconds, repeat */
function timedStory() {
 if (currPic<4){
 currPic++;
 change(currPic, 1);
 timer1=setTimeout('timedStory()',7000);
 }else{
	 currPic=0;
	clearTimeout(timer1);
	change(currPic,1);
	paused = true;
	doImageSwap();
 }
}

/* executed when the play pause button is selected */
function doButton(event) {
 paused = !paused;
 doImageSwap();
 if (paused) {
  /* stop the image loop */
  clearTimeout(timer1);
 }
 else { 
  /* restart the image loop */
  timedStory();
 }
}  


/*executed when a number link is selected */
function doNumber (event) {
 var eventSource = typeof event.target != 'undefined' ? event.target : window.event.srcElement;
 /*  get the number portion of the class name of the event source */ 
 currPic = eventSource.id.substring(1,2) - 1;
 paused = true;
 doImageSwap();
 clearTimeout(timer1);
 clearTimeout(timer2);
 change(currPic, 1);

} 

/* swap the play pause button image */
function doImageSwap() {
		 var button = document.getElementById('playLink'); 
		 if (!tii_isie){
		  var imageFile = paused ? "images/btn_play.gif" : "images/btn_pause.gif";
		  button.style.background= "url("+imageFile+") 0px 0px no-repeat"; 	
		 }else{
		  /*  Use an image sprite to deplete the image flickering in IE */
		  button.style.backgroundImage= "url(http://www.giocoegiochi.com/images/btn_playpause.gif)";
		  position = paused ? "-21 px" : "0 px";  /* change the image source */
		  try {
			  document.execCommand('BackgroundImageCache', false, true);
			} catch(e) {}
				
			  /* if paused and play is not displayed */
			  if (paused == true && currPosition != "-21 px"){
				  button.style.backgroundPositionY=position;
			  }
			  /* if playing and paused is not displayed */
			  if (paused != true && currPosition != "0 px"){
				  button.style.backgroundPositionY=position;			  
			 }  
		 currPosition = position;
		 }
}  
/* End Main story module */

// TII Ads - Version 1.0.2 - 2007.05.24

function TiiAdConfig(sitename) {
	this.sitename	= sitename;
	this.cmSitename	= sitename;

	this.setSitename	= TiiAdConfigSetSitename;
	this.setCmSitename	= TiiAdConfigSetCmSitename;
}

function TiiAdConfigSetSitename(value) {
	this.sitename = value;
}

function TiiAdConfigSetCmSitename(value) {
	this.cmSitename = value;
}

function TiiAdFactory() {
	// Detect if first agument is a string or an array
	var first = arguments[0];

	if (typeof(first) == "string") {
		this.sitename		= first;
		this.cmSitename		= first;

	} else if (typeof(first) == "object") {
		this.sitename		= first.sitename;
		this.cmSitename		= first.cmSitename;
	}

	if (TiiAd_isSecure()) {
		this.adServer		= "https://ad.doubleclick.net/";
	} else {
		this.adServer		= "http://ad.doubleclick.net/";
	}
	
	this.randomNumber	= TiiAdsGetRandomNumber();
	this.tileCounter	= 1;
	this.params		= new Array();
	this.zone		= "";
	this.dcopt		= false;
	
	if (arguments.length == 2) {
		this.zone = arguments[1];
	}
	
	this.createAd		= TiiAdFactoryCreateAd;
	this.getAd		= TiiAdFactoryGetAd;
	this.getCmAd		= TiiAdFactoryGetCmAd;
	this.getMultiAd		= TiiAdFactoryGetMultiAd;
	this.getTransitionalAd	= TiiAdFactoryGetTransitionalAd;
	this.setArticleId	= TiiAdFactorySetArticleId;
	this.setChannel		= TiiAdFactorySetChannel;
	this.setChannelPage	= TiiAdFactorySetChannelPage;
	this.setContentPage	= TiiAdFactorySetContentPage;
	this.setContentType	= TiiAdFactorySetContentType;
	this.setPackageId	= TiiAdFactorySetPackageId;
	this.setParam		= TiiAdFactorySetParam;
	this.setSubchannel	= TiiAdFactorySetSubchannel;
	this.setZone		= TiiAdFactorySetZone;
}

function TiiAdFactorySetParam(key, value) {
	if (typeof(value) == "object") {
		this.params[key] = value;
	} else {
		if (value.toString() != "") {
			this.params[key] = value;
		}
	}
}

function TiiAdFactoryCreateAd() {
	var width, height, zone, ad;

	if (arguments.length == 2) {
		width = arguments[0];
		height = arguments[1];

	} else {
		// Assume 3 arguments
		width = arguments[0];
		height = arguments[1];
		zone = arguments[2];

	}

	ad = new TiiAd(this, width, height, this.tileCounter);

	if (null != zone) {
		ad.setZone(zone);
	}

	// Copy Factory params to this specific ad
	for (var key in this.params) {
		ad.setParam(key, this.params[key]);	
	}

	ad.setParam("sz", width + "x" + height);

	var paths = window.location.pathname.split("/");
	paths = paths.slice(1, paths.length - 1);
	ad.setParam("path", paths);
	
	ad.setParam("dcove", "d");

	this.tileCounter++;

	return ad;
}

function TiiAdFactoryGetAd() {
	var width, height, zone, ad;
	
	if (arguments.length == 2) {
		width = arguments[0];
		height = arguments[1];

		ad = this.createAd(width, height);	
	
	} else {
		width = arguments[0];
		height = arguments[1];
		zone = arguments[2];
	
		ad = this.createAd(width, height, zone);
	}

	if (this.dcopt == false) {
		ad.setParam("dcopt", "ist");
		this.dcopt = true;
	}

	return ad;
}

function TiiAdFactoryGetCmAd(width, height, position, type) {
	ad = this.createAd(width, height);
	ad.setParam("cmpos", position);
	ad.setParam("cmtyp", type);
	ad.sitename = this.cmSitename;

	return ad;
}

function TiiAdFactoryGetTransitionalAd() {
	ad = this.getAd(0,0);
	return ad;
}

function TiiAdFactoryGetMultiAd(sizes) {
	var width = sizes[0].split("x")[0];
	var height = sizes[0].split("x")[1];
	var ad = this.getAd(width, height);
	var sizeValue = sizes.join(",");
	ad.setParam("sz", sizeValue);
	
	return ad;
}

function TiiAdFactorySetArticleId(articleId) {
	this.setParam("aid", articleId);
}

function TiiAdFactorySetChannel(channel) {
	this.setParam("ch", channel);
}

function TiiAdFactorySetPackageId(packageId) {
	this.setParam("pid", packageId);
}

function TiiAdFactorySetSubchannel(subchannel) {
	this.setParam("sch", subchannel);
}

function TiiAdFactorySetContentPage() {
	this.setParam("ptype", "content");
}

function TiiAdFactorySetChannelPage() {
	this.setParam("ptype", "channel");
}

function TiiAdFactorySetContentType(ctype) {
	this.setParam("ctype", ctype);
}

function TiiAdFactorySetZone(zone) {
	this.zone = zone;
}

function TiiAd(factory, width, height, tileNumber) {
	this.tileNumber		= tileNumber;
	this.width		= width;
	this.height		= height;
	this.params		= new Array();

	// Methods
	this.setParam		= TiiAdFactorySetParam;
	this.setMagicNumber	= TiiAdSetMagicNumber;
	this.setPosition	= TiiAdSetPosition;
	this.setZone		= TiiAdSetZone;
	this.write		= TiiAdWrite;

	// Private Methods
	this._formatParams	= TiiAd_formatParams;
	this._getAdParams	= TiiAd_getAdParams;
	this._getAdTag		= TiiAd_getAdTag;
	this._getAdUrl		= TiiAd_getAdUrl;
	this._getImageUrl	= TiiAd_getImageUrl;
	this._getClickUrl	= TiiAd_getClickUrl;
	this._getDebugHtml	= TiiAd_getDebugHtml;
	this._getSecureAdTag	= TiiAd_getSecureAdTag;
	
	// Copy factory settings
	this.randomNumber	= factory.randomNumber;
	this.adServer		= factory.adServer;
	this.tileNumber		= factory.tileCounter;
	this.zone		= factory.zone;
	this.sitename		= factory.sitename;
}

function TiiAdSetMagicNumber(mn) {
	this.setParam("mn", mn);
}

function TiiAdSetPosition(pos) {
	this.setParam("pos", pos);
}

function TiiAdSetZone(zone) {
	this.zone = zone;
}

function TiiAdWrite() {
	if (TiiAdsIsDebugMode()) {
		document.write(this._getDebugHtml() + "<br/>");
	}
	
	document.write(this._getAdTag());
}

function TiiAd_formatParams() {
	var adParams = "";
	for (var key in this.params) {
		var value = this.params[key];
		
		if (typeof(value) == "function") {
			continue;
		}

		if (typeof(value) == "string" || typeof(value) == "number") {
			adParams += ";" + key + "=" + escape(value).toLowerCase();
		} else {
			for (var i = 0; i < value.length; i++) {
				if (value[i] != "") {
					adParams += ";" + key + "=" + escape(value[i]).toLowerCase();
				}
			}
		}
	}
	
	return adParams;
}

function TiiAd_getAdParams() {
	var adParams	= this._formatParams();
	var tileParam	= ";tile=" + this.tileNumber;

	var secureParam = "";
	if (TiiAd_isSecure()) {
		secureParam = ";sec=1";
	}

	var ordParam	= ";ord=" + this.randomNumber;
	
	return this.sitename + "/" + this.zone.toLowerCase() + adParams + tileParam + secureParam + ordParam + "?";
}

function TiiAd_getAdTag() {
	var adTag;
	if (TiiAd_isSecure()) {
		adTag = this._getSecureAdTag();		
	} else {
		adTag = '<scr' + 'ipt type="text/javascript" src="' + this._getAdUrl() + '"></scr' + 'ipt>';
	}
	
	return adTag;
}

function TiiAd_getSecureAdTag() {
	return '<a href="' + this._getClickUrl() + '" target="_blank"><img src="' + this._getImageUrl() + '" width="' + this.width + '" height="' + this.height + '" border="0" /></a>';
}

function TiiAd_getAdUrl() {
	return this.adServer + "adj/" + this._getAdParams();
}

function TiiAd_getImageUrl() {
	return this.adServer + "ad/" + this._getAdParams();
}

function TiiAd_getClickUrl() {
	return this.adServer + "jump/" + this._getAdParams();
}

function TiiAd_getDebugHtml() {
	var output = '<input style="font-family: courier new; font-size: small; width:' + this.width + 'px; margin: 0; padding: 0" value="' + unescape(this._getAdUrl()) + '"/>';

	return output;
}

// Support Functions

function TiiAdsIsDebugMode() {
	return window.location.search.indexOf("debugads") >= 0;
}

function TiiAdsGetRandomNumber() {
	return Math.ceil(1+1E12*Math.random());
}

function TiiAd_isSecure() {
	return (document.location.protocol == "https:");
}

// Redirect Functions

function tiiAdSetType() {}
function tiiAdSetTarget() {}
function tiiHtmlAdWH(mn, width, height) {
	adFactory.getAd(width, height).write();
}

/***** TII Global Browser Sniffing Variables *****/

var tii_isopera = typeof window.opera != 'undefined';

var tii_isie = typeof document.all != 'undefined'

   	&& !tii_isopera && navigator.vendor != 'KDE';

var tii_issafari = navigator.vendor == 'Apple Computer, Inc.';

/***** TII Global Functions *****/
/* Gets the total offset position of the element, assuming none of its ancestors have a float of left or right.
   Direction is 'x' for horizontal, and 'y' for vertical */
function tii_getTotalOffsetPosition (element, direction)
{
  var pos = direction == 'x' ? element.offsetLeft : element.offsetTop;
  var tmp = element.offsetParent;
  while (tmp != null)
  {
    pos += direction == 'x' ? tmp.offsetLeft : tmp.offsetTop;
    tmp = tmp.offsetParent;
  }
  return pos;
}

/* Stops the default action for the event, such as jumping to an anchor when clicking on a hyperlink */
function tii_stopDefaultAction (event)
{
	event.returnValue = false;
	if (typeof event.preventDefault != 'undefined')
	{
		event.preventDefault ();
	}
}

/* Create a new element node with attributes */
function tii_dom_createElement (nodeName, attributes)
{
	var isopera = typeof window.opera != 'undefined';
	var isie = typeof document.all != 'undefined'
   		&& !isopera && navigator.vendor != 'KDE';
		
	var newElement;
	try
	{
		newElement = document.createElement (nodeName);
	}
	catch (error)
	{
		return null;
	}
	
	var attributesLength = attributes.length;
	for (var i = 0; i < attributesLength; i++)
	{
		var attribute = attributes [i] [0];
		var value = attributes [i] [1];
		newElement.setAttribute (attribute, value);
		switch (attribute)
		{
			case 'id':
				newElement.id = value;
				break;
			case 'class':
				if (isie)
				{
					newElement.setAttribute ('className', value);
				}
				newElement.className = value;
				break;
			case 'style':
				newElement.style.cssText = newElement.style.cssText + ' ' + value;
				break;
			case 'for':
				if (isie)
				{
					newElement.setAttribute ('htmlFor', value);
				}
				newElement.htmlFor = value;
		}
	}
	
	return newElement;
}

/* Removes all the unwanted whitespace text nodes from inside the tree
   (including tabs, spaces, and line breaks between list items) */
function tii_dom_removeWhitespaceTextNodes (node)
{
  for (var x = 0; x < node.childNodes.length; x++)
  {
    var child = node.childNodes [x];
    if (child.nodeType == 3 && !/\S/.test (child.nodeValue))
    {
      node.removeChild (node.childNodes [x]);
      x--;
    }
    if (child.nodeType == 1)
    {
      tii_dom_removeWhitespaceTextNodes (child);
    }
  }
}

/***** ^^^ TII Global Functions Placed in >TII>Shared>JavaScript>TII LIB - JavaScript Event Listeners ^^^ *****/
/* Adds a function for the window load event */
function tii_callFunctionOnWindowLoad (functionToCall)
{
  if (typeof window.addEventListener != 'undefined')
  {
    window.addEventListener ('load', functionToCall, false);
  }
  else if (typeof document.addEventListener != 'undefined')
  {
    document.addEventListener ('load', functionToCall, false);
  }
  else if (typeof window.attachEvent != 'undefined')
  {
    window.attachEvent ('onload', functionToCall);
  }
  else
  {
    var oldFunctionToCall = window.onload;
    if (typeof window.onload != 'function')
    {
      window.onload = functionToCall;
    }
    else
    {
      window.onload = function ()
      {
        oldFunctionToCall ();
        functionToCall ();
      };
    }
  }
}

/* Calls functionToCall as soon as the targetElement is loaded, even if the document hasn't completely loaded yet. 
   Place the parameter list for functionToCall in order after tii_callFunctionOnElementLoad (targetId, functionToCall),
   e.g., tii_callFunctionOnElementLoad (targetId, functionToCall, parameter1, parameter 2, parameter 3, ...) */  
function tii_callFunctionOnElementLoad (targetId, functionToCall)
{
	var myArguments = arguments;
	tii_callFunctionOnWindowLoad (function ()
		{
			window.loaded = true;
		});
	var targetElement = document.getElementById (targetId);
	if (targetElement == null && !window.loaded)
	{
		var pollingInterval = setInterval (function ()
			{
				if (window.loaded)
				{
					clearInterval (pollingInterval);
				}
				targetElement = document.getElementById (targetId);
				if (targetElement != null)
				{
					clearInterval (pollingInterval);
					var argumentsTemp = new Array ();
					var argumentsTempLength = myArguments.length - 2;
					for (var i = 0; i < argumentsTempLength; i++)
					{
						argumentsTemp [i] = myArguments [i + 2];
					}		
					functionToCall.apply (this, argumentsTemp);
				}
			}, 10);
	}
}

/* Attaches an event handling function to the targetElement as soon as the targetElement is loaded
   (even if the document hasn't completely loaded yet). */  
function tii_addEventHandlerOnElementLoad (targetId, eventType, functionToCall, bubbleEventUpDOMTree)
{
	tii_callFunctionOnWindowLoad (function ()
		{
			window.loaded = true;
		});
	var targetElement = document.getElementById (targetId);
	if (targetElement == null && !window.loaded)
	{
		var pollingInterval = setInterval (function ()
			{
				if (window.loaded)
				{
					clearInterval (pollingInterval);
				}
				targetElement = document.getElementById (targetId);
				if (targetElement != null)
				{
					clearInterval (pollingInterval);
					tii_addEventHandler (targetElement, eventType, functionToCall, bubbleEventUpDOMTree);
				}
			}, 10);
	}
}

/* Attaches an event handling function to the targetElement. 
   Examples of eventType values are 'mouseover' and 'keyup', as opposed to 'onmouseover' and 'onkeyup'. 
   bubbleEventUpDOMTree is a boolean variable specifying whether the event should activate the event listeners
   of all the ancestors of the element (up to the window object) */
function tii_addEventHandler (targetElement, eventType, functionToCall, bubbleEventUpDOMTree)
{
  if (!targetElement)
  {
	  window.status = 'Warning: Tried to attach event to null object';
	  return false;
  }
  if (typeof targetElement.addEventListener != 'undefined')
  {
    targetElement.addEventListener (eventType, functionToCall, bubbleEventUpDOMTree);
  }
  else if (typeof targetElement.attachEvent != 'undefined')
  {
    targetElement.attachEvent ('on' + eventType, functionToCall);
  }
  else
  {
    eventType = 'on' + eventType;
    if (typeof targetElement [eventType] == 'function')
    {
      var oldListener = targetElement [eventType];
      targetElement [eventType] = function ()
      {
        oldListener ();
        return functionToCall ();
      }
    }
    else
    {
      targetElement [eventType] = functionToCall;
    }
  }

  return true;
}

/* Removes an event handling function from the targetElement. 
   Examples of eventType values are 'mouseover' and 'keyup', as opposed to 'onmouseover' and 'onkeyup'. 
   bubbleEventUpDOMTree is a boolean variable specifying whether the event should activate the event listeners
   of all the ancestors of the element (up to the window object)
   ***NOTE: This function does not support removing anonymous functions; a reference to the added function is needed */
function tii_removeEventHandler (targetElement, eventType, functionToRemove, bubbleEventUpDOMTree)
{
  if (typeof targetElement.removeEventListener != "undefined")
  {
    targetElement.removeEventListener (eventType, functionToRemove, bubbleEventUpDOMTree);
  }
  else if (typeof targetElement.detachEvent != "undefined")
  {
    targetElement.detachEvent ("on" + eventType, functionToRemove);
  }
  else
  {
    targetElement ["on" + eventType] = null;
  }
  
  return true;
}

/* Initialization and Unobtrusive Javascript Calls */
tii_callFunctionOnElementLoad('playLink', initPageComponents);