

var newTextHeight = 100

// Upon loading the page scroll to the required location
function PageLoad() {
    // obtain the size of the frame
    frameSize(); 
    
    var myIframe = document.getElementById('iframe');
	// scroll to centre on the required person
    myIframe.onload = scrollFrameOnload(hsh, treeCode);
}




function frameSize() {
	//Calculate window size
	if (self.innerWidth)
	{
		frameWidth = self.innerWidth;
		frameHeight = self.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientWidth)
	{
		frameWidth = document.documentElement.clientWidth;
		frameHeight = document.documentElement.clientHeight;
	}
	else if (document.body)
	{
		frameWidth = document.body.clientWidth;
		frameHeight = document.body.clientHeight;
	}

    // calculate FreeSize
    var FreeHeight =  (frameHeight-145);
    //resize frame
    var newFrameHeight = (FreeHeight * 0.75)
    var d = document.getElementById("TreeFrame");
        d.style.height = (newFrameHeight)+'px';
    //resize textbox   
    newTextHeight = (FreeHeight * 0.25);
    var e = document.getElementById("DesText");
        e.style.height = (newTextHeight)+'px';
	return {frameWidth : frameWidth , frameHeight : newFrameHeight , newTextHeight : newTextHeight};
}



function scrollFrameOnload(hsh, treeCode) { // when page loads
    var noCookie = 0
    //alert(window.frames['Tree'].document.body.scrollLeft)     
    //scroll to the required position
    //if (window.frames['Tree'].document.body.scrollLeft < 1) { //check whether arrived from a link
        //alert("no scroll value")
        if (hsh != "" && hsh != "#") {
            //alert(hsh);
            scrollFrame(hsh); // if so scroll to relevant position
            noCookie = 1
        }
    //}
    //else { // if not let the browser return to last position
        //alert("Last Position"+window.frames['Tree'].document.body.scrollLeft)
    //    noCookie = 1
    //}
    //alert(treeCode)

    if (noCookie == 0) {
        //if not assume a cookie exists and extract the values
        var allcookies = document.cookie;
        //alert(document.cookie)
        var pos = allcookies.indexOf(treeCode + "LeftEdge=");
        //alert(pos)
        var start = pos + 13;
        var end = allcookies.indexOf(";", start);
        var value = allcookies.substring(start, end);
        var LeftEdge = parseFloat(value);

        var pos = allcookies.indexOf(treeCode + "TopEdge=");
        var start = pos + 12;
        var end = allcookies.indexOf(";", start);
        var value = allcookies.substring(start, end);
        var TopEdge = parseFloat(value);
        //alert("cookie: " + LeftEdge + ", " + TopEdge)
        //then scroll
        if (pos==-1) {// check that correct cookie value extracted
        // if not then go scroll to default location
        //alert("Default")
            scrollFrame("#Default")
            noCookie=1
        }
        else { //assume cookie and scroll to last position
            jQuery('#TreeFrame').scrollTo( { top:TopEdge,left:LeftEdge},1000 );
            //window.frames['Tree'].scrollTo(LeftEdge, TopEdge);
            noCookie = 0

        }
    }
}


function scrollFrame(hsh) { // Link on page clicked
    frameSize()
    //scroll to the required position
    var pos = name.indexOf(hsh);
    var x1 = pos - 8;
    var x2 = pos - 4;
    var x = name.substr(x1, 4);
    var y = name.substr(x2, 4);
    X = x - (frameWidth / 2) + 10;
    Y = y - (frameHeight * 0.7 / 2) + 40;
    //alert("X= "+X+"Y= "+Y)
    jQuery('#TreeFrame').scrollTo( { top:Y,left:X},1000 );
	//window.frames['Tree'].scrollTo(X, Y);
}



function showlayer(whichLayer){
    //resize textbox
    var e = document.getElementById(whichLayer);
    e.style.height = (e.style.height == '95%') ? (newTextHeight)+'px' : '95%';
}



function resettree(){
  scrollFrame('#Default')
  document.cookie=treeCode+"LeftEdge="+Y;
  document.cookie=treeCode+"TopEdge="+X;
}











document.onclick= function(treeCode){

 
  // Assign cookies so that the parent frames knows where to scroll to on its return
  document.cookie=treeCode+"LeftEdge=" + window.frames['Tree'].document.body.scrollLeft;
  document.cookie=treeCode+"TopEdge=" + window.frames['Tree'].document.body.scrollTop;





/*if (self.innerWidth)
	{
		frameWidth = self.innerWidth;
		frameHeight = self.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientWidth)
	{
		frameWidth = document.documentElement.clientWidth;
		frameHeight = document.documentElement.clientHeight;
	}
	else if (document.body)
	{
		frameWidth = document.body.clientWidth;
		frameHeight = document.body.clientHeight;
	}
	else return;

  alert("Left = "+window.frames['Tree'].document.body.scrollLeft +"; Top = "+ window.frames['Tree'].document.body.scrollTop +"; Width = "+ frameWidth +"; Height = "+ frameHeight);
*/
}
;






