/// <reference path="jquery-1.3.2.min-vsdoc.js" />

jQuery.fn.extend({
	isIE6: function() {
		///<summary>Tests if the browser is IE6</summary>
		///<returns type="bool" />
		if (document.all && document.getElementById) {
			if (document.compatMode && !window.XMLHttpRequest) {
				return true;
			}
		}
		return false;
	},
	CSSMenu: function() {
		///<summary>Adds classes to a CSS menu for browsers that do not suppoer :hover on any block element</summary>
		///<returns type="jQuery" />
		return this.each(function() {
			jQuery(this).find('li').mouseover(function() { jQuery(this).addClass('hover'); }).mouseout(function() { jQuery(this).removeClass('hover'); });
		});
	},
	expandSibling: function() {
		///<summary>Expands and sets display to 'block' of the sibling of an element</summary>
		///<returns type="jQuery" />

		return this.each(function() {
			jQuery(this).addClass('expanded').parent().addClass('expanded');
			jQuery(this).siblings('*:first').css({
				'visibility': 'hidden',
				'display': 'block',
				'position': 'absolute'
			});
			var targetHeight = jQuery(this).siblings('*:first').height();
			jQuery(this).siblings('*:first').height(0);
			jQuery(this).siblings('*:first').css({
				'visibility': 'visible',
				'position': 'relative'
			});
			jQuery(this).siblings('*:first').animate({
				height: targetHeight + 'px'
			},
			'normal',
			'swing',
			function() {
				jQuery(this).css({ 'height': 'auto' });
			}
		);
		});
	}, 
	collapseSibling: function(callback) {
		///<summary>Collapses and sets display to 'none' of the sibling of an element</summary>
		///<param name="callback">Callback function on animation complete.</param>
		///<returns type="jQuery" />

		return this.each(function() {
			jQuery(this).removeClass('expanded').parent().removeClass('expanded');
			jQuery(this).siblings('*:first').animate({
				height: 0 + 'px'
			},
				'normal',
				'swing',
				function() {
					$(this).css({
						'height': 'auto',
						'display': 'none'
					});
					if (callback) callback(this);
				}
			);
		});
	}
});

/************************************************************************************************************
* Accordian Generators
***********************************************************************************************************/

AccordianNavigation = function(listElements, stickySibling, preExpandedNodeInt) {
	///<summary>Applys accordian functionality to navigation</summary>
	///<param name="listElements">jQuery Selector of the the unordered list li's</param>
	///<param name="stickySibling">The node inside the the li to apply the click()</param>
	///<param name="preExpandedNodeInt">Pre-expand a specified node</param>
	///<returns type="void" />

	if (preExpandedNodeInt == undefined || preExpandedNodeInt == null || preExpandedNodeInt == -1) preExpandedNodeInt = -1;
	if (stickySibling == undefined || stickySibling == null || stickySibling == "") stickySibling = "a:first";
	listElements = $(listElements).find(stickySibling);
	if (preExpandedNodeInt > -1) {
		$(listElements).eq(preExpandedNodeInt).expandSibling();
	}
	$(listElements).click(function() {
		$parent = $(this).parent();
		if($parent.children('ul').size() > 0){
			if ($(this).hasClass('expanded')) {
				$(this).collapseSibling(function() {
					$parent.removeClass('AspNet-Menu-ChildSelected');
				});
				return false;
			}
			else if (!$(this).hasClass('expanded')) {
				$parent.addClass('AspNet-Menu-ChildSelected');
				$(this).expandSibling();
				return false;
			}
		}
		else return true;
	});
}

$(document).ready(function() {
	$('#sitenav').CSSMenu();
	$("#nav-solutions > ul > li > a").click(function() {
		if ($(this).hasClass("collapsed")) {
			$(this).parent("li").children("ul").slideDown();
			$(this).removeClass("collapsed").addClass("expanded");
		} else {
			$(this).parent("li").children("ul").slideUp();
			$(this).removeClass("expanded").addClass("collapsed");
		}
		return false;
	});
	$('#secnav').CSSMenu();
	AccordianNavigation('#solutions-wrapper .section ul > li');
});