/*
Name:       District Office Behaviour
Version:    0.0.2 (June 14 2010)
Company:    stadt.werk	
Author:     Finn Rudolph
Support:    rudolph@stadtwerk.org

License:    This code is licensed under a Creative Commons 
            Attribution-Noncommercial 3.0 Unported License 
            (http://creativecommons.org/licenses/by-nc/3.0/).

            You are free:
                + to Share - to copy, distribute and transmit the work
                + to Remix - to adapt the work

            Under the following conditions:
                + Attribution. You must attribute the work in the manner specified by the author or licensor 
                  (but not in any way that suggests that they endorse you or your use of the work). 
                + Noncommercial. You may not use this work for commercial purposes. 

            + For any reuse or distribution, you must make clear to others the license terms of this work.
            + Any of the above conditions can be waived if you get permission from the copyright holder.
            + Nothing in this license impairs or restricts the author's moral rights.
*/


/* Constructor */
function  districtOfficeBehaviour()
{
	/* Closure for this */
	var my = this;

	/* Initiate behaviour */
	this.init = function()
	{
		my.menuButton();
		my.redirectOnSelectChange();
	};
	
	/* Redirect select form on change */
	this.redirectOnSelectChange = function()
	{
		var select = document.getElementById('DistrictOfficeSelect');
		if(select)
		{
			select.onchange = function()
			{
				var index = select.options.selectedIndex;
				var value = select.options[index].value;
				if(value !== '')
				{
					location.href = value;
				}
			};
		}
	};
	
	
	this.menuButton = function()
	{
		/* Unhide button */
		var button = document.getElementById('menu_button');
		if(button)
		{
			/* Hide metabox, head an menu container */
			document.getElementById('metabox').style.display = 'none';
			document.getElementById('head').style.display = 'none';
			document.getElementById('menu').style.display = 'none';
			button.style.display = 'block';
			button.active = false;
			
			/* Set onclick behaviour */
			button.firstChild.onclick = function()
			{
				this.active = (this.active) ? false : true;
				var link = document.getElementById('menu_button').firstChild;
				
				if(this.active)
				{
					button.setAttribute('class', 'active');
					button.setAttribute('className', 'active');

					document.getElementById('standort_menu').style.display = 'none';
					link.firstChild.data = 'Hauptmenü ausblenden';

					document.getElementById('metabox').style.display = 'block';
					document.getElementById('head').style.display = 'block';
					document.getElementById('menu').style.display = 'block';
				}
				else
				{
					button.setAttribute('class', '');
					button.setAttribute('className', '');

					document.getElementById('standort_menu').style.display = 'block';
					link.firstChild.data = 'Hauptmenü einblenden';				

					document.getElementById('metabox').style.display = 'none';
					document.getElementById('head').style.display = 'none';
					document.getElementById('menu').style.display = 'none';
				}
				return false;
			}
		}
	};
	
};

/* Create behaviour instance when the DOM structure has been loaded */
domReady(function()
{
	var districtOffice = new districtOfficeBehaviour();
	districtOffice.init();
	
});
