var copyHeight = "" 
var pID;

function updatePageCopy(pageID){
		
	/*show loader*/
	document.getElementById("loader").style.display='block';
	
	Effect.Fade("pageCopy",{ duration: 1, queue: { position: 'end', scope: 'fadeQue' } });
	Effect.BlindUp("pageCopy",{ duration: 1, queue: { position: 'end', scope: 'blindQue' } });
		
	/*if we don't finish the effect, sometimes the ajax beats us to it, and it looks weird,
	there is a bug in scriptaculous where afterFinish doesn't always wait until the effect is done*/
	pID = pageID;
	setTimeout("pageDataRequest(pID)",1000);
}

function pageDataRequest(pageID){
	
	var pageAjax = ajaxObj();
	
	/*once we hear back from the server, update the div*/
	pageAjax.onreadystatechange=function(){
		if(pageAjax.readyState==4){
			/*0 - name, 1 - title, 2 - code*/
			pageArray = eval(pageAjax.responseText);
			
			/*pageTracker._trackPageview("/pagefilename1");*/
			
			document.getElementById("pageCopy").innerHTML = pageArray[2];
			document.getElementById("pageMetaKeywords").content = pageArray[3];
			document.getElementById("pageMetaDesc").content = pageArray[4];
						
			getPageModules(pageID);
												
			/*we need to delay it so all the content is in place, otherwise it may not extend all the way and break*/
			Effect.Appear("pageCopy",{ duration: 1, queue: { position: 'end', scope: 'fadeQue' } });
			Effect.BlindDown("pageCopy",{ duration: 1, queue: { position: 'end', scope: 'blindQue' } });
			
			document.title = pageArray[1];

			/*hide loader*/
			document.getElementById("loader").style.display = "none";
			
		}
	}
	
	/*make the request for the page content*/
	var requestParams = "function=getPage&pageID=" + pageID;
		
	ajaxPost(pageAjax,"/cmsAPI/pages/pages.php",requestParams);
}

/*requests a multi dimensional array, and evaluates it*/
function getPageModules(pageID){
	var pageModule = ajaxObj();
	
	var requestParams ="function=getPageModules&pageID=" + pageID;
	
	pageModule.onreadystatechange=function(){
		if(pageModule.readyState==4){
			/*creates array publicModule[][]...
			first array is a module, second array is as follows...
			0 - includes
			1 - jScript
			2 - dynJScript
			3 - cssLink*/
			eval(pageModule.responseText);
			
			for(g=0;g<publicModule.length;g++){
				/* module itself...*/
				getModuleHTML(publicModule[g][0]);
				/*script and style for the module...*/
				insertScriptandStyle(publicModule[g][1],publicModule[g][3]);
			}

		}
	}
	
	ajaxPost(pageModule,"/cmsAPI/module/publicModulePageMap.php",requestParams);
	
}

function getModuleHTML(modulePath){
	var moduleAjax = ajaxObj();
	
	moduleAjax.onreadystatechange=function(){
		if(moduleAjax.readyState==4){
			ajaxResponse = moduleAjax.responseText;
			document.getElementById("pageCopy").innerHTML = document.getElementById("pageCopy").innerHTML + ajaxResponse;
		}
	}
	moduleAjax.open("GET",modulePath,true);
	moduleAjax.send(null);
}


