/*
 * Vroomtrap
 * Copyright(c) 2008, Nubesoft, LLC.
 */
Ext.namespace('Ext.toppanel');
// var imgButtonTpl = new Ext.Template(
//     '<table border="0" cellpadding="0" cellspacing="0" class="x-btn-wrap"><tbody><tr>' +
//     '<button type="button"><img src="{0}"></button>' +
//     '</tr></tbody></table>');
Ext.toppanel.searchField = new Ext.app.SearchField({id: 'searchTrapsField'});
Ext.toppanel.toppanel = new Ext.Panel({
  	region:'north',
    height:100,
    bodyBorder: false,
    layout: 'border',
    items: [{
      region      : 'center',
      bodyStyle: 'padding:12px;',
      deferredRender:false,
      border: true,
      items: [{
        layout: 'anchor',      
        items:[{
          html: '<span class="search-text">Search: </span>'
        },Ext.toppanel.searchField
        ]
      }]
    },{
      region: 'west',
      width: 284,
      html: '<img src="/static/images/logo-vroomtrap-reflection.png">'
    },{
      region: 'east',
      width: 220,
      html: '<div id="msg-ct"><div id="msg"><div id="msg-inner"></div></div></div>'
    }],
    tbar: [
				'->',
        '<a href="#" onclick="facebooklogin(); return false;"><img id="fb_login_image" src="http://static.ak.fbcdn.net/images/fbconnect/login-buttons/connect_dark_medium_short.gif" alt="Connect"/></a>'
        ,'-',
				new Ext.Button({
				  text: 'Sign In',
				  iconCls: 'icngoogle',
				  id: 'signin',
					handler  : function(){
              Ext.Ajax.request({
              	url : 'proxy' , 
              	params : { v : 'login' },
              	method: 'GET',
              	success: function ( result, request ) { 
              	  data = Ext.util.JSON.decode(result.responseText);
              		location.replace(data.login);
              	},
              	failure: function ( result, request) { 
              		Ext.MessageBox.alert('Failed', result.responseText); 
              	} 
              });
          }
        }),'-',{
          text: 'Downloads',
          handler: function(){
            nubesoft.google.Vroomtrap.addTab("/downloads");
          }
				},'-',{
  					text: 'Help',
  					menu: [
  						new Ext.Action({
  						  text: 'Website',
  						  iconCls:'icnwww',
  						  handler : function(){
                  nubesoft.google.Vroomtrap.addTab("/help/website");
  						  }
      				}),
    					new Ext.Action({
  						  text: 'iPhone',
  						  iconCls:'icnapple',
  						  handler : function(){
                  nubesoft.google.Vroomtrap.addTab("/help/iphone");
  						  }
      				}),
      				new Ext.Action({
  						  text: 'Browser Compatibility',
  						  iconCls:'icnhtmlvalid',
  						  handler : function(){
                  nubesoft.google.Vroomtrap.addTab("/help/browser-compatibility");
  						  }
      				})
  					]
				},'-',{
  					text: 'Video',
  					menu: [
  						new Ext.Action({
  						  text: 'Website Getting Started',
  						  iconCls:'iconv',
  							handler  : function(){
                  Ext.videowindow.videowindow.openVideoWindow(0,"/video/website-getting-started");
                }
  						}),
  						new Ext.Action({
  						  text: 'iPhone Getting Started',
  						  iconCls:'icnapple',
  							handler  : function(){
                  Ext.videowindow.videowindow.openVideoWindow(1,"/video/iphone-getting-started");
                }						  
  						})]
  				},'-',
  				new Ext.Button({
  				  text: 'About',
    				handler  : function(){
               Ext.aboutwindow.aboutwindow.openAboutWindow();
               
            }
  				}) 
    ]
});

Ext.toppanel.loadusersettings = function() {  
  nubesoft.google.Vroomtrap.loggedIn = false;
}

Ext.onReady(Ext.toppanel.loadusersettings, Ext.toppanel.searchField, Ext.toppanel.toppanel);