$(function()
{
	resizeContentBox();

	$('.scroll-pane').each(
		function()
		{
			$(this).jScrollPane(
				{
					verticalDragMinHeight: 40,
					verticalDragMaxHeight: 60
				}
			);
			var api = $(this).data('jsp');
			var throttleTimeout;
			$(window).bind(
				'resize',
				function()
				{
					resizeContentBox();

					if ($.browser.msie) {
						// IE fires multiple resize events while you are dragging the browser window which
						// causes it to crash if you try to update the scrollpane on every one. So we need
						// to throttle it to fire a maximum of once every 50 milliseconds...
						if (!throttleTimeout) {
							throttleTimeout = setTimeout(
								function()
								{
									api.reinitialise();
									throttleTimeout = null;
								},
								50
							);
						}
					} else {
						api.reinitialise();
					}
				}
			);
		}
	);
	var blurClass = 'clickText';
	
	$('.'+blurClass).each(function () {
		// get jQuery version of 'this'
		var $input = jQuery(this),
			
		// capture the rest of the variable to allow for reuse
		title = $input.attr('title'),
		$form = jQuery(this.form),
		$win = jQuery(window);
			
		function remove() {
			if ($input.val() === title && $input.hasClass(blurClass)) {
				$input.val('').removeClass(blurClass);
			}
		}
			
		// only apply logic if the element has the attribute
		if (title) { 
			// on blur, set value to title attr if text is blank
			$input.blur(function () {
				if (this.value === '') {
					$input.val(title).addClass(blurClass);
				}
			}).focus(remove).blur(); // now change all inputs to title
			
			// clear the pre-defined text when form is submitted
			$form.submit(remove);
			$win.unload(remove); // handles Firefox's autocomplete
		}
	});

});

function resizeContentBox()
{
	var newH = $(window).height()-193;
	//console.log('window height: '+newH);
	if(newH < 580){		
		newH = 580;//(788-193);
		//console.log('reset to: '+newH);
	}
	$('.scroll-pane').css('height',newH + 'px');
	//console.log('new: '+$('.scroll-pane').css('height'));
}


function toggleNavTree(newOpenId)
{
	var newOpenBox = $('.child_' + newOpenId);
	var oldOpenBox = $('.activeNavTreeChild');
	if(newOpenBox.length==0){
		return; //no action if no new box will open
	}
	if(oldOpenBox.hasClass('child_'+newOpenId)){
		return; //no action if needs to open self box
	}
	newOpenBox.slideDown(200, function(){
		$(this).addClass('activeNavTreeChild');	
	});
	oldOpenBox.slideUp(200, function(){
		$(this).removeClass('activeNavTreeChild');
	});
	
}

function setNewActive(obj)
{
	if(obj.length==0){
		return;
	}
	$('.active').removeClass('active');
	obj.addClass('active');
}


