// JavaScript Document
/* Javascript for xml/xsl transformations 
var domDoc = Sarissa.getDomDocument();
domDoc.async = false;
var styleSheet = Sarissa.getDomDocument();
styleSheet.async = false;
var processor = new XSLTProcessor();
*/
var accOuter;
/*
function loadDoc(xslDoc, xmlDoc) {
	styleSheet.load(xslDoc);
    var rHandler = function() {
        if ( domDoc.readyState == 4) {
            //document.getElementById('OuterAccordion').innerHTML = "Document Loaded, ready to transform<br />";
            //document.getElementById('afterLoad').style.display = 'block';
        }
    }
    domDoc.onreadystatechange = rHandler;
    domDoc.load(xmlDoc);
	transform();
}
*/
function transform() {
    //processor.importStylesheet(styleSheet);
    //var output = processor.transformToDocument(domDoc);

    //var target = document.getElementById('target');
    //target.appendChild(document.importNode(output.firstChild,true));
	accOuter = new Spry.Widget.Accordion("OuterAccordion", { useFixedPanelHeights: false, enableAnimation: true, defaultPanel: -1 });
	// check if we should open a panel
	var query = window.location.search.substring(1);
	var vars = query.split("&");
	if (query.length > 0) {
	for (var i=0;i<vars.length;i++) {
   		var pair = vars[i].split("=");
   		if (pair[0] == 'fund' ) {
			num = parseFloat(pair[1]);
			accOuter.openPanelNum(num);
			var target = "fund" + (num + 1);
			var position = getAnchorPosition(target);
			//alert(position.y + ":" + (position.y - 25));
			
			/* use this to do the delayed scrolling */
			scrollPage(position.y - 50);
			
			/* this will scroll instantly */
			//window.scrollTo(0, position.y - 50);
   		}
		if(pair[0] == 't') {
		} 
	} 
	}
	else accOuter.openPanelNum(0);
}

/* Javascript for accordion */
function handleAccBtn(acc) {
	
}

function scrollPage(targetY){
	var curY = getScrollHeight();
	if (curY < targetY){
		window.scrollBy(0, 20);
		if (curY < getScrollHeight()) { //scroll happened
			setTimeout('scrollPage(' + targetY + ', ' + getScrollHeight() + ')', 	1);
		}
		
	}
}

function getScrollHeight()
{
   var h = window.pageYOffset ||
           document.body.scrollTop ||
           document.documentElement.scrollTop;
           
   return h ? h : 0;
}
/* deleting for testing of css fix 
var openPanel = null;
function handleAccBtn(acc) {
	if(acc == openPanel) { return; }
	openPanel = acc;
	
	var thisbtn;
	var accContainer = document.getElementById("OuterAccordion");
	var accLen = accContainer.childNodes.length + 1;
	for(i=1; i < accLen; i++) {
		if(document.getElementById("acc" + i)){
			document.getElementById("acc" + i).style.backgroundColor = "#ffffff";
			document.getElementById("acc" + i + "btn").style.background = "url(../images/btn_openPanel.gif) top left no-repeat";
		}
	}
	
	document.getElementById(acc + "btn").style.background = "url(../images/btn_closePanel.gif) top left no-repeat";
	document.getElementById(acc).style.backgroundColor = "#f2f2f2";

}
	
var openGiftItem = '';
function handleInnerGiftItem(gi) {
	//alert("got: " + gi);
	for(i=1; i < 18; i++) {
		document.getElementById("sec1opp" + i).style.backgroundColor = "#ffffff";
		document.getElementById("sec1opp" + i + "btn").src = "../images/btn_openPanel.gif";
	}
		
	document.getElementById(gi).style.backgroundColor = "#f2f2f2";
	document.getElementById(gi + "btn").src = "../images/btn_closePanel.gif";
}
*/

/* position finder */
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 {"x":curleft,"y":curtop};
}


// ===================================================================
// Author: Matt Kruse <matt@mattkruse.com>
// WWW: http://www.mattkruse.com/
//
// NOTICE: You may use this code for any purpose, commercial or
// private, without any further permission from the author. You may
// remove this notice from your final code if you wish, however it is
// appreciated by the author if at least my web site address is kept.
//
// You may *NOT* re-distribute this code in any way except through its
// use. That means, you can include it in your product, or your web
// site, or any other form where the code is actually being used. You
// may not put the plain javascript up on your site for download or
// include it in your javascript libraries for download. 
// If you wish to share this code with others, please just point them
// to the URL instead.
// Please DO NOT link directly to my .js files from your site. Copy
// the files to your server and use them there. Thank you.
// ===================================================================

function getAnchorPosition(anchorname){var useWindow=false;var coordinates=new Object();var x=0,y=0;var use_gebi=false, use_css=false, use_layers=false;if(document.getElementById){use_gebi=true;}else if(document.all){use_css=true;}else if(document.layers){use_layers=true;}if(use_gebi && document.all){x=AnchorPosition_getPageOffsetLeft(document.all[anchorname]);y=AnchorPosition_getPageOffsetTop(document.all[anchorname]);}else if(use_gebi){var o=document.getElementById(anchorname);x=AnchorPosition_getPageOffsetLeft(o);y=AnchorPosition_getPageOffsetTop(o);}else if(use_css){x=AnchorPosition_getPageOffsetLeft(document.all[anchorname]);y=AnchorPosition_getPageOffsetTop(document.all[anchorname]);}else if(use_layers){var found=0;for(var i=0;i<document.anchors.length;i++){if(document.anchors[i].name==anchorname){found=1;break;}}if(found==0){coordinates.x=0;coordinates.y=0;return coordinates;}x=document.anchors[i].x;y=document.anchors[i].y;}else{coordinates.x=0;coordinates.y=0;return coordinates;}coordinates.x=x;coordinates.y=y;return coordinates;}
function getAnchorWindowPosition(anchorname){var coordinates=getAnchorPosition(anchorname);var x=0;var y=0;if(document.getElementById){if(isNaN(window.screenX)){x=coordinates.x-document.body.scrollLeft+window.screenLeft;y=coordinates.y-document.body.scrollTop+window.screenTop;}else{x=coordinates.x+window.screenX+(window.outerWidth-window.innerWidth)-window.pageXOffset;y=coordinates.y+window.screenY+(window.outerHeight-24-window.innerHeight)-window.pageYOffset;}}else if(document.all){x=coordinates.x-document.body.scrollLeft+window.screenLeft;y=coordinates.y-document.body.scrollTop+window.screenTop;}else if(document.layers){x=coordinates.x+window.screenX+(window.outerWidth-window.innerWidth)-window.pageXOffset;y=coordinates.y+window.screenY+(window.outerHeight-24-window.innerHeight)-window.pageYOffset;}coordinates.x=x;coordinates.y=y;return coordinates;}
function AnchorPosition_getPageOffsetLeft(el){var ol=el.offsetLeft;while((el=el.offsetParent) != null){ol += el.offsetLeft;}return ol;}
function AnchorPosition_getWindowOffsetLeft(el){return AnchorPosition_getPageOffsetLeft(el)-document.body.scrollLeft;}
function AnchorPosition_getPageOffsetTop(el){var ot=el.offsetTop;while((el=el.offsetParent) != null){ot += el.offsetTop;}return ot;}
function AnchorPosition_getWindowOffsetTop(el){return AnchorPosition_getPageOffsetTop(el)-document.body.scrollTop;}






