// Realis d.o.o. (c) 2007
//
//=============================================================
// Page layout
// ------------------------------------------------------------
// 
//=============================================================


//desable context menu on body
Ext.get(document.body).on('contextmenu', function(e){e.stopEvent();});


//main page
var innerLayout;
var Page = function()
{
    var layout;
    
    return {
           
        init : function(){
           
           Ext.QuickTips.init();
                                                                
           layout = new Ext.BorderLayout(document.body, {
                north: {
                    split:false,
                    initialSize: 130,
                    titlebar: false
                },
                center: {
                    titlebar: false,
                    autoScroll:false,
                    closeOnTab: true,
                    alwaysShowTabs: false
                }
            });
            innerLayout = new Ext.BorderLayout(document.getElementById("pagecontent"), {
                west: {
                    split:true,
                    initialSize: Math.max(applicationSettings.panelWidth, 280 + Math.max(0,document.body.offsetWidth-600)*0.1),
                    minSize: 25,
                    maxSize: 9999,
                    titlebar: false,
                    collapsible: true,
                    animate: true,
                    tabPosition: "top"
                },
                center: {
                    titlebar: false,
                    autoScroll: false,
                    closeOnTab: true
                }
            });
           
            layout.beginUpdate();
                   
            var searchManager = new MKSearch({elementId: 'rmapSearch'});    
            var searchLayout = searchManager.layout;
            innerLayout.add('west', new Ext.NestedLayoutPanel(searchLayout, {title: lngDict["tabSearch"]}));
            var layerListContentPanel = new Ext.ContentPanel('layerListContainer', {title: lngDict["tabCnts"], fitToFrame: true});
            layerListContentPanel.addListener('resize', onResize);
            innerLayout.add('west', layerListContentPanel);           
            innerLayout.add('west', new Ext.ContentPanel('locationsListContainer', {autoCreate:true, title: lngDict["tabLocs"], fitToFrame: true, autoScroll:true}));
            innerLayout.add('west', new Ext.ContentPanel('routingContainer', {title: lngDict["tabRout"], fitToFrame: true, autoScroll:true}));
            
            var mapContentPanel = new Ext.ContentPanel('mapContainer', {fitToFrame: true});
            mapContentPanel.addListener('resize', onResize);
            innerLayout.add('center', mapContentPanel);
            innerLayout.getRegion('center').el.unselectable();
                              
            var tb = new Ext.Toolbar('toolbar', pageMenu);
            layout.add('north', new Ext.ContentPanel('pageheader', {fitToFrame:true, toolbar: tb, resizeEl:'titlebar'}));
            layout.add('center', new Ext.NestedLayoutPanel(innerLayout));
            innerLayout.getRegion('west').showPanel('layerListContainer');
            layout.endUpdate();	    
            
            var loading = Ext.get('loading');
						var mask = Ext.get('loading-mask');
						mask.setOpacity(.8);
						mask.shift({
		        xy:loading.getXY(),
		        width:loading.getWidth(),
		        height:loading.getHeight(), 
		        remove:true,
		        duration:1,
		        opacity:.3,
		        easing:'bounceOut',
		        callback : function(){loading.fadeOut({duration:.2,remove:true}); }
	        });
	        innerLayout.regions.west.resizeTo(innerLayout.regions.west.panelSize.width);
	     }
	   };
}();


var msgCt=Ext.DomHelper.insertFirst(document.body, {id:'msg-div'}, true);
msgCt.alignTo(document, 't-t');
var alertMessage=function(msg,type,title)
{   
  if(type=="INFO")
  {   
      msgCt.alignTo(document, 't-t');          
      var s = msg;
      var m = Ext.DomHelper.append(msgCt, {html:createBox("INFORMACIJA", s)}, true);
      m.slideIn('t').pause(5).ghost("t", {remove:true});
  }
  else
  {
      if(title==null)
          title="Sporočilo";
      Ext.MessageBox.alert(title, msg);
  }
}  
      
var createBox=function(t, s)
{
    return ['<div class="msg">',
            '<div class="x-box-tl"><div class="x-box-tr"><div class="x-box-tc"></div></div></div>',
            '<div class="x-box-ml"><div class="x-box-mr"><div class="x-box-mc"><h3>', t, '</h3><br/>', s, '</div></div></div>',
            '<div class="x-box-bl"><div class="x-box-br"><div class="x-box-bc"></div></div></div>',
            '</div>'].join('');
}

