var triveSpecifics = Class.create();

triveSpecifics.prototype = {
	XSLTXML2ID: function(xslt,xml,id) {
		new Ajax.Request(xml, {
			method: 'get',
			onLoading: function() {
				$(id).innerHTML = "<h1>Laddar</h1>";
			},
			onSuccess: function(transport) {
				setTimeout(function() {
					$(id).innerHTML = triveCommon.prototype.setXSL(transport.responseXML, xslt);
				}, 500);
			}
		});
	},
	
	XML2DropDownID: function(xml,id,loadingHTML) {
		new Ajax.Request(xml, {
			method: 'get',
			onLoading: function() {
				$(id).options[0] = new Option(loadingHTML, '-1');
				$(id).selectedIndex = 0;
			},
			onSuccess: function(transport) {
				setTimeout(function() {
					
					if (window.ActiveXObject)
					{
						xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
						xmlDoc.async=false;
						xmlDoc.loadXML(transport.responseText);
		
					}
					// code for Mozilla, Firefox, Opera, etc.
					else if (document.implementation && document.implementation.createDocument)
					{
						var parser=new DOMParser();
						var xmlDoc=parser.parseFromString(transport.responseText,"text/xml");
					}
					else
					{
						
					}
					
					arrOptions = new Array(xmlDoc.getElementsByTagName("item").length);
					dropDownList = $(id);
					dropDownList.options.length = 0;
					
					if(xmlDoc.getElementsByTagName("item").length <= 1){
						dropDownList.options[0] = new Option("Not available", "-1");
						dropDownList.disabled = true;
					}
					else{
					
						for(i = 0; i < xmlDoc.getElementsByTagName("item").length; i++){
							dropDownList.options[i] = new Option(xmlDoc.getElementsByTagName("item")[i].getElementsByTagName("name")[0].childNodes[0].nodeValue, 
								xmlDoc.getElementsByTagName("item")[i].getElementsByTagName("id")[0].childNodes[0].nodeValue);	
						}
					}
					
				}, 500);
			}
		});
	},
	
	PopulateMiniPresentation: function(el,id)
	{
		if(!$("divMiniPresentation" + id))
		{
			element = document.createElement('div');
			element.id = "divMiniPresentation" + id;
			element.className = 'divMiniPresentation';
			el.setAttribute('rel', "divMiniPresentation" + id);
			el.parentNode.appendChild(element);
			triveDropoutInitializeManual(el);
			triveSpecifics.prototype.XSLTXML2ID('xslt/miniPresentation.xslt','xml/miniPresentation.xml?q=' + id,'divMiniPresentation' + id)
		}
	},
	
	ToggleAndChangeExecutor: function(element,executor,text)
	{
		element = $(element);
		if(Element.visible(element))
		{
			executor.innerHTML = text[0];
			Element.hide(element);
		}
		else
		{
			executor.innerHTML = text[1];
			Element.show(element);
		}
	}
}

var userMenu = Class.create();

userMenu.prototype = {

	// Jan Jarfalk at Trive AB
	// jan.jarfalk@trive.se
	// http://www.trive.se

	// Requires	Prototype
	//			Script.aculo.us

	initialize: function(id) {
		actor = this;
		this.id = id;
		this.hideSubMenus();
		//Event.observe($(this.id), 'click', this.toggle.bindAsEventListener(this), false);
		
		
		$$('#' + this.id + ' li').each(function(item){
			item.onclick = function(){
				if(this.parentNode.parentNode.tagName == 'LI')
				{
					userMenu.prototype.toggle(this);
				}
			}
		});
		
	},
	
	hideSubMenus: function()
	{
		$$('#' + this.id + ' li ul li ul').each(function(item){
			item.hide();
		});
	},

	toggle: function(item)
	{ 
		
		this.el = item.getElementsByTagName('ul')[0];
		this.el.visible = Element.visible(item.getElementsByTagName('ul')[0]);

		if(this.el.visible){
			Effect.SlideUp(this.el,{ duration:0.1 });
			this.el.className = "hasSubMenuMazimize";
			return false;
		}
		else if(!this.el.visible){
			Effect.SlideDown(this.el,{ duration:0.1 });
			this.el.className = "hasSubMenuMinimize";
			return false;
		}
		
		
	}

}