	document.documentElement.className += " js";
	
	
	(function() {
		var dom = glow.dom,
			$ = glow.dom.get,
			events = glow.events,
			anim = glow.anim;
		
		function getFullHeight(myNodeList) {
			var currentHeight = myNodeList[0].style.height;
			
			var fullHeight = myNodeList.css("visibility", "hidden").
					css("position", "absolute").
					css("height", "auto")[0].offsetHeight;
			
			myNodeList.css("visibility", "").
					css("position", "").
					css("height", currentHeight);
			
			return fullHeight;
		}
		
	
		function slideOpenContent(accordionContent) {
			accordionContent.parent().get(">.accordionContent").each(function() {
				if (this.__isOpen) {
					slideCloseContent($(this));
				}
			})
			
			if (accordionContent[0].__anim) {
				accordionContent[0].__anim.stop();
			}
			
			var openAnim = accordionContent[0].__anim = anim.css(accordionContent, 0.4, {
				height: {to: getFullHeight(accordionContent)}
			}, {tween: glow.tweens.easeBoth()});
			
			accordionContent[0].__completeListener = events.addListener(openAnim, "complete", function() {
				accordionContent.css("height", "auto");
			});
			
			openAnim.start();
			
			//change classes
			accordionContent.addClass('contentOpen');
			accordionContent.prev().removeClass("titleClosed");
			accordionContent.prev().addClass("titleOpen");
			
			accordionContent[0].__isOpen = true;
			
			//setCookie('languages_accordion_display_' + accordionContent[0].id, 'open', 14);
		}
		
		function slideCloseContent(accordionContent) {
			if (accordionContent[0].__anim) {
				accordionContent[0].__completeListener && (events.removeListener(accordionContent[0].__completeListener));
				accordionContent[0].__anim.stop();
			}
			accordionContent[0].__anim = anim.css(accordionContent, 0.4, {
				height: {to: 0}
			}, {tween: glow.tweens.easeBoth()}).start();
			accordionContent[0].__isOpen = false;
			
			//change classes
			accordionContent.removeClass('contentOpen');
			accordionContent.prev().removeClass("titleOpen");
			accordionContent.prev().addClass("titleClosed");
			
			//setCookie('languages_accordion_display_' + accordionContent[0].id, 'closed', 14);
		}
		
		function setCookie(c_name, value, expiredays){
			var exdate=new Date();
			exdate.setDate(exdate.getDate()+expiredays);
			document.cookie=c_name+ "=" +escape(value)+
			((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
		}
		
		function getCookie(c_name){
		if (document.cookie.length>0){
			c_start=document.cookie.indexOf(c_name + "=");
			if (c_start!=-1){ 
				c_start=c_start + c_name.length+1; 
				c_end=document.cookie.indexOf(";",c_start);
				if (c_end==-1) c_end=document.cookie.length;
					return unescape(document.cookie.substring(c_start,c_end));
				} 
			}
			return "";
		}
		
		function accordionTitleClick() {
			var accordionContent = $(this).parent().next();
			var accordionTitle = $(this).parent();
			
			if (!accordionContent[0].__isOpen) {
				slideOpenContent(accordionContent);
			} else {
				slideCloseContent(accordionContent);
			}
			//prevent default
			return false;
		}
		
		function initAccordion(accordionNode) {
			
			//set the javascript state to open for any accordions which have a class of .startOpen on the content div
			$(accordionNode).get(".startOpen").each(function() { 
				this.__isOpen = true; 
				$(this).addClass('contentOpen');
			});
			
			//alter the open/closed state from cookies if necessary
			$(accordionNode).get(".accordionContent").each(function() { 
			
				var displayCookie = getCookie('languages_accordion_display_' + this.getAttribute("id"));
				if(this.__isOpen){//close accordions which should be closed
					if(displayCookie == 'closed'){
						slideCloseContent($(this));
					}
				} else {//open accordions which should be open
				
					if(displayCookie == 'open'){
						slideOpenContent($(this));
					}
				}
			});
		
			$(accordionNode).get(" > .accordionTitle").each(function() {
				this.innerHTML = '<a href="#">' + this.innerHTML + '</a>';
				
			}).each(function() {
				events.addListener($(this).get("a"), "click", accordionTitleClick);
			});
		}
		
		glow.ready(function() {
			$(".accordion").each(function() {
				initAccordion(this);
			});
		});
		
		
	}());