
var openmenu;


function getElementsByClassName(className, searchIn)
{
	
	var container = $(searchIn); 
	var elems = container.getElementsByTagName('*');
	
	var active_link;
	
	for(var i = 0; i < elems.length; i++)
	{
		var elem = elems[i];
		var cls = elem.className;
	
		if (cls == "active")
		{
			active_link = elem	
			
			addEvent(active_link, 'click', function(){ 

					if (this.className == "active show")
					{
						this.className = "active"
						this.parentNode.style.zIndex = 0
						openmenu = null;
					}
					else
					{
						openmenu = this
						this.className = "active show";
						this.parentNode.style.zIndex = 1000
					}
	
					
			});
			
		
		}  
		
		if(cls == className)
		{
			var list = elem.getElementsByTagName('li')

			for (var j = 0; j < list.length; j++)
			{
	
				
				if (list[j].className != "active" && list[j].className != "button")
				{
					
					addEvent(list[j].firstChild, 'click',function () {
					
						
						var href = this.getAttribute('href')
						this.setAttribute('href', "javascript:void(0)")
						
						this.parentNode.parentNode.parentNode.setAttribute('value', href) ;
						this.parentNode.parentNode.parentNode.firstChild.nodeValue = this.firstChild.nodeValue.length > 30 ? this.firstChild.nodeValue.substring(0, 30) + "..." : this.firstChild.nodeValue;
	
						this.parentNode.parentNode.parentNode.className = "active show"
	
						var link = lastChildOfList(this.parentNode.parentNode.parentNode.parentNode).getElementsByTagName('a')



						if (link.length > 0)
							link[0].setAttribute("href", href)
				
					var elem = this;
			    
					if (document.all)
						setTimeout(function(){setHref(elem,href)}, 500);
					else
						setTimeout(setHref, 500, this, href);
					
					});
				}
			}
	
		}
	}
	
	
}

function setHref(elem, href)
{
	elem.setAttribute('href', href)	
}


// gets the last child of an element, but not "/n"
 function lastChildOfList(elem)
 {
  e = elem;
  if ((e == null) || (e.lastChild == null))
   return null
  lc = e.lastChild;
  while (lc.tagName == null)
   lc = lc.previousSibling
  return lc
 }


// opens the function to make onclicks on the dropdown li's
addEvent(window,'load', function() {
																
	var elems = getElementsByClassName("dropdown","dropdown")
			
});

// for the inclick events
function addEvent( obj, type, fn ) {
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] );
  } else
    obj.addEventListener( type, fn, false );
}


function removeEvent( obj, type, fn ) {
  if ( obj.detachEvent ) {
    obj.detachEvent( 'on'+type, obj[type+fn] );
    obj[type+fn] = null;
  } else
    obj.removeEventListener( type, fn, false );
}

addEvent(document,'mouseup', function() {

	if(openmenu)
	{
		openmenu.className = "active";
		openmenu.parentNode.style.zIndex = 0
	}
		
});