jQuery.noConflict();
	
jQuery("ul.subnav").parent().append("<span id='open-choices'></span>"); //Only shows drop down trigger when js is enabled (Adds empty span tag after ul.subnav*)

/**
 * domCloak
 *
 * Date: 18 August 2009.
 * Author: D Braksator.
 */

// Override IE setTimeout.
/*@cc_on
(function(f){
 window.setTimeout =f(window.setTimeout);
 window.setInterval =f(window.setInterval);
})(function(f){return function(c,t){var a=[].slice.call(arguments,2);return f(function(){c.apply(this,a)},t)}});
@*/

// Event caching
var domCloakEventCache = function(){
	var listEvents = [];
	return {
		listEvents : listEvents,
		add : function(node, sEventName, fHandler){
			listEvents.push(arguments);
		},
		flush : function(){
			var i, item;
			for(i = listEvents.length - 1; i >= 0; i = i - 1){
				item = listEvents[i];
				if(item[0].removeEventListener){
					item[0].removeEventListener(item[1], item[2], item[3]);
				}
				if(item[1].substring(0, 2) != "on"){
					item[1] = "on" + item[1];
				}
				if(item[0].detachEvent){
					item[0].detachEvent(item[1], item[2]);
				}
				item[0][item[1]] = null;
			}
		}
	};
}();

// Mouse enter function
function domCloakMouseEnter(fn) {
  return function(event) {
    var relTarget = event.relatedTarget;
    if (this === relTarget || domCloakChildOf(this, relTarget)) { return; }
    fn.call(this, event);
  }
};

// Is 'parent' a child of 'child'?
function domCloakChildOf(parent, child) {
  if (parent === child) { return false; }
  while (child && child !== parent) { child = child.parentNode; }
  return child === parent;
}

// Add DOM event
function domCloakAddEvent(obj, type, fn) {
	if (obj.addEventListener) {
    if (type == 'mouseenter') {
      type = 'mouseover';
      fn = domCloakMouseEnter(fn);
    }
    else if (type == 'mouseleave') {
      type = 'mouseout'
      fn = domCloakMouseEnter(fn);
    }
		obj.addEventListener(type, fn, false);
		domCloakEventCache.add(obj, type, fn);
	}
	else if (obj.attachEvent) {
		obj["e" + type + fn] = fn;
		obj[type + fn] = function() { 
      obj["e" + type + fn](window.event); 
    }
		obj.attachEvent("on" + type, obj[type + fn]);
		domCloakEventCache.add(obj, type, fn);
	}
	else {
		obj["on" + type] = obj["e" + type + fn];
	}
}

domCloakAddEvent(window, "unload", domCloakEventCache.flush);

domCloakAddEvent(document.getElementById('open-choices'),'click',openLang);
domCloakAddEvent(document.getElementById('topnav'),'mouseleave',closeLang);

function openLang(){
	jQuery(".topnav").find("ul.subnav").show();

    x = 0; //horizontal coord

    y = getDocHeight(); //vertical coord

    setTimeout('window.scroll(x,y)',1);
}

function getDocHeight() {
    var D = document;
    return Math.max(
        Math.max(D.body.scrollHeight, D.documentElement.scrollHeight),
        Math.max(D.body.offsetHeight, D.documentElement.offsetHeight),
        Math.max(D.body.clientHeight, D.documentElement.clientHeight)
    );
}

function closeLang(){
	jQuery(".topnav").find("ul.subnav").hide(); //When the mouse hovers out of the subnav, move it back up
}
