package example.com.velezguiatour;

import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import android.widget.TabHost;
import android.widget.Toast;

public class Visita extends TabActivity
{

    private ListView list,list2,list3;
    private LazyAdapter adapter,adapter2,adapter3; 
    private int nObras = 5;
	private String[][] piso1 = new String[nObras][nObras];
	private String[][] piso2 = new String[nObras][nObras];
	private String[][] piso3 = new String[nObras][nObras];
	
    /** Called when the activity is first created. */	
	@Override public void onCreate(Bundle savedInstanceState)
	{	 
		super.onCreate(savedInstanceState);
		setContentView(R.layout.visita);
		
		TabHost tabHost = getTabHost();
		tabHost.addTab(tabHost.newTabSpec("tab1").setIndicator(getResources().getString(R.string.first_floor), getResources().getDrawable(R.drawable.ic_menu_gallery)).setContent(R.id.tab1Layout));
		tabHost.addTab(tabHost.newTabSpec("tab2").setIndicator(getResources().getString(R.string.second_floor), getResources().getDrawable(R.drawable.ic_menu_gallery_2)).setContent(R.id.tab2Layout));
		tabHost.addTab(tabHost.newTabSpec("tab3").setIndicator(getResources().getString(R.string.third_floor), getResources().getDrawable(R.drawable.ic_menu_gallery_3)).setContent(R.id.tab3Layout));

		initString();
		
		/* Se carga lista de Obras del Piso1*/
		list = (ListView)findViewById(R.id.list);
		adapter = new LazyAdapter(this, piso1, 1);
		list.setAdapter(adapter);
		list.setItemsCanFocus(true);
		list.setOnItemClickListener(new OnItemClickListener()
		{
			@Override public void onItemClick(AdapterView<?> arg0, View arg1, int position, long id)
			{
				Toast.makeText(getApplicationContext(), piso1[position][1], Toast.LENGTH_LONG).show();
				if (position < nObras)
				{
					Intent intent = new Intent(arg1.getContext(), Gallery.class);
					intent.putExtra("position", position);
					intent.putExtra("files", piso1[position][0]);
					intent.putExtra("title", piso1[position][1]);
					startActivityForResult(intent,0);
				}
			}
		});
		
		list2 = (ListView)findViewById(R.id.list2);
		adapter2 = new LazyAdapter(this, piso2, 2);
		list2.setAdapter(adapter2);
		list2.setItemsCanFocus(true);
		list2.setOnItemClickListener(new OnItemClickListener()
		{
			@Override public void onItemClick(AdapterView<?> arg0, View arg1, int position, long id)
			{
				Toast.makeText(getApplicationContext(), piso2[position][1], Toast.LENGTH_LONG).show();
				if (position < nObras)
				{
					Intent intent = new Intent(arg1.getContext(), Gallery.class);
					intent.putExtra("position", position);
					intent.putExtra("files", piso2[position][0]);
					intent.putExtra("title", piso2[position][1]);
					startActivityForResult(intent,0);
				}
			}
		});
		
		/* Se carga lista de Obras del Piso3*/
		list3 = (ListView)findViewById(R.id.list3);
		adapter3 = new LazyAdapter(this, piso3, 3);
		list3.setAdapter(adapter3);
		list3.setItemsCanFocus(true);
		list3.setOnItemClickListener(new OnItemClickListener()
		{
			@Override public void onItemClick(AdapterView<?> arg0, View arg1, int position, long id)
			{
				Toast.makeText(getApplicationContext(), piso3[position][1], Toast.LENGTH_LONG).show();
				if (position < nObras)
				{
					Intent intent = new Intent(arg1.getContext(), Gallery.class);
					intent.putExtra("position", position);
					intent.putExtra("files", piso3[position][0]);
					intent.putExtra("title", piso3[position][1]);
					startActivityForResult(intent,0);
				}
			}
		});
	}
	
	private void initString()
    {
		piso1[0][0] = "juan";
		piso1[0][1] = "Iglesia de San Juan Bautista";
		piso1[1][0] = "cerro";
		piso1[1][1] = "Ermita de la Virgen de los Remedios";
		piso1[2][0] = "maria";
		piso1[2][1] = "Iglesia de Santa Maria de la Encarnacion";

		
		piso2[0][0] = "fortaleza";
		piso2[0][1] = "La Fortaleza";
		piso2[1][0] = "beniel";
		piso2[1][1] = "Palacio del Marques de Beniel";
		piso2[2][0] = "cervantes";
		piso2[2][1] = "Casa Cervantes";

		
		piso3[0][0] = "villa";
		piso3[0][1] = "Puerta Real de la Villa y las murallas de la Medina";
		piso3[1][0] = "arco";
		piso3[1][1] = "Arco Mihrab";
		piso3[2][0] = "fernando";
		piso3[2][1] = "Fuente de Fernando VI";

		
    } 
	    
    @Override public void onDestroy()
	{
        list.setAdapter(null);
        super.onDestroy();
    }
            
    @Override public boolean onCreateOptionsMenu(Menu menu)
    {
    	super.onCreateOptionsMenu(menu);
    	MenuInflater inflater = getMenuInflater();
    	inflater.inflate(R.menu.menu_main, menu);
    	return true;
    }
    

    


    public OnClickListener listener = new OnClickListener()
    {
    	@Override public void onClick(View arg0)
    	{
            adapter.imageLoader.clearCache();
            adapter.notifyDataSetChanged();
        }    	 
    };


    public void clickPresentacion(View view)
    {
    	Intent intent = new Intent(view.getContext(), Gallery.class);
		intent.putExtra("position", 6);
		intent.putExtra("files", "presentacion");
		intent.putExtra("title", "PRESENTACIÓN");
		startActivityForResult(intent,0);
	}

       
}