
var TourOperatorCategoryBlock = new Class({
	
	initialize : function(id, is_collapsable)
	{
		var el = $(id);
		if (!el) return;
		
		this.header_el = el;
		this.content = el.getNext();
				
		if (is_collapsable) this.makeCollapsable();
	},
	
	makeCollapsable : function()
	{
		this.content.setStyle('display', 'none');
		
		this.header_el.setStyle('cursor', 'pointer');
		this.header_el.addEvent('click', this.toggleCollapse.bind(this));
		this.header_el.addEvent('mouseover', this.hoverBar.bind(this));
		this.header_el.addEvent('mouseout', this.dehoverBar.bind(this));
		
		var button= new Element('div');
		button.className = 'tours-options-expand';
		button.inject(this.header_el, 'top');
		this.collapse_button = button;
		
		this.header_el.onselectstart = function()
		{
		    return false;
		};
		this.header_el.onmousedown = function()
		{
		    return false;
		};
	},

	
	hoverBar : function()
	{
		this.header_el.removeClass('blue');
		this.header_el.addClass('lblue');
	},
	
	dehoverBar : function()
	{
		this.header_el.removeClass('lblue');
		this.header_el.addClass('blue');
	},
	
	toggleCollapse : function(ev)
	{
		ev = new Event(ev);
		ev.preventDefault();
		
		var state = (this.content.getStyle('display') == 'block') ? 'none' : 'block';
		 
		this.content.setStyle('display', state);
		
		
		this.collapse_button.className = (state == 'none') ? 'tours-options-expand':  'tours-options-collapse';
	}
});

var TourOperatorLocationBlock = new Class({
	
	initialize : function(id, selected_tab, is_collapsable)
	{
		var el = $(id);
		if (!el) return;
		
		this.tab_el = el;
		this.tabs = new TabbedSection(el);
		this.content = el.getParent().getNext();
		this.header_el = el.getParent().getPrevious();
		
		this.tabs.addEvent('changed', this.tabChanged.bind(this));
		
		this.updateTab(selected_tab);
				
		if (is_collapsable) this.makeCollapsable();
	},
	
	makeCollapsable : function()
	{
		this.tab_el.getParent().setStyle('display', 'none');
		this.content.setStyle('display', 'none');
		
		this.header_el.setStyle('cursor', 'pointer');
		
		this.header_el.addEvent('click', this.toggleCollapse.bind(this));
		this.header_el.addEvent('mouseover', this.hoverBar.bind(this));
		this.header_el.addEvent('mouseout', this.dehoverBar.bind(this));
		
		var button= new Element('div');
		button.className = 'tours-options-expand';
		button.inject(this.header_el, 'top');
		this.collapse_button = button;
		
		this.header_el.onselectstart = function()
		{
		    return false;
		};
		this.header_el.onmousedown = function()
		{
		    return false;
		};
	},
	
	hoverBar : function()
	{
		this.header_el.removeClass('blue');
		this.header_el.addClass('lblue');
	},
	
	dehoverBar : function()
	{
		this.header_el.removeClass('lblue');
		this.header_el.addClass('blue');
	},
	
	toggleCollapse : function(ev)
	{
		ev = new Event(ev);
		ev.preventDefault();
		
		var state = (this.content.getStyle('display') == 'block') ? 'none' : 'block';
		 
		this.tab_el.getParent().setStyle('display', state);
		this.content.setStyle('display', state);
		
		this.collapse_button.className = (state == 'none') ? 'tours-options-expand':  'tours-options-collapse';
	},
	
	tabChanged : function(el, tab_id)
	{
		tab_id = tab_id.substring(9);
		
		this.updateTab(tab_id);
	},
	
	updateTab : function(tab_id)
	{
		var tab_panels = $$('.locations-tab-panel');
		
		var id = 'locations-'+tab_id;
		
		tab_panels.each(function (el){
			el.setStyle('display', (el.id == id) ? 'block' : 'none');
		});
	}
});