
/*!
 * Ext JS Library 3.2.1
 * Copyright(c) 2006-2010 Ext JS, Inc.
 * licensing@extjs.com
 * http://www.extjs.com/license
 */
// some data used in the examples
Ext.namespace('Ext.navigation');

/* ===============================================================================================
HILFSNAVIGATION
================================================================================================*/
Ext.navigation.hilfsnavi = new Ext.Toolbar({
	//enableOverflow: true,
	id: 'hilfsnavitb',
	style:
	{
		'float': 'right'
	},
	//style: 'background:transparent',
	items: [
		{
			xtype: 'button',
			id: 'abmeldenBtn',
			text: '<b>Abmelden</b>',
			icon: './img/logout_16x16.png',
			tooltip: 'Von der Applikation abmelden',
			tooltipType: 'title',
			iconAlign: 'left',
			handler: function() {
				window.location = "logout.php";
			}

		},{xtype: 'tbseparator', id:'abmeldenSeperator'},
		{
			xtype: 'button',
			id: 'btnChangeTemplate',
			text: '...',
			tooltip: 'Design verändern',
			tooltipType: 'title',
			handler: function ()
			{				
				var newSS = getNextStyleSheet ();
	
				setActiveStyleSheet (newSS);
				Ext.getCmp ('btnChangeTemplate').setText (Ext.variables.styles[getNextStyleSheet()]);
				// Ext.getCmp ('hilfspanel').doLayout();
			}
		},
		'-',
		{
			xtype: 'button',
			id: 'hilfeBtn',
			text: 'Hilfe',
			tooltip: 'Hilfeseite aufrufen',
			tooltipType: 'title',
			handler: function() {
//				Ext.windows.openStdWindow('Hilfe', 'http://2010.urlaubambauernhof.at/uploads/tool_hilfe.pdf', 600, 800);
				window.open ('http://2010.urlaubambauernhof.at/uploads/tool_hilfe.pdf');
			}
		},
		'-',
		{
			xtype: 'button',
			id: 'impressumBtn',
			text: 'Impressum',
			tooltip: 'Impressum aufrufen',
			tooltipType: 'title',
			handler: function() {
				// Ext.windows.openStdWindow('Impressum', MY_ELEARNING_URL + 9);
				window.open ('http://www.urlaubambauernhof.at/footer/impressum.html');
			}
		},
		'-',
		{
			xtype: 'button',
			id: 'kontaktBtn',
			text: 'Kontakt',
			tooltip: 'Kontaktseite aufrufen',
			tooltipType: 'title',
			handler: function() {
			  window.location.href = 'mailto:' + LVMAIL;
			}
		}
	]
});


/* ===============================================================================================
KOPFBEREICH
================================================================================================*/
Ext.navigation.kopfbereich = new Ext.Panel( {
	xtype: 'panel',
	id: 'nord-panel',
	title: 'Bereich oben',
	region: 'north',
	tpl: '',
	autoHeight: true,
	border: false,
	header: false,
	headerAsText: false,
	padding: '0 0 0 0',
	split: false,
	frame: false,

	items: [
		{
			xtype: 'panel',
			title: 'Hilfspanel',
			id: 'hilfspanel',
			layout: 'column',
			header: false,
			headerAsText: false,
			unstyled: false,
			height: 90,
			bodyStyle: 'background-image:url(./img/bg_top.png)',
			items: [
				{
					xtype: 'panel',
					title: 'Logo',
					width: 265,
					html: LOGO_HTML,
					header: false,
					headerAsText: false,
					bodyStyle: 'background:transparent',
					border: false
				},
				{
					xtype: 'panel',
					title: 'Hilfsnavi',
					header: false,
					headerAsText: false,
					border: false,
					bodyStyle: 'background:transparent',
					// width: 248,
					columnWidth: 1,
					tbar: Ext.navigation.hilfsnavi
					// items:
					// [
						// {
							// xtype: 'panel',
							// tbar: Ext.navigation.hilfsnavi
						// }
					// ]
					
				}
			]
		},
		{
			xtype: 'panel',
			title: 'Navigation',
			header: false,
			headerAsText: false,
			autoWidth: false,
			border: false,
			layoutConfig: {
				align: 'stretchmax'
			},
			tbar: Ext.navigation.hauptnavi
		}
	]
});

Ext.navigation.fussbereich = new Ext.Panel ({
	xtype: 'panel',
	id: 'fussbereich',
	title: 'Bereich unten',
	region: 'south',
	tpl: '',
	hideBorders: true,
	bodyBorder: false,
	border: false,
	header: false,
	headerAsText: false,
	padding: '2 2 2 2',
	height: 20,
	items:
	[
	 	{
	 		xtype: 'panel',
	 		hideBorders: true,
	 		bodyBorder: false,
	 		padding: 2,
	 		html: '<span style="float: right;"><span style="font-size: 10px; padding-right: 5px; vertical-align: top">powered by</span><a href="http://seam.at/"><img src="img/seam_logo.png" alt="seam media group" /></a></span>'
	 		
	 	}
	]
});

/* ===============================================================================================
Update Header-Bereich
================================================================================================*/
// This function calls itself every minute
// So we update all the menu items (left menu, right menu, top menu) here!


function renderNavigationNewMessages(anzahl)
{
	var btnNachrichten = Ext.getCmp ('btnNachrichten');
	
	if (typeof btnNachrichten != 'undefined')
	{
		if (typeof anzahl != 'undefined')
		{
			btnNachrichten.setText ('&nbsp;Anfragen <b>(' + anzahl + ' neu)</b>');
		}
		else
		{
			btnNachrichten.setText ('&nbsp;Anfragen');
		}
		
	}
}


function updateNavigation ()
{
	Ext.Ajax.request ({
		url: MY_AJAX_DEFAULTHANDLER,
		method: 'POST',
		params:{
			section: 'updatemenu',
			method: '',
			'loadmsgcount[type]': 'new'
		},
		success: function (response, opts)
		{
			// TODO Dummy function, updates only the "New Messages".
			// TODO Return input as JSON, parse it and apply the updates to the UI
			var resp = Ext.util.JSON.decode (response.responseText);

			if (resp['success'] == false) {
				//showError ("Fehler beim updaten der Navigation: " + resp['errors']['reason']);
			} else {
				// Handling für neue Messages
				if (resp.loadmsgcount != null){
					renderNavigationNewMessages(resp.loadmsgcount.data[0])
				}
			}
		},
		failure: function (response, opts){
			//showError ("Ein Fehler ist aufgetreten beim updaten der Navigation:<br /> " + response.responseText);
		}
	})
	rTimerNavigation = setTimeout (updateNavigation, 60000);
}

// Just update the items if the user is logged in
//We only need to block the inital call of the fct

////////////// Due to Errors this will be called at the bottom of Index.php!!!!!!!!!!!!!!!!!!!!!!
// if (IS_LOGGEDIN){
	// var rTimerNavigation = updateNavigation();
// }


