var xmlHttp = createXmlHttpRequestObject();

function createXmlHttpRequestObject() {
    try {
        xmlHttp = new XMLHttpRequest();                             /* all except IE */
    } catch(e) {
        try {
            xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");          /* some versions IE */
        } catch (e) {
            try {
                xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");      /* some versions IE */
            } catch (e) {}
        }
    }
    if (!xmlHttp)
        alert("Error creating the XMLHttpRequest object.");
    else
        return xmlHttp;
}
                
function openPhoto(path) {
	hideMenu();
	document.getElementById('photoContainer').onmouseover = hideMenu;
    document.getElementById('photoContainer').style.visibility = 'visible';
    document.getElementById('photoBackground').style.visibility = 'visible';

    xmlHttp.open("GET", "showphoto.php?which="+path, true);
    xmlHttp.onreadystatechange=function() {
        if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
            var response = xmlHttp.responseText;
            var brokenstring = response.split("*");
            var width = brokenstring[0];
            var height = brokenstring[1];
            var prev = brokenstring[2];
            var next = brokenstring[3];
            var alignleft = width/2;
            var aligntop = height/2;
            
            height = parseFloat(height)+30;
            
            document.getElementById('photoContainer').style.width = width+"px";
            document.getElementById('photoContainer').style.height = height+"px";
            
            document.getElementById('photoContainer').style.marginLeft = -alignleft+"px";
            document.getElementById('photoContainer').style.marginTop = -aligntop+"px";
            document.getElementById('theImage').src = path;
            document.getElementById('hiddendiv').title = prev;
            document.getElementById('hiddendiv2').title = next;
			document.getElementById('photoContainer').onmouseover = showMenu;
			showMenu();
        }
    }
	xmlHttp.send(null);
}
                
function openPhotoPrev() {
	hideMenu();
	document.getElementById('photoContainer').onmouseover = hideMenu;
    path = document.getElementById('hiddendiv').title;
    xmlHttp.open("GET", "showphoto.php?which="+path, true);
    xmlHttp.onreadystatechange=function() {
        if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
            var response = xmlHttp.responseText;
            var brokenstring = response.split("*");
            var width = brokenstring[0];
            var height = brokenstring[1];
            var prev = brokenstring[2];
            var next = brokenstring[3];
            var alignleft = width/2;
            var aligntop = height/2;
            height = parseFloat(height)+30;
            document.getElementById('photoContainer').style.width = width+"px";
            document.getElementById('photoContainer').style.height = height+"px";
            document.getElementById('photoContainer').style.marginLeft = -alignleft+"px";
            document.getElementById('photoContainer').style.marginTop = -aligntop+"px";
            document.getElementById('theImage').src = path;
            document.getElementById('hiddendiv').title = prev;
            document.getElementById('hiddendiv2').title = next;
			document.getElementById('photoContainer').onmouseover = showMenu;
			showMenu();
        }
    }
	xmlHttp.send(null);
}
                
function openPhotoNext() {
	hideMenu();
	document.getElementById('photoContainer').onmouseover = hideMenu;
    path = document.getElementById('hiddendiv2').title;
    xmlHttp.open("GET", "showphoto.php?which="+path, true);
    xmlHttp.onreadystatechange=function() {
        if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
            var response = xmlHttp.responseText;
            var brokenstring = response.split("*");
            var width = brokenstring[0];
            var height = brokenstring[1];
            var prev = brokenstring[2];
            var next = brokenstring[3];
            var alignleft = width/2;
            var aligntop = height/2;
            height = parseFloat(height)+30;
            document.getElementById('photoContainer').style.width = width+"px";
            document.getElementById('photoContainer').style.height = height+"px";
            document.getElementById('photoContainer').style.marginLeft = -alignleft+"px";
            document.getElementById('photoContainer').style.marginTop = -aligntop+"px";
            document.getElementById('theImage').src = path;
            document.getElementById('hiddendiv').title = prev;
            document.getElementById('hiddendiv2').title = next;
			document.getElementById('photoContainer').onmouseover = showMenu;
			showMenu();
        }
    }
	xmlHttp.send(null);
}
                
function showMenu() {
    document.getElementById('photoMenu').style.visibility = 'visible';   
}
                
function hideMenu() {
    document.getElementById('photoMenu').style.visibility = 'hidden';    
}
                
function closeDiv() {
    document.getElementById('photoContainer').style.visibility = 'hidden';
    document.getElementById('photoBackground').style.visibility = 'hidden';
    document.getElementById('photoMenu').style.visibility = 'hidden';    
}

function pleaseLogin() {
	alert('Please login in order to view this album');
	return false;
}

/////////////////////////////////

function openPhotoN(path) {
    hideMenu();
    document.getElementById('photoContainer').onmouseover = hideMenu;
    document.getElementById('photoContainer').style.visibility = 'visible';
    document.getElementById('photoBackground').style.visibility = 'visible';

    xmlHttp.open("GET", "shownewsphoto.php?which="+path, true);
    xmlHttp.onreadystatechange=function() {
        if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
            var response = xmlHttp.responseText;
            var brokenstring = response.split("*");
            var width = brokenstring[0];
            var height = brokenstring[1];
            var prev = brokenstring[2];
            var next = brokenstring[3];
            var alignleft = width/2;
            var aligntop = height/2;
            
            height = parseFloat(height)+30;
            
            document.getElementById('photoContainer').style.width = width+"px";
            document.getElementById('photoContainer').style.height = height+"px";
            
            document.getElementById('photoContainer').style.marginLeft = -alignleft+"px";
            document.getElementById('photoContainer').style.marginTop = -aligntop+"px";
            document.getElementById('theImage').src = path;
            document.getElementById('hiddendiv').title = prev;
            document.getElementById('hiddendiv2').title = next;
            document.getElementById('photoContainer').onmouseover = showMenu;
            showMenu();
        }
    }
    xmlHttp.send(null);
}
                
function openPhotoPrevN() {
    hideMenu();
    document.getElementById('photoContainer').onmouseover = hideMenu;
    path = document.getElementById('hiddendiv').title;
    xmlHttp.open("GET", "shownewsphoto.php?which="+path, true);
    xmlHttp.onreadystatechange=function() {
        if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
            var response = xmlHttp.responseText;
            var brokenstring = response.split("*");
            var width = brokenstring[0];
            var height = brokenstring[1];
            var prev = brokenstring[2];
            var next = brokenstring[3];
            var alignleft = width/2;
            var aligntop = height/2;
            height = parseFloat(height)+30;
            document.getElementById('photoContainer').style.width = width+"px";
            document.getElementById('photoContainer').style.height = height+"px";
            document.getElementById('photoContainer').style.marginLeft = -alignleft+"px";
            document.getElementById('photoContainer').style.marginTop = -aligntop+"px";
            document.getElementById('theImage').src = path;
            document.getElementById('hiddendiv').title = prev;
            document.getElementById('hiddendiv2').title = next;
            document.getElementById('photoContainer').onmouseover = showMenu;
            showMenu();
        }
    }
    xmlHttp.send(null);
}
                
function openPhotoNextN() {
    hideMenu();
    document.getElementById('photoContainer').onmouseover = hideMenu;
    path = document.getElementById('hiddendiv2').title;
    xmlHttp.open("GET", "shownewsphoto.php?which="+path, true);
    xmlHttp.onreadystatechange=function() {
        if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
            var response = xmlHttp.responseText;
            var brokenstring = response.split("*");
            var width = brokenstring[0];
            var height = brokenstring[1];
            var prev = brokenstring[2];
            var next = brokenstring[3];
            var alignleft = width/2;
            var aligntop = height/2;
            height = parseFloat(height)+30;
            document.getElementById('photoContainer').style.width = width+"px";
            document.getElementById('photoContainer').style.height = height+"px";
            document.getElementById('photoContainer').style.marginLeft = -alignleft+"px";
            document.getElementById('photoContainer').style.marginTop = -aligntop+"px";
            document.getElementById('theImage').src = path;
            document.getElementById('hiddendiv').title = prev;
            document.getElementById('hiddendiv2').title = next;
            document.getElementById('photoContainer').onmouseover = showMenu;
            showMenu();
        }
    }
    xmlHttp.send(null);
}