bmap panel_pic = <panel2.bmp>;
var dn_timer = 0;
var day_length;
var temp_var;

///////////////////////////////////////////////////////
// section: Sky Sphere 0 (night sky)

sky night_sky
{
	type = <sky_stars.pcx>;
	speed_u = 1.5;
	speed_v = 0.0;
	scale_x = 0.125;
	scale_y = 0.125;
	flags = dome,visible;
	layer = 1;
}
///////////////////////////////////////////
// night sky horizon

sky night_sky_horizon 
{
	type = <sky_stars.pcx>;
	speed_u = 1.5;
	speed_v = .2;
	scale_x = .02;
	tilt = -3;
	flags = scene,overlay,visible,;
	layer = 8;
}
////////////////////////////////////////////////////////
// section: Sky Sphere 1 (day sky)

sky day_sky
{

	type = <sky_blue.pcx>;
	speed_u = 1.5;
	speed_v = 0.5;
	scale_x = 1.0;
	scale_y = 1.0;
	flags =  dome, transparent;
	alpha = 100;
	layer = 2;
}
///////////////////////////////////////////
// day sky horizon

sky day_sky_horizon
{

	type = <sky_blue.pcx>;
	speed_u = 1.5;
	speed_v = .2;
	scale_x = .02;
	tilt = -3;
	alpha = 100;
	flags = scene,overlay,transparent;
	layer = 9;
}
////////////////////////////////////////////////
// The sun
//sky sun_sky
//{
//	type = <thesun.mdl>;
//	//speed_u = 3;
//	//speed_v = 3;
//	x= 0;
//	y= 5000;
//	z= 1000;
//	tilt = 20;
//	scale_x = .2;
//	scale_y = .2;
//	scale_z = .2;
//	pan = 0;
//
//	ambient =100;
//	flags = visible,overlay,bright,flare;
//	alpha = 100;
//	layer = 3;
//}


//////////////////////////////////////////////////////////////
// section: Sky Sphere 2 (cloud layer 2)
sky sky00_02_sky
{
	type = <cloud2.bmp>;
	speed_u = 2;
	speed_v = 2;
	scale_x = 1;
	scale_y = 1;
	flags = dome,overlay,visible,transparent;  // sky dome, black transparent, alpha
	alpha = 85;
	layer = 6;
}

///////////////////////////////////////////////////////////////////
//


function daynight_cycle (num)
{
	day_length = num*60;
	temp_var = 180/day_length;
	while (1)
	{
		if (dn_timer < day_length/2)
			{ 	
				sun_angle.pan = 90;
				sun_angle.tilt += temp_var;
				sun_light +=3*temp_var;
			}
		if ((dn_timer < day_length ) && (dn_timer >= day_length/2))
			{
				sun_angle.pan = 270;
				sun_angle.tilt -= temp_var;
				sun_light -=3*temp_var;
			}
		if (dn_timer == day_length)
			{
				lensflare_stop();
				sun_light = 0;	
				while (day_sky.alpha > 0)
				{
					day_sky.alpha -=.02;
					day_sky_horizon.alpha -=.02;
					wait(1);
				}
				day_sky.alpha = 0;
				day_sky_horizon.alpha = 0;
				day_sky.visible = off;
				day_sky_horizon.visible = off;
			}
		if ((dn_timer == day_length*2) || (dn_timer == 0 ))
			{
				day_sky.visible = on;
				day_sky_horizon.visible = on;
				sun_light =30;
				while (day_sky.alpha < 100)
				{	
					day_sky.alpha +=.02;
					day_sky_horizon.alpha +=.02;
					wait(1);
				}
				day_sky.alpha = 100;
				day_sky_horizon.alpha = 100;
				lensflare_start();
				dn_timer = 0;
			}

		dn_timer += 1;
		sleep(1);
	}
}


///////////////////////////////////////
panel panel_one
{
	bmap = panel_pic;
	pos_x =25; pos_y = 350;
	digits = 5,5,4,_a4font,1,dn_timer;
	digits = 5,12,4,_a4font,1,day_length;
	digits = 5,19,4,_a4font,1,sun_angle.tilt;
	digits = 5,26,4,_a4font,1,sun_light;
	alpha = 60;
	flags transparent, refresh,visible;
}
