/**
 * @version    $Id$
 * @package    IT_Theme_Framework
 * @author     InnoThemes Team <support@innothemes.com>
 * @copyright  Copyright (C) 2012 InnoThemes.com. All Rights Reserved.
 * @license    GNU/GPL v2 or later http://www.gnu.org/licenses/gpl-2.0.html
 *
 * Websites: http://www.innothemes.com
 */

( function() {
	var it_menu_toggled = document.getElementById( 'it-mainmenu' ), it_button, menu;
	if ( ! it_menu_toggled )
		return;
	it_button = it_menu_toggled.getElementsByTagName( 'h3' )[0];
	menu   = it_menu_toggled.getElementsByTagName( 'ul' )[0];
	if ( ! it_button )
		return;

	// Hide button if menu is missing or empty.
	if ( ! menu || ! menu.childNodes.length ) {
		it_button.style.display = 'none';
		return;
	}

	it_button.onclick = function() {
		if ( -1 == menu.className.indexOf( 'nav-menu' ) )
			menu.className = 'nav-menu';

		if ( -1 != it_button.className.indexOf( 'toggled-on' ) ) {
			it_button.className = it_button.className.replace( 'toggled-on', '' );
			menu.className = menu.className.replace( 'toggled-on', '' );
		} else {
			it_button.className += 'toggled-on';
			menu.className += ' toggled-on';
		}
	};
} )();