js.module('jumpers');

window.addEvent('domready', function(){jumpers.loadCurrentOfficeInfoPanel();});

jumpers = {
	curr_header_panel : false,
	curr_office_section : false,
	office_hybrid_link : false,
	is_progress : false,
	
	refreshUserAccounts : function()
	{
		//top_user_accounts_div
		new AJAX(js.getAjaxPath('accounts.reload'), null, true, 'top_user_accounts_div', true);
	}
	,
	toggle : function(id)
	{
	    for(var i=0; i<10; i++)
	    {
	      if($('megalink_'+i))
	      {
	    	  if(id==i)
	    		  visual.setColor('megalink_'+i, 'brown');
	    	  else
	    		  visual.setColor('megalink_'+i, '');
	      }
	    	
	      if($('jumper_td_'+i))
	      {
	      	if(id==i)
	      		visual.show($('jumper_td_'+i));
	      	else
	      		visual.hide($('jumper_td_'+i));
	      }
	    }
	
	    common.cookie('last_main_page_tab', id, 'never');
	}
	,
	init : function()
	{
	    var num = common.getCookie('last_main_page_tab');
	    if(num=='' || num=='undefined' || num==null || !$('megalink_'+num) || !$('jumper_td_'+num))
	      num=1;	    	
	    
	  	this.toggle(num);
	}
	,
	toggleOfficeInfoPanel : function(id)
	{
		if(jumpers.is_progress) return;
		
		if(id==jumpers.curr_header_panel) return;
		
		jumpers.is_progress=true;
		
		if(jumpers.curr_header_panel !== false)
		{
			var hidef = new Fx.Morph('office_info_panel_'+jumpers.curr_header_panel, {duration:200}).set({'opacity' : 1 });
			visual.setColor('office_info_panel_button_'+jumpers.curr_header_panel,'black');
			hidef.start({'opacity':0.1}).chain(function(){ jumpers.showOfficeInfoPanel(id); });
		}
		else
		{
			jumpers.showOfficeInfoPanel(id);
		}
	}
	,
	showOfficeInfoPanel : function(id,immed)
	{
		visual.hide('office_info_panel_'+jumpers.curr_header_panel);
		visual.show('office_info_panel_'+id);
		
		if(immed==undefined)
		{
			var showf = new Fx.Morph('office_info_panel_'+id, {duration:200}).set({'opacity' : 0.1 });
			showf.start({'opacity':1}).chain(function () {jumpers.is_progress=false;visual.setColor('office_info_panel_button_'+id,'brown');});
		}
		else
		{
			jumpers.is_progress=false;
			visual.setColor('office_info_panel_button_'+id,'brown');
		}
		
		jumpers.curr_header_panel = id;
		common.cookie('office-info-last-panel', id, "never", '/', '.'+js.server_url);
	}
	,
	loadCurrentOfficeInfoPanel : function()
	{
		for(var i=1;i<5;i++)
		{
			if($('office_info_panel_button_'+i))
			{
				visual.disableSelection($('office_info_panel_button_'+i),'pointer');
			}
		}
		var last_panel = 1;
		if($('office_info_panel_'+common.getCookie('office-info-last-panel')))
			last_panel = common.getCookie('office-info-last-panel');
		jumpers.showOfficeInfoPanel(last_panel,true);
	}
	,
	toggleOfficeSection : function(id)
	{
		if(jumpers.curr_office_section!==false)
		{
			visual.setClass($('office_section_button_'+jumpers.curr_office_section), 'deco_text');
			visual.hide($('office_section_panel_'+jumpers.curr_office_section));
		}
		
		visual.setClass($('office_section_button_'+id), 'deco_text gray_table_current');
		
		visual.show($('office_section_panel_'+id));

		common.cookie('office_last_section', id, "never", '/', '.'+js.server_url);
		jumpers.curr_office_section=id;

		jumpers.loadSpecialOfficeSection(id);
	}
	,
	toggleOfficeSectionMenu : function(id)
	{
		jumpers.toggleOfficeSection(id);
		menu.hideAll();
	}
	,
	loadSpecialOfficeSection : function(id)
	{
		if($('office_section_panel_'+id) && $A('office_section_panel_'+id, 'special')==1)
		{
			if($A('office_section_panel_'+id, 'loaded')!=1)
			{
				$A('office_section_panel_'+id, 'loaded', 1);
				new AJAX(js.getAjaxPath('customsects.loader'), 'sect_id='+$P(id), true, 'office_special_section_'+id+'_content');
			}
		}
	}
}