// JavaScript Document
addLoadListener(init);
function init()
{			
	//prepareMenu();
	fixFooter();
	var iBase = TextResizeDetector.addEventListener(onFontResize,null);
}
function fixFooter()
{
	//alert("FixFooter");
	var tollest = getElementsByAttribute("class", "tollest");
	var toll = 0;
	for(var i = 0;  i < tollest.length; i++)
	{
		var footerTopPositionTemp = getPosition(tollest[i])[1];
		footerTopPositionTemp = footerTopPositionTemp + tollest[i].offsetHeight + 20;
		if(footerTopPositionTemp > toll)
			toll = footerTopPositionTemp; 
	}
	
	var footer = document.getElementById("footer");
//	var footerTopPosition = getPosition(tollest[0])[1];
//	footerTopPosition = footerTopPosition + tollest[0].offsetHeight + 20;

	//alert(footer.style.top + " Prije");
	footer.style.top = toll + "px";
	//alert(footer.style.top + " Poslije");
}

function onFontResize(e,args) 
{
	fixFooter();
}
//id of element to check for and insert control
TextResizeDetector.TARGET_ELEMENT_ID = 'container';
//function to call once TextResizeDetector has init'd
TextResizeDetector.USER_INIT_FUNC = init;

// DropDownMenu by Miha Hribar
// http://hribar.info

function prepareMenu() {
    // first lets make sure the browser understands the DOM methods we will be using
  	if (!document.getElementsByTagName) return false;
  	if (!document.getElementById) return false;
  	
  	// lets make sure the element exists
  	if (!document.getElementById("main_nav")) return false;
  	var menu = document.getElementById("main_nav");
  	
  	// for each of the li on the root level check if the element has any children
  	// if so append a function that makes the element appear when hovered over
  	var root_li = menu.getElementsByTagName("li");
  	for (var i = 0; i < root_li.length; i++) 
	{
  	    var li = root_li[i];
  	    // search for children
  	    var child_ul = li.getElementsByTagName("ul");
  	    if (child_ul.length >= 1) {
			if(li.parentNode.id != "main_nav")
				li.className = "hasSubMenu";

		// we have children - append hover function to the parent
  	        li.onmouseover = function () 
			{
  	            if (!this.getElementsByTagName("ul"))
					return false;

				var ul = this.getElementsByTagName("ul");
  	            ul[0].style.display = "block";
  	            return true;
  	        }
  	        li.onmouseout = function () 
			{
  	            if (!this.getElementsByTagName("ul")) 
					return false;
					
  	            var ul = this.getElementsByTagName("ul");
  	            ul[0].style.display = "none";
  	            return true;
  	        }
  	    }
  	}
  	
  	return true;
}

function resizeMenu(object, resizeBy, destHeight)
{
	if(object.offsetHeight > destHeight)
	{
		object.style.height -= resizeBy;
	}
	else if (object.offsetHeight < destHeight)
	{
		object.style.height += resizeBy;
	}
	else if(object.offsetHeight == 0)
	{
		
	}
	setTimeout(function(){transitionSquash(target)}, 50);
}

