size = { 157, 209 }



defineProperty("view_type", globalPropertyi("sim/graphics/view/view_type"))
defineProperty("view_is_external", globalPropertyi("sim/graphics/view/view_is_external"))

--test
defineProperty("cloud_tops_1", globalPropertyf("sim/weather/cloud_tops_msl_m[0]"))
--
defineProperty("popup_mfd", globalPropertyi("cl300/popup_mfd"))
defineProperty("dis_2d_cockpit", globalPropertyi("cl300/dis_2d_cockpit"))

defineProperty("cam_panel_s", globalPropertyi("cl300/cam_panel_s"))


defineProperty("cam_type", globalPropertyi("cl300/cam_type"))
defineProperty("menu2", loadImage("menu1.png", 0, 351, 157, 209))
defineProperty("closing", loadImage("closing.png", 16, 16))

defineProperty("customslider1", globalPropertyi("cl300/customslider1"))

defineProperty("headposx", globalPropertyf("sim/graphics/view/pilots_head_x"))
defineProperty("headposy", globalPropertyf("sim/graphics/view/pilots_head_y"))
defineProperty("headposz", globalPropertyf("sim/graphics/view/pilots_head_z"))
defineProperty("headpsi", globalPropertyf("sim/graphics/view/pilots_head_psi"))
defineProperty("headthe", globalPropertyf("sim/graphics/view/pilots_head_the"))

defineProperty("mfd_pan", globalPropertyi("cl300/mfd_pan"))

--starter_1 = findCommand("sim/starters/engage_starter_1")

captview = findCommand("sim/view/forward")
cockview = findCommand("sim/view/3d_cockpit")
captview2 = findCommand("sim/view/forward_with_panel")
cockview2 = findCommand("sim/view/3d_cockpit_cmnd_look")


createCommand("cl300/viewdisptoggle", "View displays zoom")

viewdispl = findCommand("cl300/viewdisptoggle")
vd_t = 0

zm_x = get(headposx)
zm_y = get(headposy)
zm_z = get(headposz)
zm_psi = get(headpsi)
zm_the = get(headthe)
set(cam_type, 0)


local font1 = loadFont('font_5.fnt')

	color1 = {0.4,0.4,0.4}
	color2 = {0.4,0.4,0.4}
	color3 = {0.4,0.4,0.4}
	color4 = {0.4,0.4,0.4}
	color5 = {0.4,0.4,0.4}
	color6 = {0.4,0.4,0.4}
	color7 = {0.4,0.4,0.4}
	color8 = {0.4,0.4,0.4}




--



 function viewdHandler(phase)
     if 0 == phase then
		 if vd_t == 0 then
		 commandOnce(cockview2)
			set(headposx, -0.24640998244286)
			set(headposy, 0.7736536860466)
			set(headposz, -6.8731637001038)
			set(headpsi, 0)
			set(headthe, -12.090915679932)
			vd_t = 1
			if get(popup_mfd) == 1 then set(mfd_pan, 1) end
		else
		 commandOnce(captview)
		 commandOnce(cockview)
		commandOnce(captview2)
		commandOnce(cockview2)
		 vd_t = 0
--		 set(mfd_pan, 0)
		end
        -- command start
--[=[print("New camera position")
print("headposx = ",get(headposx))
print("headposy = ",get(headposy))
print("headposz = ",get(headposz))
print("headpsi = ",get(headpsi))
print("headthe = ",get(headthe))--]=]
     --elseif 2 == phase then
 	--commandOnce(white_smoke);
	--set(white_smoke_d, 0)
        -- command end

     end
     return 1
 end

registerCommandHandler(viewdispl, 1, viewdHandler);

function update()

if get(dis_2d_cockpit) == 1 then
	if get(view_is_external) == 0 and get(view_type) ~= 1026 then set(view_type, 1026)	end
end

if get(cam_panel_s) == 1 then

	if get(cam_type) == 2 then
			set(headposx, 0.44564479589462)
			set(headposy, 0.90220862627029)
			set(headposz, -5.2913269996643-1.2192)
	end

	if get(cam_type) == 3 then
			set(headposx, 0.47367909550667)
			set(headposy, 0.62394458055496)
			set(headposz, 1.637542963028-1.2192)
	end

	if get(cam_type) == 4 then
			set(headposx, 0.58394801616669)
			set(headposy, 0.54318302869797)
			set(headposz, -2.819384098053-1.2192)
	end

	if get(cam_type) == 5 then
			set(headposx, 0.62512969970703)
			set(headposy, 0.58265388011932)
			set(headposz, -0.39221715927124-1.2192)
	end

	if get(cam_type) == 6 then
			set(headposx, -0.516751)
			set(headposy, 0.556614)
			set(headposz, -0.038810)
	end
	if get(cam_type) == 7 then
			set(headposx, 0.73232400417328)
			set(headposy, 1.00274896621)
			set(headposz, 2.6334295272827-1.2192)
	end
	if get(cam_type) == 8 then
			set(headposx, 0.52529412508011)
			set(headposy, 1.1162127256393)
			set(headposz, 2.990875005722-1.2192)
	end

else
set(cam_type, 0)
end
end

components = {

    textureLit {
        position = {0,0,157,209},
        image = get(menu2)

    },
--pilot
	clickable {
       position = {  0, 170, 84, 14  },


		onMouseMove = function()
	        color1 = {0.4,0.4,0.8}
			color2 = {0.4,0.4,0.4}
			color3 = {0.4,0.4,0.4}
			color4 = {0.4,0.4,0.4}
			color5 = {0.4,0.4,0.4}
			color6 = {0.4,0.4,0.4}
			color7 = {0.4,0.4,0.4}
			color8 = {0.4,0.4,0.4}
        end,

        onMouseClick = function()
			set(cam_type, 1)
--			color1 = {0.2,0.7,0.2}
			commandOnce(captview)
			commandOnce(cockview)
			commandOnce(captview2)
			commandOnce(cockview2)
--			set(customslider1, 0)
        end


    },
	--copilot

	clickable {
       position = {  0, 149, 84, 14  },


		onMouseMove = function()
	        color1 = {0.4,0.4,0.4}
			color2 = {0.4,0.4,0.8}
			color3 = {0.4,0.4,0.4}
			color4 = {0.4,0.4,0.4}
			color5 = {0.4,0.4,0.4}
			color6 = {0.4,0.4,0.4}
			color7 = {0.4,0.4,0.4}
			color8 = {0.4,0.4,0.4}
        end,

        onMouseClick = function()
			set(cam_type, 2)
			commandOnce(cockview2)
			set(headposx, 0.44564479589462)
			set(headposy, 0.90220862627029)
			set(headposz, -5.2913269996643-1.2192)
			set(headpsi, 0)
			set(headthe, -6.0441737174988)
--			set(customslider1, 0)
        end
    },
-- cabin 1
	clickable {
       position = {  0, 129, 84, 14  },


		onMouseMove = function()
	        color1 = {0.4,0.4,0.4}
			color2 = {0.4,0.4,0.4}
			color3 = {0.4,0.4,0.8}
			color4 = {0.4,0.4,0.4}
			color5 = {0.4,0.4,0.4}
			color6 = {0.4,0.4,0.4}
			color7 = {0.4,0.4,0.4}
			color8 = {0.4,0.4,0.4}
        end,

        onMouseClick = function()
			set(cam_type, 3)
			commandOnce(cockview2)
			set(headposx, 0.47367909550667)
			set(headposy, 0.62394458055496)
			set(headposz, 1.637542963028-1.2192)
			set(headpsi, 345.72509765625)
			set(headthe, 6.1636881828308)
--			set(customslider1, 0)
        end
    },
--cabin 2
	clickable {
       position = {  0, 110, 84, 14  },


		onMouseMove = function()
	        color1 = {0.4,0.4,0.4}
			color2 = {0.4,0.4,0.4}
			color3 = {0.4,0.4,0.4}
			color4 = {0.4,0.4,0.8}
			color5 = {0.4,0.4,0.4}
			color6 = {0.4,0.4,0.4}
			color7 = {0.4,0.4,0.4}
			color8 = {0.4,0.4,0.4}
        end,

        onMouseClick = function()
			set(cam_type, 4)
			commandOnce(cockview2)
			set(headposx, 0.58394801616669)
			set(headposy, 0.54318302869797)
			set(headposz, -2.819384098053-1.2192)
			set(headpsi, 196.89665222168)
			set(headthe, 8.7736225128174)
--			set(customslider1, 0)

        end
    },
-- cabin 3
		clickable {
       position = {  0, 92, 84, 14  },


		onMouseMove = function()
	        color1 = {0.4,0.4,0.4}
			color2 = {0.4,0.4,0.4}
			color3 = {0.4,0.4,0.4}
			color4 = {0.4,0.4,0.4}
			color5 = {0.4,0.4,0.8}
			color6 = {0.4,0.4,0.4}
			color7 = {0.4,0.4,0.4}
			color8 = {0.4,0.4,0.4}
        end,

        onMouseClick = function()
			set(cam_type, 5)
			commandOnce(cockview2)
			set(headposx, 0.62512969970703)
			set(headposy, 0.58265388011932)
			set(headposz, -0.39221715927124-1.2192)
			set(headpsi, 200.17715454102)
			set(headthe, 5.1395978927612)
--			set(customslider1, 0)

        end
    },

-- cabin 4
		clickable {
       position = {  0, 69, 84, 14  },


		onMouseMove = function()
	        color1 = {0.4,0.4,0.4}
			color2 = {0.4,0.4,0.4}
			color3 = {0.4,0.4,0.4}
			color4 = {0.4,0.4,0.4}
			color5 = {0.4,0.4,0.4}
			color6 = {0.4,0.4,0.4}
			color7 = {0.4,0.4,0.4}
			color8 = {0.4,0.4,0.8}
        end,

        onMouseClick = function()
			set(cam_type, 6)
			commandOnce(cockview2)
			set(headposx, -0.516751)
			set(headposy, 0.556614)
			set(headposz, -0.038810)
			set(headpsi, 248.304474)
			set(headthe, 2.944788)
--			set(customslider1, 0)

        end
    },

--lavatory
			clickable {
       position = {  0, 45, 84, 14  },


		onMouseMove = function()
	        color1 = {0.4,0.4,0.4}
			color2 = {0.4,0.4,0.4}
			color3 = {0.4,0.4,0.4}
			color4 = {0.4,0.4,0.4}
			color5 = {0.4,0.4,0.4}
			color6 = {0.4,0.4,0.8}
			color7 = {0.4,0.4,0.4}
			color8 = {0.4,0.4,0.4}
        end,

        onMouseClick = function()
			set(cam_type, 7)
			commandOnce(cockview2)
			set(headposx, 0.73232400417328)
			set(headposy, 1.00274896621)
			set(headposz, 2.6334295272827-1.2192)
			set(headpsi, 288.5475769043)
			set(headthe, -6.6578507423401)
--			set(customslider1, 0)

        end
    },
--baggage
				clickable {
       position = {  0, 21, 84, 14  },


		onMouseMove = function()
	        color1 = {0.4,0.4,0.4}
			color2 = {0.4,0.4,0.4}
			color3 = {0.4,0.4,0.4}
			color4 = {0.4,0.4,0.4}
			color5 = {0.4,0.4,0.4}
			color6 = {0.4,0.4,0.4}
			color7 = {0.4,0.4,0.8}
			color8 = {0.4,0.4,0.4}
        end,

        onMouseClick = function()
			set(cam_type, 8)
			commandOnce(cockview2)
			set(headposx, 0.52529412508011)
			set(headposy, 1.1162127256393)
			set(headposz, 2.990875005722-1.2192)
			set(headpsi, 254.1301574707)
			set(headthe, -21.29100227356)
--			set(customslider1, 0)
        end
    },

 		-- close zone
    textureLit {
        position = {size[1] - 16, size[2] - 16, 16, 16 },
        image = get(closing)

    },
		clickable {
		position = {size[1]-16, size[2]-16, 16, 16 },

		cursor = {
			x = -16,
			y = 0,
			width = 32,
			height = 16,
			shape = loadImage("clickclose.png")
		},
		 onMouseClick = function()
			set(cam_panel_s, 0)
		 end
	},

}


function draw()

drawAll(components)

--if get(cam_type) == 0 then
drawText(font1, 30, 174, "PILOT",  color1[1],color1[2],color1[3])
drawText(font1, 30, 153, "COPILOT",  color2[1],color2[2],color2[3])
drawText(font1, 30, 132, "CABIN 1",  color3[1],color3[2],color3[3])
drawText(font1, 30, 111, "CABIN 2",  color4[1],color4[2],color4[3])
drawText(font1, 30, 90, "CABIN 3",  color5[1],color5[2],color5[3])
drawText(font1, 30, 69, "CABIN 4",  color8[1],color8[2],color8[3])
drawText(font1, 30, 48, "LAVATORY",  color6[1],color6[2],color6[3])
drawText(font1, 30, 27, "BAGGAGE",  color7[1],color7[2],color7[3])

end
