var xmlHttp;

// Mozilla, Opera, Safari sowie Internet Explorer (ab v7)
if (typeof XMLHttpRequest != 'undefined')
{
    xmlHttp = new XMLHttpRequest();
	if(xmlHttp.overrideMimeType)
		xmlHttp.overrideMimeType('text/xml');
}

if (!xmlHttp)
{
    // Internet Explorer 6 und aelter
    try {
        xmlHttp  = new ActiveXObject("Msxml2.XMLHTTP");
    } catch(e) {
        try {
            xmlHttp  = new ActiveXObject("Microsoft.XMLHTTP");
        } catch(e) {
            xmlHttp  = null;
        }
    }
}

function closePopup(elem)
{
	elem.parentNode.parentNode.removeChild(elem.parentNode);
}

function loadPopup(url)
{
	xmlHttp.open("GET","/popups/" + url + ".htm", true);
	xmlHttp.onreadystatechange = function()
		{
			if (xmlHttp.readyState == 4 && xmlHttp.status == 200)
			{
				var div = document.createElement('div');
				div.className = "popup";
				div.innerHTML = "<img class='cb' src='/images-global/zoom/closebox.png' onClick='closePopup(this);'/>" + xmlHttp.responseText;
				//alert(div.outerHTML);
				document.body.appendChild(div);
				window.scrollTo(0, 0);
			}
		}
	xmlHttp.send(null);
}

function loadFooter()
{
	if((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i)))
		xmlHttp.open("GET","/popups/ifooter.htm", true);
	else
		xmlHttp.open("GET","/popups/footer.htm", true);
	xmlHttp.onreadystatechange = function()
	{
		if (xmlHttp.readyState == 4 && xmlHttp.status == 200)
		{
			var div = document.createElement('div');
			div.innerHTML = xmlHttp.responseText;
			document.body.appendChild(div.firstChild);
		}
	}
	xmlHttp.send(null);
}

if((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i)))
{
	addEventListener("load", function()
	{
		setTimeout(updateLayout, 0);
	}, false);
	
	addEventListener("load", loadFooter, false);

	var currentWidth = 0;
	
	function updateLayout()
	{
		if (window.innerWidth != currentWidth)
		{
			currentWidth = window.innerWidth;
	
			var orient = currentWidth == 320 ? "profile" : "landscape";
			document.body.setAttribute("orient", orient);
			setTimeout(function()
			{
				window.scrollTo(0, 1);
			}, 100);            
		}
	}
	
	setInterval(updateLayout, 400);
}
else if (xmlHttp)
{
	if (navigator.userAgent.match("MSIE"))
		attachEvent("onload",loadFooter);
	else
		addEventListener("load", loadFooter, false);
}
	
