

var xt = Ext.tree;


function showLocation(node, detail)
{
    if(!node.attributes.x || !node.attributes.y)
        return;
        
//    map.setCenter(node.attributes.x, node.attributes.y);
//    if(detail && map.getZoomLevel() > 1)
//        map.setZoomLevel(1);
//		if(node.attributes.text && node.parentNode.text)
//			map.openInfoWindow(node.parentNode.text+": "+node.attributes.text);
//			
		if(detail)
			map.setView(node.attributes.x, node.attributes.y, Math.min(map.getZoomLevel(),map.getDetailZoomLevel())); 
    else
      map.setCenter(node.attributes.x, node.attributes.y);
		if(node.attributes.text && node.parentNode.text)
			map.openInfoWindow(node.parentNode.text+": "+node.attributes.text);
}

var stree = new xt.TreePanel('locationsListContainer', {
        animate:true,
        enableDrag:false,
        containerScroll: true,
        rootVisible:false
    });


var sroot = new xt.AsyncTreeNode({
        text: 'Lokacije',
        id: 'croot',
        loader: new xt.TreeLoader({dataUrl: applicationSettings.locationsUri, requestMethod: 'GET'}),
        draggable: false
    });
    

    
    
    
stree.addListener('click', function(node,e){showLocation(node, false);});
stree.addListener('dblclick', function(node,e){showLocation(node, true);});
    
stree.setRootNode(sroot);
stree.render();
sroot.expand(false, false);




