
/* Merged Plone Javascript file
 * This file is dynamically assembled from separate parts.
 * Some of these parts have 3rd party licenses or copyright information attached
 * Such information is valid for that section,
 * not for the entire composite file
 * originating files are separated by - filename.js -
 */

/* - booklet.js - */
// http://www.vivebem.com/portal_javascripts/booklet.js?original=1
(function($){var cookie=klib.bound(klib.logged($.cookie),'booklet');
function getCookie(){var value=cookie();if(value){return $.evalJSON(value)} else{return{}}}
function setCookie(value){cookie($.toJSON(value),{path:'/'})}
function Booklet(element){this.element=element;this.path=this.currentURL();this.readCookie();this.markCurrent();this.styleAll();this.saveCookie();this.bindButtons();this.bindSymtomCheckerButton()}
$.extend(Booklet.prototype,{currentURL: function(){return window.location.href},readCookie: function(){this.data=getCookie();if(this.data===undefined){this.data={}}},saveCookie: function(){setCookie(this.data)},markCurrent: function(){var self=this;var url=this.currentURL();
function addData(){var uid=$(this).classAttr('id');self.data[uid]=1}
$('.section a[href]',this.element).filter(function(){return $(this).attr('href')===url}).eq(0).each(addData).parents('.section').children("a[href]").each(addData)},styleAll: function(){var self=this;$('.main a[href]',this.element).each(function(){self.style(this)})},style: function(element){var uid=$(element).classAttr('id');if(this.data[uid]){klib.log('visited',element);this.mark(element)} else{klib.log('unvisited',element);this.unmark(element)}},mark: function(element){$(element).parents('.sub').addClass('visited');$(element).parents('.section').addClass('visited').addClass('open')},unmark: function(element){$(element).parents('.sub').removeClass('visited')},bindButtons: function(){var self=this;$('a.remove',this.element).click(klib.suppressed(function(){$(this).siblings('a[href]').each(function(){var uid=$(this).classAttr('id');delete self.data[uid];self.saveCookie();self.unmark(this)});return false},true,false))},bindSymtomCheckerButton: function(){if($.cookie('symptom_checker')){json=$.evalJSON($.cookie('symptom_checker'));link="";for(j in json){link+=j+'='+json[j]+'&' }
$('.symptom-checker',this.element).find('a').attr('href','/@@symptom_checker_print?'+link)} else{$('.symptom-checker',this.element).remove()}
$('.symptom-checker .remove',this.element).click(function(e){e.preventDefault();$(this).parents('.sub').remove();$.cookie('symptom_checker',null)})}});$.fn.extend({booklet: function(){this.each(function(){new Booklet(this)})},classAttr: function(name){var i,index,clazz,classes=this.attr('class').split(' ');for(i=0;i<classes.length;i++){clazz=classes[i];index=clazz.indexOf(name+'-');if(index===0){return clazz.substr(index+name.length+1)}}
return undefined}});$(function(){$('#personal-booklet').booklet()})})(jQuery);

/* - common.js - */
// http://www.vivebem.com/portal_javascripts/common.js?original=1
(function($){
function externalLinks(){return $("a[href^=http]").not("[href^=http://"+document.domain+"]").not('.continue')}
function setOtherConditionsEnabled(enabled){var value=enabled?'':'disabled';var list=$('input.other_condition');list.each(function(index){$(this).attr('disabled',value);if(value){$(this).attr('checked',false)}})}
function showErrorOnTellusSurvey(){$('div#tellus_error').show()}
function errorInTellUsForm(){if($('[name=how_well]').val()&&$('[name=relevant]').val()&&$('[name=satisfaction]').val()&&$('[name=most_useful]').val()&&$('[name=improvements]').val())
return false;return true}
$(document).ready(function(){externalLinks().addClass('external-link').each(function(){var href=$(this).attr('href');$(this).attr({'href':'/interstitial?from_page='+location.href+'&to_page='+escape(href)})})});$(document).ready(function(){$('input[name=user_type]').each(function(){$(this).click(function(){setOtherConditionsEnabled(true);return true})});$('input#r4').click(function(){setOtherConditionsEnabled(false);return true})});$(document).ready(function(){$('input#submit_tallus_survey').click(function(){var errors=errorInTellUsForm();if(errors){showErrorOnTellusSurvey();return false} else{return true}})})})(jQuery);

/* - symptom-checker.js - */
// http://www.vivebem.com/portal_javascripts/symptom-checker.js?original=1
(function($){var symptomLog=klib.bound(klib.log,'symptom-checker');var cookie=klib.bound(klib.logged($.cookie),'symptom_checker');
function setCookie(value){cookie($.toJSON(value),{path:'/'})}
function SymptomChecker(element){this.element=element;$(element).find('form')[0].reset();this.hideElements();this.bindActions()}
$.extend(SymptomChecker.prototype,{points:0,result:'',list:{'option1':0,'option2':1,'option3':2,'option4':3,'option5':4,'option6':5},results:[{'class':'normal','from':22,'to':25},{'class':'mild','from':17,'to':21},{'class':'mild-to-moderate','from':12,'to':16},{'class':'moderate','from':8,'to':11},{'class':'severe','from':0,'to':7}],hideElements: function(){$('#ED-results').hide();$('#ED-results h3').hide();$(self.element).find('input[name=result]').attr('value','')},checkSelect: function(){var tmp=0;$(this.element).find('ol:first li select').each(function(){if(this.options[this.selectedIndex].value=='option0'){tmp=1}});if(tmp){return false} else{return true}},checkPoints: function(){var self=this;self.points=0;$(this.element).find('ol:first li select').each(function(e){if(this.options[this.selectedIndex].value!='option0'){self.points+=self.list[this.options[this.selectedIndex].value]}});if(self.points>0){for(var i=0;i<self.results.length;i++){if(self.points>=self.results[i]['from']&&self.points<=self.results[i]['to']){var style_class=self.results[i]['class'];self.result=style_class;$('#ED-results').show();$('#ED-results h3.answer-'+style_class).show();$(self.element).find('input[name=result]').attr('value',style_class);$('#ED-results ul li').find('span').removeClass('active');$('#ED-results ul li.'+style_class).find('span').addClass('active');$('#ED-results p').hide().filter('.'+style_class).show()}}}},savePoints:klib.suppressed(function(){var json={'result':this.result};$('ol:first li select',this.element).each(function(){var value=this.options[this.selectedIndex].value;var name=$(this).attr('name');json[name]=value});setCookie(json)}),bindActions: function(){var self=this;$(this.element).find('div.check input').click(function(e){e.preventDefault();if(self.checkSelect()){self.checkPoints();self.savePoints();if($.cookie('symptom_checker')){json=$.evalJSON($.cookie('symptom_checker'));link="";for(j in json){link+=j+'='+json[j]+'&' }
$('.symptom-checker',this.element).find('a').attr('href','/@@symptom_checker_print?'+link)}}});$(this.element).find('ol:first li select').change(function(){self.hideElements()});$('#ED-results .check-print a').click(function(e){e.preventDefault();$(self.element).find('form')[0].submit()})}});$.fn.extend({symptom_checker: function(){this.each(function(){new SymptomChecker(this)})}});$(function(){$('#symptom-checker').symptom_checker()})})(jQuery);

/* - next_steps_suggestions.js - */
// http://www.vivebem.com/portal_javascripts/next_steps_suggestions.js?original=1
(function($){var cookie=klib.bound(klib.logged($.cookie),'booklet');
function getCookie(){var value=cookie();if(value){return $.evalJSON(value)} else{return{}}}
function Suggestions(element){this.element=element;this.readCookie();this.hideElements();this.checkElements()}
$.extend(Suggestions.prototype,{readCookie: function(){this.data=getCookie();if(this.data===undefined){this.data={}}},hideElements: function(){var self=this;$('a',this.element).each(function(){var uid=$(this).classAttr('id');if(self.data[uid]){if($(this).hasClass('header')){$(this).parent().prepend($(this).html());$(this).remove()} else{$(this).parents('.sub').remove()}}})},checkElements: function(){$('.section',this.element).each(function(){var items=$(this).find('.sub');var links=$(this).find('a[href]');if(!((items.length>0)&&(typeof(items)!="undefined"))&&!((links.length>0)&&(typeof(links)!="undefined"))){$(this).remove()}})}});$.fn.extend({suggestions: function(){this.each(function(){new Suggestions(this)})},classAttr: function(name){var i,index,clazz,classes=this.attr('class').split(' ');for(i=0;i<classes.length;i++){clazz=classes[i];index=clazz.indexOf(name+'-');if(index===0){return clazz.substr(index+name.length+1)}}
return undefined}});$(function(){$('#next-steps-suggestions').suggestions()})})(jQuery);

/* - ui.selectmenu.js - */
 /*
 * jQuery UI selectmenu
 *
 * Copyright (c) 2009 AUTHORS.txt (http://jqueryui.com/about)
 * Dual licensed under the MIT (MIT-LICENSE.txt)
 * and GPL (GPL-LICENSE.txt) licenses.
 *
 * http://docs.jquery.com/UI
 */

(function($) {

$.widget("ui.selectmenu", {
	_init: function() {
		var self = this, o = this.options;
		
		//quick array of button and menu id's
		var num = Math.round(Math.random() * 1000);
		this.ids = [this.element.attr('id') + '_' + 'button' + '_' + num, this.element.attr('id') + '_' + 'menu' + '_' + num];
		
		//define safe mouseup for future toggling
		this._safemouseup = true;
		
		//create menu button wrapper
		this.newelement = $('<a class="'+ this.widgetBaseClass +' ui-widget ui-state-default ui-corner-all" id="'+this.ids[0]+'" role="button" href="#" aria-haspopup="true" aria-owns="'+this.ids[1]+'"></a>')
			.insertAfter(this.element);
		
		//transfer tabindex
		var tabindex = this.element.attr('tabindex');
		if(tabindex){ this.newelement.attr('tabindex', tabindex); }
		
		//save reference to select in data for ease in calling methods
		this.newelement.data('selectelement', this.element);
		
		//menu icon
		this.selectmenuIcon = $('<span class="'+ this.widgetBaseClass +'-icon ui-icon"></span>')
			.prependTo(this.newelement)
			.addClass( (o.style == "popup")? 'ui-icon-triangle-2-n-s' : 'ui-icon-triangle-1-s' );	

			
		//make associated form label trigger focus
		$('label[for='+this.element.attr('id')+']')
			.attr('for', this.ids[0])
			.bind('click', function(){
				self.newelement.focus();
				return false;
			});	

		//click toggle for menu visibility
		this.newelement
			.bind('mousedown', function(event){
				self._toggle(event);
				//make sure a click won't open/close instantly
				if(o.style == "popup"){
					self._safemouseup = false;
					setTimeout(function(){self._safemouseup = true;}, 300);
				}	
				return false;
			})
			.bind('click',function(){
				return false;
			})
			.keydown(function(event){
				var ret = true;
				switch (event.keyCode) {
					case $.ui.keyCode.ENTER:
						ret = true;
						break;
					case $.ui.keyCode.SPACE:
						ret = false;
						self._toggle(event);	
						break;
					case $.ui.keyCode.UP:
					case $.ui.keyCode.LEFT:
						ret = false;
						self._moveSelection(-1);
						break;
					case $.ui.keyCode.DOWN:
					case $.ui.keyCode.RIGHT:
						ret = false;
						self._moveSelection(1);
						break;	
					case $.ui.keyCode.TAB:
						ret = true;
						break;	
					default:
						ret = false;
						self._typeAhead(event.keyCode, 'mouseup');
						break;	
				}
				return ret;
			})
			.bind('mouseover focus', function(){ 
				$(this).addClass(self.widgetBaseClass+'-focus ui-state-hover'); 
			})
			.bind('mouseout blur', function(){  
				$(this).removeClass(self.widgetBaseClass+'-focus ui-state-hover'); 
			});
		
		//document click closes menu
		$(document)
			.mousedown(function(event){
				self.close(event);
			});

		//change event on original selectmenu
		this.element
			.click(function(){ this._refreshValue(); })
			.focus(function(){ this.newelement.focus(); });
		
		//create menu portion, append to body
		var cornerClass = (o.style == "dropdown")? " ui-corner-bottom" : " ui-corner-all"
		this.list = $('<ul class="' + self.widgetBaseClass + '-menu ui-widget ui-widget-content'+cornerClass+'" aria-hidden="true" role="listbox" aria-labelledby="'+this.ids[0]+'" id="'+this.ids[1]+'"></ul>').appendTo('body');				
		
		//serialize selectmenu element options	
		var selectOptionData = [];
		this.element
			.find('option')
			.each(function(){
				selectOptionData.push({
					value: $(this).attr('value'),
					text: self._formatText(jQuery(this).text()),
					selected: $(this).attr('selected'),
					classes: $(this).attr('class'),
					parentOptGroup: $(this).parent('optgroup').attr('label')
				});
			});		
				
		//active state class is only used in popup style
		var activeClass = (self.options.style == "popup") ? " ui-state-active" : "";
		
		//write li's
		for(var i in selectOptionData){
			var thisLi = $('<li role="presentation"><a href="#" tabindex="-1" role="option" aria-selected="false">'+ selectOptionData[i].text +'</a></li>')
				.data('index',i)
				.addClass(selectOptionData[i].classes)
				.data('optionClasses', selectOptionData[i].classes|| '')
				.mouseup(function(event){
						if(self._safemouseup){
							var changed = $(this).data('index') != self._selectedIndex();
							self.value($(this).data('index'));
							self.select(event);
							if(changed){ self.change(event); }
							self.close(event,true);
						}
					return false;
				})
				.click(function(){
					return false;
				})
				.bind('mouseover focus', function(){ 
					self._selectedOptionLi().addClass(activeClass); 
					self._focusedOptionLi().removeClass(self.widgetBaseClass+'-item-focus ui-state-hover'); 
					$(this).removeClass('ui-state-active').addClass(self.widgetBaseClass + '-item-focus ui-state-hover'); 
				})
				.bind('mouseout blur', function(){ 
					if($(this).is( self._selectedOptionLi() )){ $(this).addClass(activeClass); }
					$(this).removeClass(self.widgetBaseClass + '-item-focus ui-state-hover'); 
				});
				
			//optgroup or not...
			if(selectOptionData[i].parentOptGroup){
				var optGroupName = self.widgetBaseClass + '-group-' + selectOptionData[i].parentOptGroup;
				if(this.list.find('li.' + optGroupName).size()){
					this.list.find('li.' + optGroupName + ':last ul').append(thisLi);
				}
				else{
					$('<li role="presentation" class="'+self.widgetBaseClass+'-group '+optGroupName+'"><span class="'+self.widgetBaseClass+'-group-label">'+selectOptionData[i].parentOptGroup+'</span><ul></ul></li>')
						.appendTo(this.list)
						.find('ul')
						.append(thisLi);
				}
			}
			else{
				thisLi.appendTo(this.list);
			}
			
			//this allows for using the scrollbar in an overflowed list
			this.list.bind('mousedown mouseup', function(){return false;});
			
			//append icon if option is specified
			if(o.icons){
				for(var j in o.icons){
					if(thisLi.is(o.icons[j].find)){
						thisLi
							.data('optionClasses', selectOptionData[i].classes + ' ' + self.widgetBaseClass + '-hasIcon')
							.addClass(self.widgetBaseClass + '-hasIcon');
						var iconClass = o.icons[j].icon || "";
						
						thisLi
							.find('a:eq(0)')
							.prepend('<span class="'+self.widgetBaseClass+'-item-icon ui-icon '+iconClass + '"></span>');
					}
				}
			}
		}	
		
		//add corners to top and bottom menu items
		this.list.find('li:last').addClass("ui-corner-bottom");
		if(o.style == 'popup'){ this.list.find('li:first').addClass("ui-corner-top"); }
		
		//transfer classes to selectmenu and list
		if(o.transferClasses){
			var transferClasses = this.element.attr('class') || ''; 
			this.newelement.add(this.list).addClass(transferClasses);
		}
		
		//original selectmenu width
		var selectWidth = this.element.width();
		
		//set menu button width
		this.newelement.width( (o.width) ? o.width : selectWidth);
		
		//set menu width to either menuWidth option value, width option value, or select width 
		if(o.style == 'dropdown'){ this.list.width( (o.menuWidth) ? o.menuWidth : ((o.width) ? o.width : selectWidth)); }
		else { this.list.width( (o.menuWidth) ? o.menuWidth : ((o.width) ? o.width - o.handleWidth : selectWidth - o.handleWidth)); }	
		
		//set max height from option 
		if(o.maxHeight && o.maxHeight < this.list.height()){ this.list.height(o.maxHeight); }	
		
		//save reference to actionable li's (not group label li's)
		this._optionLis = this.list.find('li:not(.'+ self.widgetBaseClass +'-group)');
				
		//transfer menu click to menu button
		this.list
			.keydown(function(event){
				var ret = true;
				switch (event.keyCode) {
					case $.ui.keyCode.UP:
					case $.ui.keyCode.LEFT:
						ret = false;
						self._moveFocus(-1);
						break;
					case $.ui.keyCode.DOWN:
					case $.ui.keyCode.RIGHT:
						ret = false;
						self._moveFocus(1);
						break;	
					case $.ui.keyCode.HOME:
						ret = false;
						self._moveFocus(':first');
						break;	
					case $.ui.keyCode.PAGE_UP:
						ret = false;
						self._scrollPage('up');
						break;	
					case $.ui.keyCode.PAGE_DOWN:
						ret = false;
						self._scrollPage('down');
						break;
					case $.ui.keyCode.END:
						ret = false;
						self._moveFocus(':last');
						break;			
					case $.ui.keyCode.ENTER:
					case $.ui.keyCode.SPACE:
						ret = false;
						self.close(event,true);
						$(event.target).parents('li:eq(0)').trigger('mouseup');
						break;		
					case $.ui.keyCode.TAB:
						ret = true;
						self.close(event,true);
						break;	
					case $.ui.keyCode.ESCAPE:
						ret = false;
						self.close(event,true);
						break;	
					default:
						ret = false;
						self._typeAhead(event.keyCode,'focus');
						break;		
				}
				return ret;
			});
			
		//selectmenu style
		if(o.style == 'dropdown'){
			this.newelement
				.addClass(self.widgetBaseClass+"-dropdown");
			this.list
				.addClass(self.widgetBaseClass+"-menu-dropdown");	
		}
		else {
			this.newelement
				.addClass(self.widgetBaseClass+"-popup");
			this.list
				.addClass(self.widgetBaseClass+"-menu-popup");	
		}
		
		//append status span to button
		this.newelement.prepend('<span class="'+self.widgetBaseClass+'-status">'+ selectOptionData[this._selectedIndex()].text +'</span>');
		
		//hide original selectmenu element
		this.element.hide();
		
		//transfer disabled state
		if(this.element.attr('disabled') == true){ this.disable(); }
		
		//update value
		this.value(this._selectedIndex());
	},
	destroy: function() {
		this.element.removeData(this.widgetName)
			.removeClass(this.widgetBaseClass + '-disabled' + ' ' + this.namespace + '-state-disabled')
			.removeAttr('aria-disabled');
	
		//unbind click on label, reset its for attr
		$('label[for='+this.newelement.attr('id')+']')
			.attr('for',this.element.attr('id'))
			.unbind('click');
		this.newelement.remove();
		this.list.remove();
		this.element.show();	
	},
	_typeAhead: function(code, eventType){
		var self = this;
		//define self._prevChar if needed
		if(!self._prevChar){ self._prevChar = ['',0]; }
		var C = String.fromCharCode(code);
		c = C.toLowerCase();
		var focusFound = false;
		function focusOpt(elem, ind){
			focusFound = true;
			$(elem).trigger(eventType);
			self._prevChar[1] = ind;
		};
		this.list.find('li a').each(function(i){	
			if(!focusFound){
				var thisText = $(this).text();
				if( thisText.indexOf(C) == 0 || thisText.indexOf(c) == 0){
						if(self._prevChar[0] == C){
							if(self._prevChar[1] < i){ focusOpt(this,i); }	
						}
						else{ focusOpt(this,i); }	
				}
			}
		});
		this._prevChar[0] = C;
	},
	_uiHash: function(){
		return {
			value: this.value()
		};
	},
	open: function(event){
		var self = this;
		this._refreshPosition();
		this._closeOthers(event);
		this.newelement
			.addClass('ui-state-active');
		
		this.list
			.appendTo('body')
			.addClass(self.widgetBaseClass + '-open')
			.attr('aria-hidden', false)
			.find('li:not(.'+ self.widgetBaseClass +'-group):eq('+ this._selectedIndex() +') a').focus();	
		if(this.options.style == "dropdown"){ this.newelement.removeClass('ui-corner-all').addClass('ui-corner-top'); }	
		this._refreshPosition();
		this._trigger("open", event, this._uiHash());
	},
	close: function(event, retainFocus){
		if(this.newelement.is('.ui-state-active')){
			this.newelement
				.removeClass('ui-state-active');
			this.list
				.attr('aria-hidden', true)
				.removeClass(this.widgetBaseClass+'-open');
			if(this.options.style == "dropdown"){ this.newelement.removeClass('ui-corner-top').addClass('ui-corner-all'); }
			if(retainFocus){this.newelement.focus();}	
			this._trigger("close", event, this._uiHash());
		}
	},
	change: function(event) {
		this.element.trigger('change');
		this._trigger("change", event, this._uiHash());
	},
	select: function(event) {
		this._trigger("select", event, this._uiHash());
	},
	_closeOthers: function(event){
		$('.'+ this.widgetBaseClass +'.ui-state-active').not(this.newelement).each(function(){
			$(this).data('selectelement').selectmenu('close',event);
		});
		$('.'+ this.widgetBaseClass +'.ui-state-hover').trigger('mouseout');
	},
	_toggle: function(event,retainFocus){
		if(this.list.is('.'+ this.widgetBaseClass +'-open')){ this.close(event,retainFocus); }
		else { this.open(event); }
	},
	_formatText: function(text){
		return this.options.format ? this.options.format(text) : text;
	},
	_selectedIndex: function(){
		return this.element[0].selectedIndex;
	},
	_selectedOptionLi: function(){
		return this._optionLis.eq(this._selectedIndex());
	},
	_focusedOptionLi: function(){
		return this.list.find('.'+ this.widgetBaseClass +'-item-focus');
	},
	_moveSelection: function(amt){
		var currIndex = parseInt(this._selectedOptionLi().data('index'), 10);
		var newIndex = currIndex + amt;
		return this._optionLis.eq(newIndex).trigger('mouseup');
	},
	_moveFocus: function(amt){
		if(!isNaN(amt)){
			var currIndex = parseInt(this._focusedOptionLi().data('index'), 10);
			var newIndex = currIndex + amt;
		}
		else { var newIndex = parseInt(this._optionLis.filter(amt).data('index'), 10); }
		
		if(newIndex < 0){ newIndex = 0; }
		if(newIndex > this._optionLis.size()-1){
			newIndex =  this._optionLis.size()-1;
		}
		var activeID = this.widgetBaseClass + '-item-' + Math.round(Math.random() * 1000);
		
		this._focusedOptionLi().find('a:eq(0)').attr('id','').blur();
		this._optionLis.eq(newIndex).find('a:eq(0)').attr('id',activeID).focus();
		this.list.attr('aria-activedescendant', activeID);
	},
	_scrollPage: function(direction){
		var numPerPage = Math.floor(this.list.outerHeight() / this.list.find('li:first').outerHeight());
		numPerPage = (direction == 'up') ? -numPerPage : numPerPage;
		this._moveFocus(numPerPage);
	},
	_setData: function(key, value) {
		this.options[key] = value;
		if (key == 'disabled') {
			this.element
				.add(this.newelement)
				.add(this.list)
					[value ? 'addClass' : 'removeClass'](
						this.widgetBaseClass + '-disabled' + ' ' +
						this.namespace + '-state-disabled')
					.attr("aria-disabled", value);
		}
	},
	value: function(newValue) {
		if (arguments.length) {
			this.element[0].selectedIndex = newValue;
			this._refreshValue();
			this._refreshPosition();
		}
		return this.element[0].selectedIndex;
	},
	_refreshValue: function() {
		var activeClass = (this.options.style == "popup") ? " ui-state-active" : "";
		var activeID = this.widgetBaseClass + '-item-' + Math.round(Math.random() * 1000);
		//deselect previous
		this.list
			.find('.'+ this.widgetBaseClass +'-item-selected')
			.removeClass(this.widgetBaseClass + "-item-selected" + activeClass)
			.find('a')
			.attr('aria-selected', 'false')
			.attr('id', '');
		//select new
		this._selectedOptionLi()
			.addClass(this.widgetBaseClass + "-item-selected"+activeClass)
			.find('a')
			.attr('aria-selected', 'true')
			.attr('id', activeID);
			
		//toggle any class brought in from option
		var currentOptionClasses = this.newelement.data('optionClasses') ? this.newelement.data('optionClasses') : "";
		var newOptionClasses = this._selectedOptionLi().data('optionClasses') ? this._selectedOptionLi().data('optionClasses') : "";
		this.newelement
			.removeClass(currentOptionClasses)
			.data('optionClasses', newOptionClasses)
			.addClass( newOptionClasses )
			.find('.'+this.widgetBaseClass+'-status')
			.html( 
				this._selectedOptionLi()
					.find('a:eq(0)')
					.html() 
			);
			
		this.list.attr('aria-activedescendant', activeID)
	},
	_refreshPosition: function(){	
		//set left value
		this.list.css('left', this.newelement.offset().left);
		
		//set top value
		var menuTop = this.newelement.offset().top;
		var scrolledAmt = this.list[0].scrollTop;
		this.list.find('li:lt('+this._selectedIndex()+')').each(function(){
			scrolledAmt -= $(this).outerHeight();
		});
		
		if(this.newelement.is('.'+this.widgetBaseClass+'-popup')){
			menuTop+=scrolledAmt; 
			this.list.css('top', menuTop); 
		}	
		else { 
			menuTop += this.newelement.height();
			this.list.css('top', menuTop); 
		}
	}
});

$.extend($.ui.selectmenu, {
	getter: "value",
	version: "@VERSION",
	eventPrefix: "selectmenu",
	defaults: {
		transferClasses: true,
		style: 'popup', 
		width: null, 
		menuWidth: null, 
		handleWidth: 26, 
		maxHeight: null,
		icons: null, 
		format: null
	}
});

})(jQuery);

/* - PEDAC.js - */
DidyouKnow = function () {
    this.init();
}

DidyouKnow.Events = {
    START: 'start',
    NEXT: 'next'
}

DidyouKnow.Constants = {
    AUTO: 8
}

jQuery.extend(DidyouKnow.prototype, {

    init: function () {
        var self = this;
        $(".did-you-know DIV P").hide();
        self.totalQuotes = $(".did-you-know P").length;

        self.currentQuote = 1;
        self.start = 1;
        self.auto = DidyouKnow.Constants.AUTO;
        self.stopped = false;

        this.wireEventHandlers();

        this.changeQuote(this.start);
        this.currentQuote = this.start;

        self.startTimer();

    },

    wireEventHandlers: function () {
        var self = this;

        $(document).bind(DidyouKnow.Events.START, function () {
            self.startTimer();
        });

        $(document).bind(DidyouKnow.Events.NEXT, function (e, data) {  
            if ((self.currentQuote) == self.totalQuotes) {
                self.changeQuote(1);
                self.currentQuote = 0;
            }else if ((self.currentQuote + 1) <= self.totalQuotes) {
                self.changeQuote(self.currentQuote + 1);
                self.currentQuote++;
            }


            self.startTimer();

        });
    },

    changeQuote: function (quotePos) {
        var self = this;

        // show / hide quotes
        $('.did-you-know DIV p:nth-child(' + (parseFloat(self.currentQuote)) + ')').hide();
        $('.did-you-know DIV p:nth-child(' + (parseFloat(quotePos)) + ')').fadeIn("slow");

    },

    startTimer: function () {

        var self = this;
        var next = function () {
            $(document).trigger(DidyouKnow.Events.NEXT, [DidyouKnow.Constants.AUTO]);
        }
        self.t = setTimeout(next, self.auto*1000);

    }

});

(function ($) {
// VERTICALLY ALIGN FUNCTION
$.fn.vAlign = function() {
    return this.each(function(i){
        var ah = $(this).height();
        var ph = $(document).height();
        var mh = (ph - ah) / 2;
        $(this).css('margin-top', mh);
    });
};
})(jQuery);

jQuery(document).ready(function() {

    var dyk = new DidyouKnow();


    
    // set 15 row height booklet builder
    
    var sectionHeight = 6;
     $('.section strong').each(function(index) {
           sectionHeight += $(this).outerHeight();
       });
       
    $('.section li:visible').each(function(index) {
        if (index == 15) { 
            return false;
            }
          sectionHeight += $(this).outerHeight();
      });
      
    $('#booklet-sections').css("height", sectionHeight);
   
    
     // treatment table
    //$('.treatment-table').prepend('<a id="expand-all">Expand All / Collapse All</a>');

    $('.treatment-table h3:not(#expand-all)').click(function() {
        $(this).next().toggle('fast');
        $(this).toggleClass('ui-state-active');
        return false;
        }).next().hide();

        $('.treatment-table #expand-all').toggle(function() {
            $('.treatment-table > DIV').show('fast');
            $('.treatment-table > H3').addClass('ui-state-active');
        
        }, function() {
            $('.treatment-table > H3').removeClass('ui-state-active');
            $('.treatment-table > DIV').hide('fast');
        });

        $('#interstitial').vAlign(); 

        $(window).resize(function() {
          $('#interstitial').vAlign();     
        });
        
        $('#portal-languageselector').selectmenu({
            style:'dropdown',
            icons: [
            {find: '.nl'},
            {find: '.be'},
            {find: '.gb'},
            {find: '.fr'},
            {find: '.pl'}
            ]
        });
        
        references_UIDs = []
        $('#references').hide();
        $('#references li').hide();
        $('sup[title]').each(function(){
        	references_UIDs.push(this.title);
        });
        if(references_UIDs.length > 0){
        	$('#references').show();
	        for(var i=0; i < references_UIDs.length; i++) {
	        	$('#references ul li.' + references_UIDs[i]).show();
	        }
        }
});


