#!/bin/bash

function main-inx ()
{

# Grab all external functions files so we know what's what, and can match the call.
. f-sirius
. f-menu
. f-hints
. f-intro
. f-tour
. f-fun
. f-why
. f-splash
. f-colours
. f-net
. f-office
. f-sshfs
. f-mailfunctions
. f-radiofunctions
. f-tutorialfunctions
. f-drivinx
. show_mounts
. time_settings
. f-tools

# Check how we are being called ( which function needed first? )

function call ()

{

case "$CALL" in

	inx)
	f-splash
	f-menu ;;

	menu)
	f-menu ;;

	random)
	f-plinput ;;

	stream)
	f-radiomenu ;;

	hints)
	f-hints ;;

	intro)
	f-intro ;;

	tour)
	f-tour ;;

	tutorial)
	f-tutorial  ;;

	fun)
	f-fun ;;

	usb)
	f-usb ;;

	why)
	f-why ;;

	mailinx)
	f-mail ;;

	monitor)
	f-monitor ;;
	
	mailscreen)
	f-mailscreen ;;
	
	filemanage)
	f-filemanage ;;
	
	mutt)
	f-mutt ;;
	
	netinx)
	f-net ;;
	
	splash)
	f-splash ;;
	
	office)
	f-office ;;
	
	sharinx)
	f-sshfs ;;

	music)
	f-music ;;
	
	sirius)
	f-sirius ;;
	
	disc)
	f-discmount ;;

        drivinx)
	f-drivinx ;;
	
	time_settings)
	time_settings ;;
	
	tools)
	f-tools ;;
	
	*)
	echo "main-inx: Bad call ... can't find "$CALL" ... this shouldn't happen ..."
	exit 1	
	;;
	
esac

}

#play with the colours before the call 
# f-flip calls f-switch calls "call" in main-inx 

f-flip

}

function f-flip ()
{
# Play with colours...

# Define some schemes...
standard ()
{
	
	fig-col ()
		{
		bold
		magenta
		}
	head-col ()
		{
		bold
		cyan
		}
	info-col ()
		{
		bold
		white
		}
}

gringold ()
{

	fig-col ()
		{
		bold
		green
		}
	head-col ()
		{
		bold
		yellow
		}
	info-col ()
		{
		bold
		white
		}

}

understated ()
{

	fig-col ()
		{
		bold
		white
		}
	head-col ()
		{
		unbold
		yellow
		}
	info-col ()
		{
		unbold
		white
		}

}

trad ()
{
	fig-col ()
		{
		bold
		yellow
		}
	head-col ()
		{
		bold
		white
		}
	info-col ()
		{
		unbold
		white
		}
}

mono ()
{
	fig-col ()
		{
		unbold
		white
		}
	head-col ()
		{
		bold
		white
		}
	info-col ()
		{
		unbold
		white
		}
}

cool ()
{
	fig-col ()
		{
		bold
		cyan
		}
	head-col ()
		{
		bold
		blue
		}
	info-col ()
		{
		unbold
		cyan
		}
}

uncool ()
{
	fig-col ()
		{
		bold
		yellow
		}
	head-col ()
		{
		bold
		red
		}
	info-col ()
		{
		bold
		yellow
		}
}

ice ()
{
	fig-col ()
		{
		bold
		cyan
		}
	head-col ()
		{
		bold
		white
		}
	info-col ()
		{
		unbold
		white
		}
}

glowcave ()
{
	fig-col ()
		{
		bold
		blue
		}
	head-col ()
		{
		bold
		cyan
		}
	info-col ()
		{
		bold
		white
		}
}

CURRENT="foo"
f-switch
}

function f-switch ()
{
case "$CURRENT" in

	gringold)
	CURRENT="standard"
	standard
	call
	;;
	standard)
	CURRENT="mono"
	mono
	call
	;;
	mono)
	CURRENT="cool"
	cool
	call
	;;
	cool)
	CURRENT="glowcave"
	glowcave
	call
	;;
	glowcave)
	CURRENT="ice"
	ice
	call
	;;
	ice)
	CURRENT="uncool"
	uncool
	call
	;;
	uncool)
	CURRENT="trad"
	trad
	call
	;;
	trad)
	CURRENT="lessgreen"
	understated
	call
	;;
	lessgreen)
	CURRENT="gringold"
	gringold
	call
	;;
	*)
	CURRENT="gringold"
	gringold
	call
	;;
esac
}

function f-escape ()
{

# Help, get me out of here!

read -n 1
case "$REPLY" in

	m)
	f-menu
	;;
	x)
	f-prompt
	;;
	*)
	;;
esac
}

function f-sup ()
{
# Startup info ... so people know something is happening if it takes a while
head-col
echo
echo "  Starting up, please wait........"
white
}

f-ttynum ()
{
# Print the tty number on the right edge of the screen. GNU screen doesn't need this with INX defaults

if [ $TERM = linux ] ; then
unbold 
let END=$COLUMNS-5
for space in $(seq 1 $END) ; do printf " " ; done ; tty | cut -d/ -f3
white ; bold
fi

}
	
function f-prompt ()
{
	cyan ; bold 
	echo
	printf "Aarrrgh "\!" "
	yellow
	printf "You typed  "
	cyan 
	printf "X"
	yellow
	printf " ...  "
	cyan 
	printf "INX Is Not X "\!"   "
	printf "\n\n"
	green
	printf "So: - here is your command prompt..."
	echo
	echo "Type: \"inx\" or \"menu\" then hit <enter> , or just hit ctrl+d, to return to the inx script."
	echo
	white 
	unbold
	exit 0
}
