/*
 /*
 * Earth Atlas 0.3
 * Copyright(c) 2008, Bjorn Sandvik
 * bjorn@thematicmapping.org
 *
 * Danish version
 * Søren Johannessen Copyright(c) 2008
 * http://www.microformats.dk/om/
 * Under en GNU General Public License v3 http://www.gnu.org/copyleft/gpl.html
 */
google.load("earth", "1");
google.load("maps", "2.xx");


Ext.onReady(function(){


    var params = Ext.urlDecode(window.location.search.substr(1));
    
    var gEarthPanel = new Ext.ux.GEarthPanel({
        region: 'center',
        contentEl: 'center',
        id: 'earthPanel',
        margins: '0 5 0 0'
    });
    
    var viewport = new Ext.Viewport({
        layout: 'border',
        items: [{
            region: 'north',
            contentEl: 'north',
            margins: '0 0 5 0'
        }, gEarthPanel, {
            region: 'west',
            contentEl: 'west',
            id: 'controlPanel',
            title: 'Touring Ireland',
            split: true,
            width: 250,
            minSize: 175,
            maxSize: 330,
            collapsible: true,
            margins: '0 0 0 5',
            layout: 'accordion',
            layoutConfig: {
                animate: true
            },
            defaults: {
                bodyStyle: 'padding: 3px 7px'
            }
        }        /* botom viewport removed - also need to remove calls for its content within 'Ext.ux.GEarthPanel.js' .k
         ,{
         region: 'south',
         contentEl: 'south',
         id: 'sourcePanel',
         split: true,
         height: 90,
         minSize: 50,
         maxSize: 200,
         collapsible: true,
         title: 'More Information',
         bodyStyle: 'padding: 5px',
         margins: '0 5 5 5'
         }*/
        ]
    });
	    
    var kmlAccomodation = new Ext.data.SimpleStore({
        fields: ['name', 'description', 'source', 'sourceUrl', 'credit', 'kmlUrl'],
        data: [
		/*['error', 'Hotels in Ireland', 'Touring Ireland', 'http://www.touringireland.com/', 'The Touring Ireland Team', 'http://touringireland.com/mapData/kml/errorKML.php?g4yhg69'],*/
		/*['Hotels', 'Hotels in Ireland', 'Touring Ireland', 'http://www.touringireland.com/', 'The Touring Ireland Team', 'http://touringireland.com/mapData/kml/getKML.php?cat1=3&cat2=12&rand=uetrt2'],*/
		/*['Hotels lod db', 'Hotels in Ireland', 'Touring Ireland', 'http://www.touringireland.com/', 'The Touring Ireland Team', 'http://touringireland.com/mapData/kml/getKML.php?cat1=3&cat2=12'],
		['Hotels kml static', 'Hotels in Ireland', 'Touring Ireland', 'http://www.touringireland.com/', 'The Touring Ireland Team', 'http://touringireland.com/hotelStaticTemp.kml'],*/
		['Hotels', 'Hotels in Ireland', 'Touring Ireland', 'http://www.touringireland.com/', 'The Touring Ireland Team', 'http://touringireland.com/mapData/kml/getKML.php?cat1=3&cat2=12'],
		
		['Guest Houses', 'Guest Houses', 'Touring Ireland', 'http://www.touringireland.com/', 'The Touring Ireland Team', 'http://touringireland.com/mapData/kml/getKML.php?cat1=3&cat2=13&rand=trtrt2'],
		['Bed & Breakfast', 'Bed & Breakfast', 'Touring Ireland', 'http://www.touringireland.com/', 'The Touring Ireland Team', 'http://touringireland.com/mapData/kml/getKML.php?cat1=3&cat2=14'],
		['Self Catering', 'Self Catering', 'Touring Ireland', 'http://www.touringireland.com/', 'The Touring Ireland Team', 'http://touringireland.com/mapData/kml/getKML.php?cat1=3&cat2=15'],
		['Caravan & Camping', 'Caravan & Camping', 'Touring Ireland', 'http://www.touringireland.com/', 'The Touring Ireland Team', 'http://touringireland.com/mapData/kml/getKML.php?cat1=3&cat2=16'],
		['Hostels', 'Hostels', 'Touring Ireland', 'http://www.touringireland.com/', 'The Touring Ireland Team', 'http://touringireland.com/mapData/kml/getKML.php?cat1=3&cat2=17'],
		['Student Accom', 'Student Accom', 'Touring Ireland', 'http://www.touringireland.com/', 'The Touring Ireland Team', 'http://touringireland.com/mapData/kml/getKML.php?cat1=3&cat2=18']/*,
		['Hotel Visibility Testr', 'Media', 'Touring Ireland', 'http://www.touringireland.com/', 'The Touring Ireland Team', 'http://touringireland.com/mapData/static/hotellod.kml'],*/
		]
    });
    
    
    
    var kmlTransportation = new Ext.data.SimpleStore({
        fields: ['name', 'description', 'source', 'sourceUrl', 'credit', 'kmlUrl'],
        data: [
		['Airports', 'Airports', 'Touring Ireland', 'http://www.touringireland.com/', 'The Touring Ireland Team', 'http://touringireland.com/mapData/kml/getKML.php?cat1=5&cat2=26'],
		['Ferries', 'Ferries', 'Touring Ireland', 'http://www.touringireland.com/', 'The Touring Ireland Team', 'http://touringireland.com/mapData/kml/getKML.php?cat1=5&cat2=27&jh665d'],
		['Trains Stations', 'Trains Stations', 'Touring Ireland', 'http://www.touringireland.com/', 'The Touring Ireland Team', 'http://touringireland.com/mapData/kml/getKML.php?cat1=5&cat2=28'],
		['Bus Stations', 'Bus Stations', 'Touring Ireland', 'http://www.touringireland.com/', 'The Touring Ireland Team', 'http://touringireland.com/mapData/kml/getKML.php?cat1=5&cat2=29'],
		['Car Rentals', 'Car Rentals', 'Touring Ireland', 'http://www.touringireland.com/', 'The Touring Ireland Team', 'http://touringireland.com/mapData/kml/getKML.php?cat1=5&cat2=30'],
		['Limo Hire', 'Limo Hire', 'Touring Ireland', 'http://www.touringireland.com/', 'The Touring Ireland Team', 'http://touringireland.com/mapData/kml/getKML.php?cat1=5&cat2=31'],
		['Coach & Bus Hire', 'Coach & Bus Hire', 'Touring Ireland', 'http://www.touringireland.com/', 'The Touring Ireland Team', 'http://touringireland.com/mapData/kml/getKML.php?cat1=5&cat2=32'],
		['Motorhome Rentals', 'Motorhome Rentals', 'Touring Ireland', 'http://www.touringireland.com/', 'The Touring Ireland Team', 'http://touringireland.com/mapData/kml/getKML.php?cat1=5&cat2=33'],
		['Helicopter & Aircraft Hire', 'Helicopter & Aircraft Hire', 'Touring Ireland', 'http://www.touringireland.com/', 'The Touring Ireland Team', 'http://touringireland.com/mapData/kml/getKML.php?cat1=5&cat2=35'],
		['Boat & Cruiser Hire', 'Boat & Cruiser Hire', 'Touring Ireland', 'http://www.touringireland.com/', 'The Touring Ireland Team', 'http://touringireland.com/mapData/kml/getKML.php?cat1=5&cat2=34'],
		['Berths & Marinas', 'Berths & Marinas', 'Touring Ireland', 'http://www.touringireland.com/', 'The Touring Ireland Team', 'http://touringireland.com/mapData/kml/getKML.php?cat1=5&cat2=36'],
		['Bike Hire', 'Bike Hire', 'Touring Ireland', 'http://www.touringireland.com/', 'The Touring Ireland Team', 'http://touringireland.com/mapData/kml/getKML.php?cat1=5&cat2=37']
		]
    });
    
    
    var kmlWhatToSeeAndDo = new Ext.data.SimpleStore({
        fields: ['name', 'description', 'source', 'sourceUrl', 'credit', 'kmlUrl'],
        data: [
		['Art, Culture & Museums', 'Art, Culture and Museums ', 'Touring Ireland', 'http://www.touringireland.com/', 'The Touring Ireland Team', 'http://touringireland.com/mapData/kml/getKML.php?cat1=1&cat2=1'],
		['Attractions & Visitors Centres', 'Attractions & Visitors Centres', 'Touring Ireland', 'http://www.touringireland.com/', 'The Touring Ireland Team', 'http://touringireland.com/mapData/kml/getKML.php?cat1=1&cat2=2'],
		['Festivals & Events', 'Festivals & Events', 'Touring Ireland', 'http://www.touringireland.com/', 'The Touring Ireland Team', 'http://touringireland.com/mapData/kml/getKML.php?cat1=1&cat2=3'],
		['Heritage Sites', 'Heritage Sites', 'Heritage Ireland', 'http://www.touringireland.com/', 'The heritage Ireland Team', 'http://touringireland.com/mapData/kml/getKML.php?cat1=1&cat2=4'],
		['Zoos Wildlife Parks and Gardens', 'Zoos, Wildlife Parks and Gardens', 'Touring Ireland', 'http://www.touringireland.com/', 'The Touring Ireland Team', 'http://touringireland.com/mapData/kml/getKML.php?cat1=1&cat2=5'],
		['Local Tours', 'Local Tours', 'Touring Ireland', 'http://www.touringireland.com/', 'The Touring Ireland Team', 'http://touringireland.com/mapData/kml/getKML.php?cat1=1&cat2=38']
		]
    });
    
    
    var kmlFoodAndEntertainment = new Ext.data.SimpleStore({
        fields: ['name', 'description', 'source', 'sourceUrl', 'credit', 'kmlUrl'],
        data: [
		['Restaurants', 'Restaurants', 'Touring Ireland', 'http://www.touringireland.com/', 'The Touring Ireland Team', 'http://touringireland.com/mapData/kml/getKML.php?cat1=4&cat2=19'],
		['Pubs', 'Pubs', 'Touring Ireland', 'http://www.touringireland.com/', 'The Touring Ireland Team', 'http://touringireland.com/mapData/kml/getKML.php?cat1=4&cat2=20'],
		['Shopping', 'Shopping', 'Touring Ireland', 'http://www.touringireland.com/', 'The Touring Ireland Team', 'http://touringireland.com/mapData/kml/getKML.php?cat1=4&cat2=21'],
		['Theaters', 'Theaters', 'Touring Ireland', 'http://www.touringireland.com/', 'The Touring Ireland Team', 'http://touringireland.com/mapData/kml/getKML.php?cat1=4&cat2=22&ds'],
		['Cinemas', 'Cinemas', 'Touring Ireland', 'http://www.touringireland.com/', 'The Touring Ireland Team', 'http://touringireland.com/mapData/kml/getKML.php?cat1=4&cat2=23'],
		['Night Clubs', 'Night Clubs', 'Touring Ireland', 'http://www.touringireland.com/', 'The Touring Ireland Team', 'http://touringireland.com/mapData/kml/getKML.php?cat1=4&cat2=24'],
		['Shows & Concerts', 'Shows & Concerts', 'Touring Ireland', 'http://www.touringireland.com/', 'The Touring Ireland Team', 'http://touringireland.com/mapData/kml/getKML.php?cat1=4&cat2=25']
		]
    });
    
    var kmlActivities = new Ext.data.SimpleStore({
        fields: ['name', 'description', 'source', 'sourceUrl', 'credit', 'kmlUrl'],
        data: [
		['Leisure', 'Leisure', 'Touring Ireland', 'http://www.touringireland.com/', 'The Touring Ireland Team', 'http://touringireland.com/mapData/kml/getKML.php?cat1=2&cat2=6&ksdjf'],
		['Golf', 'Golf', 'Touring Ireland', 'http://www.touringireland.com/', 'The Touring Ireland Team', 'http://touringireland.com/mapData/kml/getKML.php?cat1=2&cat2=46&ksdjf'],
		['Adventure', 'Adventure', 'Touring Ireland', 'http://www.touringireland.com/', 'The Touring Ireland Team', 'http://touringireland.com/mapData/kml/getKML.php?cat1=2&cat2=7'],
		['Spectator', 'Spectator', 'Touring Ireland', 'http://www.touringireland.com/', 'The Touring Ireland Team', 'http://touringireland.com/mapData/kml/getKML.php?cat1=2&cat2=8'],
		['For the Kids', 'For the Kids', 'Touring Ireland', 'http://www.touringireland.com/', 'The Touring Ireland Team', 'http://touringireland.com/mapData/kml/getKML.php?cat1=2&cat2=9'],
		['Blue Flag Beaches', 'Blue Flag Beaches', 'Touring Ireland', 'http://www.touringireland.com/', 'The Touring Ireland Team', 'http://touringireland.com/mapData/kml/getKML.php?cat1=6&cat2=40']/*,
		['Walking Routes', 'Walking Routes', 'Touring Ireland', 'http://www.touringireland.com/', 'The Touring Ireland Team', 'http://touringireland.com/mapData/kml/getKML.php?cat1=2&cat2=10'],
		['Cycling Routes', 'Cycling Routes', 'Touring Ireland', 'http://www.touringireland.com/', 'The Touring Ireland Team', 'http://touringireland.com/mapData/kml/getKML.php?cat1=2&cat2=11'],
		['Driving Routes', 'Driving Routes', 'Touring Ireland', 'http://www.touringireland.com/', 'The Touring Ireland Team', 'http://touringireland.com/mapData/kml/getKML.php?cat1=2&cat2=12']*/
		]
    });
    
    var kmlIreland = new Ext.data.SimpleStore({
        fields: ['name', 'description', 'source', 'sourceUrl', 'credit', 'kmlUrl'],
        data: [
		['Provinces', 'Provinces', 'Touring Ireland', 'http://www.touringireland.com/', 'The Touring Ireland Team', 'http://touringireland.com/mapData/static/provinces.kmz'],
		['Counties', 'Counties', 'Touring Ireland', 'http://www.touringireland.com/', 'The Touring Ireland Team', 'http://touringireland.com/mapData/static/counties.kmz'],
		/*['Geography', 'Geography', 'Touring Ireland', 'http://www.touringireland.com/', 'The Touring Ireland Team', 'http://touringireland.com/mapData/static/geography.kmz'],
		*/['Did you know', 'Did you know', 'Touring Ireland', 'http://www.touringireland.com/', 'The Touring Ireland Team', 'http://touringireland.com/mapData/kml/getKML.php?cat1=6&cat2=43&342234'],
		['Movie Locations', 'Movie Locations', 'Touring Ireland', 'http://www.touringireland.com/', 'The Touring Ireland Team', 'http://touringireland.com/mapData/kml/getKML.php?cat1=6&cat2=42'],
		['Webcams', 'Webcams', 'Touring Ireland', 'http://www.touringireland.com/', 'The Touring Ireland Team', 'http://touringireland.com/mapData/kml/getKML.php?cat1=6&cat2=45&rand=44653'],
		['Embassies & Consulates', 'Embassies & Consulates', 'Touring Ireland', 'http://www.touringireland.com/', 'The Touring Ireland Team', 'http://touringireland.com/mapData/kml/getKML.php?cat1=6&cat2=41']
		/*,
		['Media', 'Media', 'Touring Ireland', 'http://www.touringireland.com/', 'The Touring Ireland Team', 'http://touringireland.com/mapData/kml/getKML.php?cat1=6&cat2=44'],
		['Street Veiw Test', 'Media', 'Touring Ireland', 'http://www.touringireland.com/', 'The Touring Ireland Team', 'http://touringireland.com/mapData/static/streetview.kml'],
		['Street Veiw Test 2', 'Media', 'Touring Ireland', 'http://www.touringireland.com/', 'The Touring Ireland Team', 'http://touringireland.com/mapData/static/streetview2.kmz'],
		['ktesting', 'Media', 'Touring Ireland', 'http://www.touringireland.com/', 'The Touring Ireland Team', 'http://touringireland.com/mapData/static/lodtest.kml'],
		['lodtest', 'Media', 'Touring Ireland', 'http://www.touringireland.com/', 'The Touring Ireland Team', 'http://touringireland.com/mapData/static/hotellod.kml']*/
		]
    });
    
    var kmlHistoricMaps = new Ext.data.SimpleStore({
        fields: ['name', 'description', 'source', 'sourceUrl', 'credit', 'kmlUrl'],
        data: [['Ireland 1702', 'Ireland 1702', 'Touring Ireland', 'http://www.touringireland.com/', 'The Touring Ireland Team', 'http://touringireland.com/noel/touring99.kml'],
		['Ireland 1716', 'Ireland 1716', 'Touring Ireland', 'http://www.touringireland.com/', 'The Touring Ireland Team', 'http://touringireland.com/noel/kmz/HistoricMaps/Ireland1716.kml'],
		['Ireland 1794', 'Ireland 1794', 'Touring Ireland', 'http://www.touringireland.com/', 'The Touring Ireland Team', 'http://touringireland.com/noel/kmz/HistoricMaps/Ireland1794.kml'],
		['Ireland 1808', 'Ireland 1808', 'Touring Ireland', 'http://www.touringireland.com/', 'The Touring Ireland Team', 'http://touringireland.com/noel/kmz/HistoricMaps/Ireland1808.kml']
		]
    });
    
    
    
    
    
    
    
    // Build control panel
    gEarthPanel.on('earthLoaded', function(earthPanel){
        var controlPanel = Ext.getCmp('controlPanel');
        
        controlPanel.add({
            xtype: 'panel',
            id: 'Ireland',
            title: 'Ireland',
            items: earthPanel.addKmlCheckbox(kmlIreland)
        });
        
        controlPanel.add({
            xtype: 'panel',
            title: 'What to see & do',
            items: earthPanel.addKmlCheckbox(kmlWhatToSeeAndDo)
        });
        
        controlPanel.add({
            xtype: 'panel',
            title: 'Activities',
            items: earthPanel.addKmlCheckbox(kmlActivities)
        });
        
        controlPanel.add({
            xtype: 'panel',
            id: 'accomodation',
            title: 'Accommodation',
            items: earthPanel.addKmlCheckbox(kmlAccomodation)
        });
        
        controlPanel.add({
            xtype: 'panel',
            title: 'Food & Entertainment',
            items: earthPanel.addKmlCheckbox(kmlFoodAndEntertainment)
        });
        
        
        controlPanel.add({
            xtype: 'panel',
            title: 'Transportation',
            items: earthPanel.addKmlCheckbox(kmlTransportation)
        });
        
        
        /*
         controlPanel.add({
         xtype: 'panel',
         title: 'Historic Maps',
         items: earthPanel.addKmlCheckbox(kmlIreland)
         });
         */
        controlPanel.add({
            xtype: 'panel',
            title: 'Earth Layers',
            items: earthPanel.getLayers()
        });
		      controlPanel.add({
            xtype: 'panel',
            title: 'Map Options',
            items: earthPanel.getOptions()
        });
		
		     controlPanel.doLayout();
        
        if (params.kml) {
            earthPanel.fetchKml(params.kml);
            Ext.getCmp('kmlTree').expand();
        }
		
try {

            var myAdID = parseFloat(document.getElementById('viewAdID').value);
        } 
        catch (err) {
            //  alert("error county not load individual ad ");
        }
        if (myAdID) { // check if it exists, if no ind ad is requested it wont .k
           var viewAdURL = 'http://touringireland.com/mapData/kml/getKML.php?adID=' + myAdID;
            this.fetchKml(viewAdURL);
        }
		
		//gEarthPanel
	
/*
    var lookAt = earthPanel.createLookAt('');
   lookAt.set(53.3047,-7.91, 8, earthPanel.ALTITUDE_RELATIVE_TO_GROUND, 0, 0, 600000);
   earthPanel.getView().setAbstractView(lookAt);*/
  
    gEarthPanel.fetchKml('http://touringireland.com/mapData/kml/getKML.php?cat1=7&cat2=47');
  //gEarthPanel.fetchKml('http://touringireland.com/ktest/lookat.kml');
  
  //gEarthPanel.fetchKml('http://touringireland.com/mapData/kml/getKML.php?cat1=3&cat2=13');

   
  
   
  // gEarthPanel.findLocation('Kerry');
  
  /*
  var myLaLat = parseFloat(document.getElementById('laLat').value);
		var myLaLng = parseFloat(document.getElementById('laLng').value);
		var myLaZoom = parseFloat(document.getElementById('laZoom').value);
		alert("lat - " + myLaLat + " lng - " + myLaLng + " zoom - " + myLaZoom);
   
   //gEarthPanel.zoomArea(53.3047, -7.91, 8);
   
   gEarthPanel.zoomArea(myLaLat, myLaLng, myLaZoom);
   */
  
   // gEarthPanel.zoomArea(52, -9, 8);
	
	//getPop();
       
    });
    
});





