//Ashurst alumni javascript

var objMove = new Object;
var objDrag = new Object;

function createMoveVariables(strGuid){
	objMove[strGuid] = false;
	objDrag[strGuid] = {z: 0, x: 0, y: 0, offsetx : null, offsety : null, targetobj : null, dragapproved : 0, initialize:function(){
		document.onmousedown=this.drag; 
		document.onmouseup=function(){this.dragapproved=0}
		},drag:function(e){var evtobj=window.event? window.event : e
		this.targetobj=window.event? event.srcElement : e.target
		if (this.targetobj.className=='drag' || this.targetobj.className=='drag1' || this.targetobj.className=='drag2'){
			if (this.targetobj.className=='drag1'){
				this.targetobj=this.targetobj.parentElement
			}
			if (this.targetobj.className=='drag2'){
				this.targetobj=this.targetobj.parentElement.parentElement
			}
			this.dragapproved=1
			var divs=document.getElementsByTagName('div')
			for (var intcount=0; intcount < divs.length; intcount++) 
				{
					divs[intcount].style.zIndex=0;
				}
			this.targetobj.style.zIndex=100;
			if (isNaN(parseInt(this.targetobj.style.left))){
				this.targetobj.style.left=0
			} 
			if (isNaN(parseInt(this.targetobj.style.top))){
				this.targetobj.style.top=0
			} 
			this.offsetx=parseInt(this.targetobj.style.left) 
			this.offsety=parseInt(this.targetobj.style.top)
			this.x=evtobj.clientX
			this.y=evtobj.clientY
			if (evtobj.preventDefault) 
				evtobj.preventDefault()
			document.onmousemove=objDrag[strGuid].moveit 
			}},moveit:function(e){
				var evtobj=window.event? window.event : e
				if (this.dragapproved==1){
					this.targetobj.style.left=this.offsetx+evtobj.clientX-this.x+'px'
					this.targetobj.style.top=this.offsety+evtobj.clientY-this.y+'px'
					return false}}}
			objDrag[strGuid].initialize()
}

function moveLeft(strGuid){
	objMove[strGuid]=true; 
	doMoveLeft(strGuid);
} 
			
function doMoveLeft(strGuid){
	if(objMove[strGuid]==true){
		document.all("pgContainer" + strGuid).scrollLeft=document.all("pgContainer" + strGuid).scrollLeft-1;
		window.setTimeout("doMoveLeft('" + strGuid + "')",5)
	}
} 

function moveRight(strGuid){
	objMove[strGuid]=true; 
	doMoveRight(strGuid);
} 
	
function doMoveRight(strGuid){
	if(objMove[strGuid]==true){
		document.all("pgContainer" + strGuid).scrollLeft=document.all("pgContainer" + strGuid).scrollLeft+1;
		window.setTimeout("doMoveRight('" + strGuid + "')",5)
	}
} 
		
function stopMove(strGuid){
	objMove[strGuid]=false;
} 
			
function changeImage(strGuid,obj,txt,txt2,amount,description,counttext){ 
	if(parseInt(txt.value)>=0 && parseInt(txt.value) < document.all("pgTable" + strGuid).cells.length)
	{ 
		obj.src=document.all("pgTable" + strGuid).cells(parseInt(txt.value)).childNodes(0).largeImageSrc 
		obj.alt=document.all("pgTable" + strGuid).cells(parseInt(txt.value)).childNodes(0).alt
		
		var x=parseInt(txt.value) + 1;
		
		description.innerText=document.all("pgTable" + strGuid).cells(parseInt(txt.value)).childNodes(0).alt;
		txt.value=parseInt(txt.value) + amount; 
		txt2.value=parseInt(txt2.value) + amount;
		
		if(parseInt(txt.value)>=document.all("pgTable" + strGuid).cells.length){
			txt.value=document.all("pgTable" + strGuid).cells.length;
			txt2.value=document.all("pgTable" + strGuid).cells.length - 2
		} 
		
		if(parseInt(txt.value)<0){txt.value=-1;txt2.value=1};	
		counttext.innerText="Image " + x.toString() + " of " + document.all("pgTable" + strGuid).cells.length.toString();
	}
} 

function generateGuidForPopUp()
{
	var strResult, intFloor, intCount;
	strResult = '';
	for(intCount=0; intCount<32; intCount++)
	{
		if( intCount == 8 || intCount == 12|| intCount == 16|| intCount == 20)
		//strResult = strResult + '-';
		intFloor = Math.floor(Math.random()*16).toString(16).toUpperCase();
		strResult = strResult + intFloor;
	}
	return strResult
}

function generatePopUp(strURL){
			var strGuid = generateGuidForPopUp();
			createMoveVariables(strGuid);
			
			var objImage = new Image();
			objImage.src = strURL
			
			var divDisplayContainer = document.createElement("div");
			divDisplayContainer.style.position="absolute"
			divDisplayContainer.style.border="#444444 1px solid"
			divDisplayContainer.style.display="inline";
			divDisplayContainer.style.filter="progid:DXImageTransform.Microsoft.Shadow(color=gray,direction=135)"
			divDisplayContainer.style.width=objImage.width
			divDisplayContainer.style.cursor="default"
			divDisplayContainer.style.position="absolute"
			divDisplayContainer.style.backgroundColor="#ffffff"
			divDisplayContainer.style.textAlign="center"
			divDisplayContainer.style.left=event.clientX
			divDisplayContainer.style.top=event.clientY
			divDisplayContainer.className='drag'
			divDisplayContainer.id='pgDisplayContainer' + strGuid			
			
			var divCloseBox = document.createElement("div");
			divCloseBox.className="drag1";
			divCloseBox.id="pgCloseBox" + strGuid
			divCloseBox.style.backgroundPosition="left bottom";
			divCloseBox.style.backgroundImage="url(/_layouts/1033/images/ashurst/toolgrad.gif)";
			divCloseBox.style.verticalAlign="middle";
			divCloseBox.style.width=objImage.width
			divCloseBox.style.cursor="default";
			divCloseBox.style.backgroundRepeat="repeat-x";
			divCloseBox.style.height="20px";
			divCloseBox.style.backgroundColor="transparent";
			
			var spnCount = document.createElement("span");
			spnCount.className='drag2'
			spnCount.id='spanCount' + strGuid
			spnCount.style.width=objImage.width
			spnCount.style.cursor="default";
			spnCount.style.color="#000000";
			spnCount.style.textAlign="right";
			
			var aClose = document.createElement("a");
			aClose.href="#";
			aClose.style.verticalAlign="middle";
			aClose.style.height="20px" 
			aClose.onclick = function(){closeImagePopUp()};
					
			var imgClose = document.createElement("img");		
			imgClose.border='0' 
			imgClose.src='/_layouts/images/wpclose.gif' 
			imgClose.style.verticalAlign='middle'
		
			var imgPreview = document.createElement("img");
			imgPreview.src=objImage.src
			
			aClose.appendChild(imgClose);
			spnCount.appendChild(aClose);
			divCloseBox.appendChild(spnCount);
			divDisplayContainer.appendChild(divCloseBox);
			divDisplayContainer.appendChild(imgPreview);
		
			var bodyRef = document.getElementsByTagName("body").item(0);
			bodyRef.appendChild(divDisplayContainer);
		
}

function showPicture(e,strGuid,intCurrentImage,intPrevImage,intNextImage,intTotalImages,strImageUrl)
{ 

    var objPrevImage = document.getElementById("txtPrevImage" + strGuid);
    var objNextImage = document.getElementById("txtNextImage" + strGuid);
    var objDisplayContainer = document.getElementById("pgDisplayContainer" + strGuid);
    var objImageDisplay = document.getElementById("imgPgDisplay" + strGuid);
    var objDescription = document.getElementById("spnDescription" + strGuid);
    var objCount = document.getElementById("spanCount" + strGuid);

    objPrevImage.value = intPrevImage;
    objNextImage.value = intNextImage;

    objDisplayContainer.style.left = (getWindowWidth()/2)-300;
    objDisplayContainer.style.top = 100;
    objDisplayContainer.style.display = 'inline';
    objImageDisplay.alt = e.alt;
    objDescription.innerText = e.alt;
    objCount.innerText = "Image " + intCurrentImage + " of " + intTotalImages;
    objImageDisplay.src = strImageUrl;
}

function getWindowWidth(){
    var winW = 250;

    // Get the height/width of the window space
    if (navigator.appName=="Netscape") {
        winW = window.innerWidth;
    }
    if (navigator.appName.indexOf("Microsoft")!=-1){
        winW = document.body.offsetWidth;
    }  
    return winW;
}


function closeImagePopUp(){
	event.srcElement.parentElement.parentElement.parentElement.parentElement.style.display='none'
}