
	var running   = false;
	var timeoutId = null;
	var url       = "";
	var refresh   = 30;
	var minimumRefresh = 30;
	var rCount=0;

    var reloadseconds=0;
    var secondssinceloaded=0;

    var dc=true;

	starttime=new Date();
	starttime=starttime.getTime();

	function viewPage()
	{
		running = true;

		refresh = 30;

		url     = "http://www.wikipedia.org/wiki/Special:Random";

    	starttime=new Date();
	    starttime=starttime.getTime();
		top.window.frames["main"].location.href = url;
		timeoutId = setTimeout( "changePage()", 1000 );		
	}

	function displayCountdown()
	{
		dc = document.getElementById("dc").checked;
	}

	function changePage()
	{
		if ( running )
		{
			rCount++;
	        nowtime= new Date();
	        nowtime=nowtime.getTime();
	        secondssinceloaded=(nowtime-starttime)/1000;
	        reloadseconds=Math.round(refresh-secondssinceloaded);
			var s="s";
			if (refresh>=secondssinceloaded)
			{
				if (dc)
				{
					if (reloadseconds == 1) s="";				
					window.status="Running...page will refresh in "+reloadseconds+ " second" + s;
				}
				else
				{
					window.status="";
				}
			}
			else
			{
				clearTimeout(timeoutId);
				if (rCount == 10 )
				{
					top.window.frames['ads'].location.href = "ads.html";
					rCount = 0;
				}
				top.window.frames['main'].location.href = url;
			    
		        starttime=new Date();
			    starttime=starttime.getTime();
			}
			timeoutId = setTimeout("changePage()",1000);		
		}
	}

	function stop()
	{
		if ( running )
		{
			running = false;
			clearTimeout( timeoutId );
			window.status="Refreshing stopped.";
		}
	}

