function getPannelIndex(){
	if(window.location.search){
		var pairs = location.search.split( "&" );
		for (var i=0; i<pairs.length; i++){
			var keyval = pairs[i].split( "=" );
			if(keyval[0] == 'pannel' || keyval[0] == '?pannel'){
				return keyval[1];
			}
		}
	}
	return 0;
}

$(document).ready(function() {
	//ie < 7 does not support dynamic css, so for the menu we need js
	if($.browser.msie && $.browser.version < 7.0){
		//Calculate the width of each "ul" so "li" does not expand to the end of the page, min width="10em"
		$("#menu li ul").each(function(idx){
			var h = 10;
			$(this).children("li").each(function(index) {
				var temp = $(this).text().length;
				h = h < Math.round(temp * 0.7) ? Math.round(temp * 0.7) : h;
			});
			$(this).width(h + "em");
			h = 10;
		});
		
		$("#menu li").hover(
			//Mouseover, fadeIn the hidden hover class
			function() {$(this).children('ul').fadeIn('1000');
			},

			//Mouseout, fadeOut the hover class
			function() {$(this).children('ul').hide();
		});
	}

	//This is the accordion code
	var pannelIndex = getPannelIndex();
	$(".accordionExample").each(function(idx) {
			$(this).find(".panelheader").each(function(index) {
			var _this = $(this);
			var _next = _this.next();
			if(pannelIndex == index){
				_this.addClass("mdSelected");
			}else{
				_next.slideUp("slow");
			}
			
			_this.hover(
				//Mouseover
				function() {
					$(this).addClass("mdHover");
				},
				//Mouseout
				function() {
					$(this).removeClass("mdHover");
			});
			
			_this.click(function(){
				if(!_this.hasClass("mdSelected")){
					_this.siblings(".mdSelected").each(function(index) {
						$(this).next().slideUp("slow");
						$(this).removeClass("mdSelected");
					});
					_this.addClass("mdSelected");
					_next.slideDown("slow");
				}
			});
			
		});
	});
});