YAHOO.si.Controller = 
{
	historyManager: {},
	/**
	 * The data is available, the feedback system is ready and the state is set
	 * so we can initialise the controller.
	 */
	init:function()
	{
		this.initProgress();
		this.setupHistory();
		//alert("controller knows language is " + this.historyManager.language);
		this.initBreadcrumbs();
		this.initRightLinks();
		this.initTopNavBar();
		this.initLeftMenu();
		this.initLogo();
	},
	initProgress:function()
	{
		YAHOO.si.Progress.init();	
	},
	setupHistory:function()
	{
		try
		{
			this.historyManager = YAHOO.si.HistoryManager;				
			this.historyManager.setup("jp");
			//YAHOO.si.HistoryManager.setup("jp");
		}
		catch(e)
		{
			e.contextMessage = "The file 'history.js' may be missing or the SIHistory control " +
					"may be missing.";
			YAHOO.si.handleErrors(e);
		}
	},
	initBreadcrumbs:function()
	{
		try
		{
			this.breadcrumbs = new YAHOO.si.Breadcrumbs();
			this.breadcrumbs.init();	
			this.breadcrumbs.render();
		}
		catch(e)
		{
			e.contextMessage = " The file 'renderbreadcrumbs.js' may be missing.";
			throw e;
		}		
	},
	initRightLinks:function()
	{
		try
		{
			this.rightlinks = new YAHOO.si.TopRightLinks();
			this.rightlinks.init();			
			
			//You don't need to render the top right links. They're already in the page.
		}
		catch(e)
		{
			e.contextMessage = " The file 'renderrightlinks.js' may be missing." +
					" Or the TopRightLinks control may be missing.";
			throw e;
		}		
	},
	initTopNavBar:function()
	{
		try
		{
			this.topNavBar = new YAHOO.si.TopNavBar();
			this.topNavBar.init();		
		}
		catch(e)
		{
			e.contextMessage = " The file 'rendertopnavbar.js' may be missing." +
					" Or the TopNavBar control may be missing.";
			throw e;
		}		
	},
	initLeftMenu:function()
	{
		try
		{
			this.leftMenu = new YAHOO.si.LeftMenu();
			this.leftMenu.init();
			//this.leftEnMenu = new YAHOO.si.LeftMenu();		
			//this.leftJpMenu = new YAHOO.si.LeftMenu();		
			//this.leftEnMenu.init("en");
			//this.leftJpMenu.init("jp");
			//this.setLeftMenuLanguage();
		}
		catch(e)
		{
			e.contextMessage = " The file 'renderleftmenu.js' may be missing." +
					" Or the LeftMenu control may be missing.";
			throw e;
		}		
	},
	/*
	setLeftMenuLanguage:function()
	{
		if(YAHOO.si.HistoryManager.language==="en")
		{
			this.leftEnMenu.setVisible(true);
			this.leftJpMenu.setVisible(false);
		}
		else
		{
			this.leftEnMenu.setVisible(false);
			this.leftJpMenu.setVisible(true);
		}
	},
	*/
	updateLeftMenu:function()
	{
		this.leftMenu.init();
	},
	initLogo:function()
	{
		try
		{
			YAHOO.si.Logo();
		}
		catch(e)
		{
			e.contextMessage = " The file \'logo.js\' may be missing."; 
			throw e;
		}		
	},
	changeLanguage:function()
	{
		if(this.historyManager.language=="en")
		{
			this.historyManager.language = "jp";
		}
		else
		{
			this.historyManager.language = "en";
		}
	},
	/**
	 * This determines the new area and then calls changeLanguage
	 * 
	 */
	translateArea:function()
	{
		try
		{
			var language = this.historyManager.language;
			var areaid = this.historyManager.areaid;
			var json = topnavbardata[language][areaid];
			this.changeLanguage();
			var transid = json.transid;
			return transid;		
		}
		catch(e)
		{
			YAHOO.si.handleErrors(e);
		}
	},
	translatePage:function()
	{
		try
		{
			var pageid = this.historyManager.pageid;
			var translation =  translations[pageid + "-4"];
			var typetransid = translation["type-transid"];
			var transid = typetransid.substring(0,typetransid.indexOf("-"));
			return transid;
		}
		catch(e)
		{
			YAHOO.si.handleErrors(e);
		}
	},
	setLeftMenuSelected:function(url)
	{
		/*
		switch(YAHOO.si.HistoryManager.language)
		{
			case "en":
				this.leftEnMenu.setSelected(url);
				break;
			case "jp":
				this.leftJpMenu.setSelected(url);
				break;
		}
		* */
	},
	toString:function()
	{
		return "YAHOO.si.Controller";
	},
	setTopNavBarSelected:function(url)
	{
		this.topNavBar.setSelected( url);
	}
};
YAHOO.si.ErrorHandler.onFeedbackReady.subscribe(function()
{
	try
	{
		this.init();
	}
	catch(e)
	{
		YAHOO.si.handleErrors(e);
	}
},YAHOO.si.Controller,true);
