// JavaScript Document
addLoadListener(init);
function init()
{				
	prepareMenu();
	fixFooter();
	fixPng();
	var iBase = TextResizeDetector.addEventListener(onFontResize,null);
}
function fixFooter()
{
	var tollest = getElementsByAttribute("class", "tollest");
	var footer = document.getElementById("footer");
	var footerTopPosition = getPosition(tollest[0])[1];
	footerTopPosition = footerTopPosition + tollest[0].offsetHeight;
	if(footerTopPosition > 500)
		footer.style.top = footerTopPosition + "px";
	else 
		footer.style.top = "500px";
	footer.style.display = "block";
}

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 fixPng() {
	var pngs = new Array();
	pngs = getAllPNGimages();
	for (var i = 0; i < pngs.length; i++)
	{
		var img = pngs[i];
		var src = img.src;
		//img.style.visibility = "hidden";
		var div = document.createElement("div");
		div.style.width = 50;
		div.className = "div_png";
		div.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "', sizingMethod='trim')"; 
		img.replaceNode(div);
	}
}
if (navigator.platform == "Win32" && navigator.appName == "Microsoft Internet Explorer" && window.attachEvent) {
   window.attachEvent("onload", alphaBackgrounds);
}

function alphaBackgrounds(){
   var rslt = navigator.appVersion.match(/MSIE (\d+\.\d+)/, '');
   var itsAllGood = (rslt != null && Number(rslt[1]) >= 5.5);
   for (i=0; i<document.all.length; i++){
      var bg = document.all[i].currentStyle.backgroundImage;
      if (itsAllGood && bg){
         if (bg.match(/\offer.png/i) != null){
			 
            var mypng = bg.substring(5,bg.length-2);
            document.all[i].style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+mypng+"', sizingMethod='scale')";
            document.all[i].style.backgroundImage = "url('/mambots/system/bot_ultimatepngfix/x.gif')";
         }
      }
   }
} 