import java.awt.*;
import java.applet.*;
import java.net.URL;


public class nav extends Applet
{
    Image back;
    Image cont;
    Image anim, down, games, images, javamen, link, mail, main, button, crea, ship;
    int w_back, h_back, w_app, h_app;
    nafi browse[];
    int AnzahlObj = 11;
    int akut = 0;
    Graphics GR;
    Thread ourThread;
    int glob_a, glob_b;
    int alt_a, alt_b;
    MediaTracker tracker;
    String name;


    public void init()
    {
        browse = new nafi[AnzahlObj];

        anim = getImage(getDocumentBase(), "anim.gif");
        down = getImage(getDocumentBase(), "down.gif");
        games = getImage(getDocumentBase(), "games.gif");
        images = getImage(getDocumentBase(), "images.gif");
        link = getImage(getDocumentBase(), "link.gif");
        mail = getImage(getDocumentBase(), "mail.gif");
        main = getImage(getDocumentBase(), "main.gif");
        button = getImage(getDocumentBase(), "textf.gif");
        javamen = getImage(getDocumentBase(), "javamen.gif");
        crea = getImage(getDocumentBase(), "crea.gif");
        ship = getImage(getDocumentBase(), "ship.gif");

        back = getImage(getDocumentBase(), "backgr.gif");
        cont = getImage(getDocumentBase(), "cont.gif");
        tracker = new MediaTracker(this);
//        tracker.addImage(back, 0); //The background image is not allowed to be
                                     //in the MediaTracker, because of the ImageObserver
                                     //in ImageUpdate().
        tracker.addImage(cont, 1);
        tracker.addImage(anim,2);
        tracker.addImage(down,3);
        tracker.addImage(games,4);
        tracker.addImage(images,5);
        tracker.addImage(link,6);
        tracker.addImage(mail,7);
        tracker.addImage(main,8);
        tracker.addImage(button, 9);
        tracker.addImage(javamen, 10);
        tracker.addImage(crea, 11);
        tracker.addImage(ship, 12);

        showStatus("Loading images.");
        try
        {
            tracker.waitForAll();
        }
        catch (InterruptedException e)
        {
            return;
        }
        Dimension d = size();
        w_app = d.width;
        h_app = d.height;

        //Area-Coords
        browse[0] = new nafi( 0,   0,   87,  16);
        browse[1] = new nafi( 11,  16, 114,  32);
        browse[2] = new nafi( 22,  33, 156,  48);
        browse[3] = new nafi( 22,  50,  87,  66);
        browse[4] = new nafi( 22,  68, 159,  83);
        browse[5] = new nafi( 22,  84,  87,  98);
        browse[6] = new nafi( 11, 100, 135, 114);
        browse[7] = new nafi( 11, 115, 139, 134);
        browse[8] = new nafi( 11, 138, 133, 154);
        browse[9] = new nafi( 11, 158,  92, 174);
        browse[10] = new nafi(11, 178,  76, 192);

        glob_a=0;
        glob_b=0;
        alt_a = 0;
        alt_b = 0;

        showStatus("Initialized correctly.");
    }

    public boolean mouseDown(Event e, int x_pos, int y_pos)
    {
        int a=0;
        int b=0;
        for (int i=0; i<AnzahlObj; i++)
        {
            if (x_pos >= browse[i].getX_pos()
                && x_pos <= browse[i].getWidth()
                && y_pos >= browse[i].getY_pos()
                && y_pos <= browse[i].getHeight())
            {
                if (i!=akut)
                {
                    akut = i;
                    a = browse[akut].getX_pos()+15;
                    b = browse[akut].getY_pos();
                    glob_a = a;
                    glob_b = b;
                    if (i==0) name = "main.html";
                    else if (i==1) name = "java-in.html";
                    else if (i==2) name = "java1.html";
                    else if (i==3) name = "java2.html";
                    else if (i==4) name = "java3.html";
                    else if (i==5) name = "java4.html";
                    else if (i==6) name = "crea.html";
                    else if (i==7) name = "ship.html";
                    else if (i==8) name = "pics.html";
                    else if (i==9) name = "link.html";
                    String n = "http://www.geocities.com/SiliconValley/Pines/8878/" + name;
                    if (i != 10) openDoc(n);
                    if (i == 10) message();
                    repaint();
                }
            }
        }
        return true;
    }

    public boolean imageUpdate( Image img, int infoflags, int x, int y,
    int width, int height )
    {
        if (( infoflags & (ALLBITS)) != 0 )
        {
            w_back = back.getWidth(null);
            h_back = back.getHeight(null);
            repaint();
            return false;
        }
        return true;
    }

    public void paint(Graphics g)
    {
        drawBack(back, g);
        Image ak = anim;
        g.drawImage(cont,0,0,this);
        if (akut == 0) ak = main;
        if (akut == 1) ak = javamen;
        if (akut == 2) ak = button;
        if (akut == 3) ak = images;
        if (akut == 4) ak = anim;
        if (akut == 5) ak = games;
        if (akut == 6) ak = crea;
        if (akut == 7) ak = ship;
        if (akut == 8) ak = down;
        if (akut == 9) ak = link;
        if (akut == 10) ak = mail;
        g.drawImage(ak, browse[akut].getX_pos()+15, browse[akut].getY_pos(), this);
    }

    public void drawBack(Image b, Graphics g)
    {
        g.drawImage(back, 0, 0, this);

        if (h_back != 0)
        {
            int w=w_back;
            for (int h=0; h<=h_app;)
            {
                for (w=0; w<=w_app;)
                {
                        g.drawImage(back, w, h, this);
                        w = w+w_back;
                }
                h = h+h_back;
            }
        }
    }

    public void openDoc(String file)
    {
		try
		{
		    URL u = new URL(file);
		    AppletContext c = getAppletContext();
		    if (c!=null)
	        c.showDocument(u, "right");
		}
		catch(Exception url)
		{
		    System.out.println(url);
		}
	}

	public void message()
	{
	    message m = new message(this, "Navigation Bar", "Thorondor", "02.10.97", "still under Construction");
        m.setBackground(Color.white);
        m.setTitle("Mail-Me!");
        m.resize(300,200);
        m.show();
    }
}

class nafi
{
    int x_pos, y_pos, width, height;
    public nafi(int x, int y, int w, int h)
    {
        x_pos = x;
        y_pos = y;
        width = w;
        height = h;
    }

    public int getX_pos()
    {
        return x_pos;
    }
    public int getY_pos()
    {
        return y_pos;
    }
    public int getWidth()
    {
        return width;
    }
    public int getHeight()
    {
        return height;
    }

}