function changePage(i, a, p, d){

	// change the URL for bookmarking
	if (p == ''){
		window.location.hash = '/' + i + '/' + a + '.html';
	} else {
		window.location.hash = '/' + i + '/' + a + ',' + p + '.html';
	}
	
	// enable the loading screen
	//$('#loading').css('display', 'block');
	
	// send the request
	req = createObject();
	req.onreadystatechange = function(){ changePageComplete(i, a, d) };
	req.open("GET", "/callers/changePage.asp?i=" + i + "&a=" + a + "&p=" + p, true);
	req.send(null);
	
	return false;
}

function changePageComplete(i, a, d){
	
	if (req.readyState == 4){
	
		// finished loading
		//$('#loading').css('display', 'none');
		
		// build response object
		var data = req.responseXML;
		
		// check for error message
		varError = data.getElementsByTagName("error")[0];
		if (varError.childNodes.length > 0){
			return false;
		}
		
		// set page title
		varTitle = data.getElementsByTagName("title")[0].childNodes[0].nodeValue;
		document.title = varTitle;
		
		// re-write the previous page button
		varPrevSlug = data.getElementsByTagName("prevSlug")[0];
		varPrevPage = data.getElementsByTagName("prevPage")[0];
		varPrevLink = data.getElementsByTagName("prevLink")[0];
		
		if (varPrevSlug.childNodes.length == 0){
			$('#movePrevious').css('display', 'none');
		} else {
			if (varPrevPage.childNodes.length == 0){
				varOnClick1 = "return changePage('" + i + "', '" + varPrevSlug.childNodes[0].nodeValue + "', '');"
				prevPageVal = ""
			} else {
				varOnClick1 = "return changePage('" + i + "', '" + varPrevSlug.childNodes[0].nodeValue + "', '" + varPrevPage.childNodes[0].nodeValue + "');"
				prevPageVal = varPrevPage.childNodes[0].nodeValue;
			}
			
			$('#movePrevious a').unbind('click').bind('click', function(){
				return changePage(i, varPrevSlug.childNodes[0].nodeValue, prevPageVal, 'prev');
			});
			
			$('#movePrevious').css('display', 'block');
			$('#movePrevious a').attr('href', varPrevLink.childNodes[0].nodeValue);
		}
		
		// re-write the next page button
		varNextSlug = data.getElementsByTagName("nextSlug")[0];
		varNextPage = data.getElementsByTagName("nextPage")[0];
		varNextLink = data.getElementsByTagName("nextLink")[0];
		
		if (varNextSlug.childNodes.length == 0){
			$('#moveNext').css('display', 'none');
		} else {
			if (varNextPage.childNodes.length == 0){
				varOnClick2 = "return changePage('" + i + "', '" + varNextSlug.childNodes[0].nodeValue + "', '');"
				nextPageVal = ""
			} else {
				varOnClick2 = "return changePage('" + i + "', '" + varNextSlug.childNodes[0].nodeValue + "', '" + varNextPage.childNodes[0].nodeValue + "');"
				nextPageVal = varNextPage.childNodes[0].nodeValue;
			}
			
			$('#moveNext a').unbind('click').bind('click', function(){
				return changePage(i, varNextSlug.childNodes[0].nodeValue, nextPageVal, 'next');
			
			});
			$('#moveNext').css('display', 'block');
			$('#moveNext a').attr('href', varNextLink.childNodes[0].nodeValue);
		}
		
		// left menu handling
		$('#toc a').removeClass('selected');
		$('#toc a[href="' + a + '.html"]').addClass('selected');
		
		// change the buttons
		$('#buttons').html("");
		
		var buttons;
		buttons = data.getElementsByTagName("button");
		
		if (buttons != null){
			for (k = 0; k < buttons.length; k++){
				buttonCaption = buttons[k].getElementsByTagName("buttonCaption")[0].childNodes[0].nodeValue;
				buttonURL = buttons[k].getElementsByTagName("buttonURL")[0].childNodes[0].nodeValue;
				buttonImage = buttons[k].getElementsByTagName("buttonImage")[0].childNodes[0].nodeValue;
				
				buttonCode = '<a href="' + buttonURL + '" class="adUnit" style="background-image: url(\'' + buttonImage + '\');">' + buttonCaption + '</a>';
				
				$('#buttons').append(buttonCode);
			}
		}
		
		// set page content
		varContent = data.getElementsByTagName("content")[0].childNodes[0].nodeValue;
		
		$('#content2').html($('#content').html());
		$('#content2').css('margin-left', '0');
		$('#content').html(varContent);
		
		if (d == 'prev'){
			$('#content').css('margin-left', '-525px');
			
			$('#content2').animate({
				marginLeft: "525px"
			}, 1000 );
		} else {
			$('#content').css('margin-left', '525px');
			
			$('#content2').animate({
				marginLeft: "-525px"
			}, 1000 );
		}
		
		$('#content').animate({
			marginLeft: "0"
		}, 1000 );
		
		// preload next set of images
		var preloads;
		preloads = data.getElementsByTagName("preload");
		preload_image_object = new Image();
		
		if (preloads != null && (document.images)){
			for (k = 0; k < preloads.length; k++){
				preloadURL = preloads[k].childNodes[0].nodeValue;
				preload_image_object.src = preloadURL;
			}
		}
		
	}

}

function createObject(){

	var request_object;
	var browser = navigator.appName;
	
	if (browser == "Microsoft Internet Explorer"){
		request_object = new ActiveXObject("Microsoft.XMLHTTP");
	} else {
		request_object = new XMLHttpRequest();
	}
	
	return request_object;

}

function issueSelector()
{
	if (document.getElementById('issueList').style.display == 'block'){
		document.getElementById('issueList').style.display = 'none';
	} else {
		document.getElementById('issueList').style.display = 'block';
	}
	
	document.getElementById('issueSelectorLink').blur();
	
	return false;
}