var childMap;
function initWindows() {
	if (document.getElementById("mapviewdesktop")) {
		var x = document.getElementsByTagName("a");
		for(i=0; i<x.length; i++) {
			x[i].addEventListener("click", function(event) {
				event.preventDefault();
				var a = event.target;
				updateParent(a);
			}, true);
		}
		resizeWin();
	}
	else {
		childMap = window.open("map_desktop.php","newWin","status=yes,width=480,height=285");	
	}
}

function resizeWin()
{
    winHeight=document.body.offsetHeight;
    winWidth=document.body.offsetWidth;
    window.resizeTo(winWidth,winHeight+75);
}

function updateParent(a) {
	var elem = opener.document.getElementById(a.id);
	opener.window.ciUI.goToPage(elem);
}

function updateChild(html){
	childMap.document.getElementById("mapview").innerHTML = html;
	childMap.initWindows();
}

function updateMap(uid){
	var url;
    switch (window.orientation){
        case 0:
            document.getElementById('mapviewcontainer').style.left = "-9999px";
			document.getElementById('mapviewcontainer').style.top = "-9999px";
            document.getElementById('iphone_body').style.left = "0px";           
            document.getElementById('iphone_header').style.left = "0px";
            document.getElementById('iphone_footer').style.left = "0px";
			url = "ajaxRotateChange.php?uid="+uid+"&ornt=portr";
            break;
        case 90:
            document.getElementById('iphone_body').style.left = "-9999px";
            document.getElementById('iphone_header').style.left = "-9999px";
            document.getElementById('iphone_footer').style.left = "-9999px";
            document.getElementById('mapviewcontainer').style.left = "0px";
			document.getElementById('mapviewcontainer').style.top = "0px";
			url = "ajaxRotateChange.php?uid="+uid+"&ornt=lands";
            break;
        case -90:
            document.getElementById('iphone_body').style.left = "-9999px";
            document.getElementById('iphone_header').style.left = "-9999px";
            document.getElementById('iphone_footer').style.left = "-9999px";
            document.getElementById('mapviewcontainer').style.left = "0px"; 
			document.getElementById('mapviewcontainer').style.top = "0px";
			url = "ajaxRotateChange.php?uid="+uid+"&ornt=landscape";
            break;
    }
	xmlHttp=GetXmlHttpObject();
	if(xmlHttp==null)
    {
	  alert ("Your browser does not support AJAX!");
	  return;
	}
	if(url != null){
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
	}
    setTimeout(function()
    {
		scrollMap();
    }, 100);
}


function scrollMap() {
	if(document.body.clientWidth > 480)
		return;
	var mapItem = document.getElementById('mapview-item');
	if(mapItem != null && window.orientation != 0) {
		scrollFunction("mapview-"+mapItem.value);
	}
	else {
        scrollToTop();
	}
}