var loading = '<div><center><img border="0" src="../images/loading.gif" ></center></div>';

function loadPrettyPhoto() {
                $(document).ready(function(){
                        $("a[rel^='prettyPhoto']").prettyPhoto({ keyboard_shortcuts: false });
                });
}

function createRequestObject() {
    var ro;
    var browser = navigator.appName;
    if(browser == "Microsoft Internet Explorer"){
        ro = new ActiveXObject("Microsoft.XMLHTTP");
    }else{
        ro = new XMLHttpRequest();
    }
    return ro;
}


function zoom(imgsrc) {
	document.getElementById("overlay").innerHTML = loading;
        document.getElementById("backarea").style.height=document.documentElement.scrollHeight+'px';
        document.getElementById("backarea").style.width=document.documentElement.clientWidth+'px';
	document.getElementById("overlay").style.height=document.documentElement.scrollHeight+'px';
        document.getElementById("overlay").style.width=document.documentElement.clientWidth+'px';
	
        document.getElementById("backarea").style.display="block";
        document.getElementById("overlay").style.display="block";
	document.getElementById("overlay").innerHTML = "<table width=100% height=100%><tr><TD valign=center><center><img src='"+imgsrc+"' class=zoomimage onclick='closezoom();'> <BR><div onclick='closezoom();'>Click to close</div></center></td></tr></table>";
}

function closezoom() {
	document.getElementById("backarea").style.display="none";
        document.getElementById("overlay").style.display="none";
}

function showimage(id,imageid) {
	var url="../calls/showimage.php";
        var data="imageid="+imageid;
	document.getElementById(id).innerHTML = loading;
        var http = createRequestObject();
        http.open("POST", url, true);http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
        http.send(data);
        http.onreadystatechange=function() {
                if(http.readyState == 4) {
                        document.getElementById(id).innerHTML =http.responseText;
                }
        }
}


function closePop (id) {
	document.getElementById(id).style.display ='none';
	window.location.href=window.location.href
}

function changesection(max,change) {
        next = document.getElementById("currentsection").value;
	if (change=='next') {
	next++;
	} else {
	next--;
	}
	if (next > max) { next=1; }
	if (next < 1) { next=max; }
	showsection(next,max);
	document.getElementById("currentsection").value=next;
}

function showsection(testid,max) {
	var i=1;
	while (i<=max)
{
toggleBox(i,0);
toggleLink(i,0);
i=i+1;
}
toggleBox(testid,1);
toggleLink(testid,1);
}	

function toggleBox(szDivID, iState) // 1 visible, 0 hidden
{
	szDivID="thumbs"+szDivID;
    if(document.layers)	   //NN4+
    {
       document.layers[szDivID].visibility = iState ? "block" : "none";
    }
    else if(document.getElementById)	  //gecko(NN6) + IE 5+
    {
        var obj = document.getElementById(szDivID);
        obj.style.display = iState ? "block" : "none";
    }
    else if(document.all)	// IE 4
    {
        document.all[szDivID].style.display = iState ? "block" : "none";
    }
}

function toggleLink(szDivID, iState) // 1 blank, 0 white
{
        szDivID="link"+szDivID;
    if(document.layers)    //NN4+
    {
       document.layers[szDivID].color = iState ? "#000000" : "#900";
    }
    else if(document.getElementById)      //gecko(NN6) + IE 5+
    {
        var obj = document.getElementById(szDivID);
        obj.style.color = iState ? "#000000" : "#900";
    }
    else if(document.all)       // IE 4
    {
        document.all[szDivID].style.color = iState ? "#000000" : "#900";
    }
}

function gotopage(formname,id,n) {
        document.getElementById(id).value=n;
        document.forms[formname].submit();
}

//findPos function is from http://www.quirksmode.org/js/findpos.html;
//where its workings are explained in more detail.
function findPos(obj) {
        var curleft = curtop = 0;
        if (obj.offsetParent) {
                curleft = obj.offsetLeft
                curtop = obj.offsetTop
                while (obj = obj.offsetParent) {
                        curleft += obj.offsetLeft
                        curtop += obj.offsetTop
                }
        }
        return [curleft,curtop];
}

//Display a named <strong class="highlight">menu</strong>, at the position of another object
function display_menu(parent,named)
{
        //get the named <strong class="highlight">menu</strong>
        var menu_element = document.getElementById(named);
        //override the 'display:none;' style attribute
        menu_element.style.display = "block";
        //get the placement of the element that invoked the <strong class="highlight">menu</strong>...
        var placement = findPos(parent);
placement[1]=placement[1]-110;
        //...and put the <strong class="highlight">menu</strong> there
        //menu_element.style.left = placement[0] + "px";
menu_element.style.left = "200px";
        menu_element.style.top = placement[1] + "px";
	//menu_element.style.top = "20px";
}

//Hide a named <strong class="highlight">menu</strong>
function hide_menu(named)
{
        //get the named <strong class="highlight">menu</strong>
        var menu_element = document.getElementById(named);
        //hide it with a style attribute
        menu_element.style.display = "none";
}

