﻿$(document).ready(function() {
    // Wire-up navigation behaviour
    $('div.Navigation.Dropdown ul:first').ptMenu();
    $('div.Navigation.Accordian ul:first').ptMenu({ vertical: true });

    // Highlight current branch for navigation controls
    $('.Navigation li.current').parentsUntil('.Navigation').addClass('follow');
	
	// Enable form routing
	// Requires dropdown and textbox
	if ( $('label:contains("Route")').length && $('label:contains("Send message to")').length ) {
		// Route textbox exists
		// Route select exists
		
		// Hide textbox
		$('label:contains("Route")').first().parent().css('visibility', 'hidden');
		$('label:contains("Route")').first().parent().next().css('visibility', 'hidden');
				
		// Set default route value
		$('label:contains("Route")').first().parent().next().children('input').first().val($('label:contains("Send message to")').first().parent().next().children('select').first().children('option').first().text());

		// Set on change event
		$('label:contains("Send message to")').first().parent().next().children('select').first().change(function() {
			$('label:contains("Route")').first().parent().next().children('input').first().val($(this).children('option:selected').first().text());
		});
	}
});
