App.Views.EmailButtonBar = Backbone.View.extend({
	template:_.template( $("#buttonbar-template").html() ),
	primaryButtonId: 'compose-mail-button',
	primaryButtonName: 'Compose',
	searchElementId:'search-email',
	events : {
		'click #get-mail-button':'getMail',
		'click #help-mail-button':'goToHelp'
	},
	

	buttons: [
	{
		id:'compose-mail',
		icon:"icon-compose_fill",
		text: "New Email",
		dropdown:false,
		context:['default','single-select','multi-select']
	},
	{
		id:'get-mail',
		icon:'icon-mail_refresh_fill',
		text:'Get Email',
		dropdown:false,
		context: ['default','single-select','multi-select']
	},
	/*
	{
		id:"sort-mail",
		icon:'icon-sort_fill',
		text:'Sort',
		dropdown:true,
		context: ['initial']
	},
	*/
	{
		id:'mark-mail',
		icon:'icon-check_fill',
		text:'Mark As',
		dropdown:true,
		context: ['single-select','multi-select']
	},
	{
		id:'more-mail',
		icon:'icon-more_fill',
		text:'More',
		dropdown:true,
		context: ['single-select','multi-select']
	},
	{
		id:'reply-mail',
		icon:'icon-email_reply_fill',
		text:'Reply',
		dropdown:false,
		context: ['single-select']
	},
	{
		id:'reply-all-mail',
		icon:'icon-email_replyall_fill',
		text:'Reply All',
		dropdown:false,
		context: ['single-select']
	},
	{
		id:'forward-mail',
		icon:'icon-email_forward_fill',
		text:'Forward',
		dropdown:false,
		context: ['single-select']
	},
	{
		id:'send-mail',
		icon:'icon-send_fill',
		text:'Send',
		dropdown:false,
		context: ['compose']
	},
	{
		id:'attach-mail',
		icon:'icon-attach_fill',
		text:'Attach',
		dropdown:false,
		context: ['compose']
	},
	{
		id:'save-draft-mail',
		icon:'icon-draft_fill',
		text:'Save Draft',
		dropdown:false,
		context: ['compose']
	},
	{
		id:'read-receipt-mail',
		icon:'icon-read_receipt',
		text:'Receipt',
		context: ['compose']
	},
	{
		id:'delete-mail',
		icon:'icon-trash_fill',
		text:'Delete',
		dropdown:false,
		context: ['multi-select','single-select','compose']
	},
	{
		id:'help-mail',
		icon:'icon-help_fill',
		text:'Help',
		dropdown:false,
		context: ['default']
	}],

	render: function(){
		var html = this.template();
		$(this.el).append( html );
		return this;
	},

	setStateInit: function(e){ App.emailChrome.buttonBar.setState('initial'); },
	setStateMulti: function(e){ App.emailChrome.buttonBar.setState('multi-select'); },
	setStateSingle: function(e){ App.emailChrome.buttonBar.setState('single-select'); },
	setStateCompose: function(e){ App.emailChrome.buttonBar.setState('compose'); },
	setState:function(state){
		
		this.$el.find("li:not(."+state+", .default)").hide();
		this.$el.find("."+state).show();
	},
	
	getMail : function(e){
		
		this.trigger('get-mail',e);
	},
	
	goToHelp : function(e){
		
		this.trigger('get-to-help',e);
	}
	
});
