SetupFullscreen(800, 600, "Snipp Snipp");

intro_layer = new Layer();
background_layer = new Layer();
clouds_layer = new Layer();
grass_layer = new Layer();
mountains_layer = new Layer();
sadhorse1_layer = new Layer();
sadhorse2_layer = new Layer();
gil1_layer = new Layer();
blond_layer = new Layer();
gil2_layer = new Layer();
pain1_layer = new Layer();
pain2_layer = new Layer();
happy_layer = new Layer();
wonder_layer = new Layer();
forklaring_layer = new Layer();

music = new AudioStream("data/Fast_MASTER.ogg");

//INTRO LAYER
intro = new Quad(intro_layer, 0, 0, 800, 600);
intro.SetImage("data/intro.png");

//CLOUDS
clouds_layer.SetBlendMode(BlendModeReplace);
clouds_image1 = new Quad(clouds_layer, 0, 0, 800, 600);
clouds_image1.SetImage("data/clouds1.png");
clouds_image2 = new Quad(clouds_layer, 0, 0, 800, 600);
clouds_image2.SetImage("data/clouds2.png");

//MOUNTAINS
mountains_layer.SetBlendMode(BlendModeReplace);
mountains_image1 = new Quad(mountains_layer, 0, 200, 800, 600);
mountains_image1.SetImage("data/mountains1.png");
mountains_image2 = new Quad(mountains_layer, 0, 0, 800, 600);
mountains_image2.SetImage("data/mountains2.png");

//GRASS
grass_layer.SetBlendMode(BlendModeReplace);
grass_image1 = new Quad(grass_layer, 0, 0, 800, 600);
grass_image1.SetImage("data/grass1.png");
grass_image2 = new Quad(grass_layer, 0, 0, 800, 600);
grass_image2.SetImage("data/grass1.png");

//SADHORSE1
sadhorse1_layer.SetBlendMode(BlendModeReplace);
sadhorse2_layer.SetBlendMode(BlendModeReplace);
sadhorse_image1 = new Quad(sadhorse1_layer, 0, 0, 800, 600);
sadhorse_image1.SetImage("data/sadhorse1.png");
sadhorse_image2 = new Quad(sadhorse2_layer, 0, 0, 800, 600);
sadhorse_image2.SetImage("data/sadhorse2.png");

//BACGROUND
background = new Quad(background_layer, 0, 0, 800, 600);
background.SetImage("data/background.png");

//GIL1
gil1_layer.SetBlendMode(BlendModeReplace);
gil1 = new Quad(gil1_layer, 100, 100, 800, 600);
gil1.SetImage("data/gil.png");

//BLOND
blond_layer.SetBlendMode(BlendModeReplace);
blond = new Quad(blond_layer, 0, 0, 800, 600);
blond.SetImage("data/horsethinks.png");

//GIL2
gil2_layer.SetBlendMode(BlendModeReplace);
gil2 = new Quad(gil2_layer, 100, 100, 800, 600);
gil2.SetImage("data/gil2.png");

//HORSE1
pain1_layer.SetBlendMode(BlendModeReplace);
pain1 = new Quad(pain1_layer, 0, 0, 800, 600);
pain1.SetImage("data/pain1.png");
pain1.SetSize(800, 600);

//HORSE2
pain2_layer.SetBlendMode(BlendModeReplace);
pain2 = new Quad(pain2_layer, 0, 0, 800, 600);
pain2.SetImage("data/pain2.png");
pain2.SetSize(800, 600);

//HAPPY
happy_layer.SetBlendMode(BlendModeReplace);
happy = new Quad(happy_layer, 0, 0, 800, 600);
happy.SetImage("data/happyhorse1.png");

//wonder
wonder_layer.SetBlendMode(BlendModeReplace);
wonder = new Quad(wonder_layer, 0, 0, 800, 600);
wonder.SetImage("data/wonder.png");

//forklaring
forklaring_layer.SetBlendMode(BlendModeReplace);
forklaring = new Quad(forklaring_layer, 0, 0, 800, 600);
forklaring.SetImage("data/start.png");


function drawBG()
{

	//BACGROUND
	background_layer.Render();
	
	//CLOUDS
	clouds_layer.Render();
	
	//MOUNTAINS
	mountains_layer.Render();
	
}

function drawFG()
{

	//GRASS
	while (grass_x < 0) grass_x += 800;
	
	grass_image1.SetPosition(grass_x, 50);
	grass_image2.SetPosition(grass_x-800,50);
	grass_layer.Render();
		
}

music.Play();

while (Update() && !KeyDown(KeyEsc))//-------------------------------------------------------------------------
{
	Clear(0,0,1);		//Hva er dette?
	
	time = GetTime()+0;
	clouds_x = time*-10;
	grass_x = time*-200;
	horse_x = 100;
	horse_y = 50;
	
	//background_layer.Render();
	
	if (time < 4.0)
	{
		drawBG();
		intro_layer.Render();
	}
	
	else if (time > 4.0 && time < 8.0)
	{
		forklaring_layer.Render();
	}
	else if (time > 8.0 && time < 14.0)
	{
		drawBG();
		drawFG();
		
		//SADHORSE
		tall = Math.floor(time*4)%2;
		
		if(tall < 1)
		{
		sadhorse_image1.SetPosition(horse_x, Math.sin(time*7)*10+horse_y);
		sadhorse1_layer.Render();
		}
		else 
		{
		sadhorse_image2.SetPosition(horse_x, Math.sin(time*7)*10+horse_y);
		sadhorse2_layer.Render();
		}
		
	}
	else if (time > 14.0 && time < 16.0)
	{
		drawBG();
		gil1_layer.Render();
	}
	else if (time > 16.0 && time < 19.0)
	{
		drawBG();
		blond_layer.Render();
	}
	else if (time > 19.0 && time < 21.0)
	{
		drawBG();
		wonder_layer.Render();
	}
	else if (time > 21.0 && time < 24.0)
	{
		drawBG();
		gil2_layer.Render();
	}
	
	else if (time > 24.0 && time < 28.0)
	{
		//HORSEPAIN
		number = Math.floor(time*5)%2;
		
		if(number < 1)
		{
		pain1_layer.Render();
		}
		else 
		{
		pain2_layer.Render();
		}
		
	}
	
	else if (time > 28.0 && time < 35.0)
	{
		drawBG();
		drawFG();
		happy_layer.Render();
	}
	
	else break;
	
}

