﻿/*-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

	Abyss Public Website: Gallery scripts
	Abyss Studios Ltd. (c) 2004-2007

	history:
		070119 - creation -=AGi=-

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/

function gallery_getScollPosition()
{
	if (document.documentElement) {
		return {x: document.documentElement.scrollLeft, y: document.documentElement.scrollTop };
	}
	else if (document.all) {
		return {x: document.body.scrollLeft, y: document.body.scrollTop };
	}
	else {
		return {x: window.pageXOffset, y: window.pageYOffset };
	}
}

function gallery_getWindowSize()
{
	if (document.documentElement) {
		return {x: document.documentElement.clientWidth, y: document.documentElement.clientHeight };
	}
	else if (document.all) {
		return {x: document.body.clientWidth, y: document.body.clientHeight };
	}
	else {
		return {x: window.innerWidth, y: window.innerHeight };
	}
}


function galleryInit(url)
{
	eBody = document.body; 

	eTrap = document.createElement('div');
	eTrap.id = 'galleryTrap';
	
	eBorder = document.createElement('div');
	eBorder.id = 'galleryBorder';
	
	eContainer = document.createElement('div');
	eContainer.id = 'galleryContainer';
	
	eContainer.innerHTML = '<iframe src="' + url + '" style="width:100%; height:100%; background-color:transparent;" scrolling="no" frameborder="0" allowtransparency="true" id="galleryFrame" name="galleryFrame" width="100%" height="100%"></iframe>';
	
	eBody.appendChild(eTrap);
	eBody.appendChild(eBorder);
	eBody.appendChild(eContainer);	
	

	eContainer.style.visibility = 'hidden';
	
	if (document.all) {
		window.attachEvent('onscroll', galleryScroll);
		window.attachEvent('onresize', galleryResize);
	}
	else {
		eTrap.style.position = 'fixed';
		eBorder.style.position = 'fixed';	
		eContainer.style.position = 'fixed';
		window.onresize = galleryResize;
	}
	
	
	galleryScroll_FixPositions();
	galleryCrossFade(0.7, 0, 200);
}

function galleryInitOnClick(e, url) // stops bubble
{
	galleryInit(url);
	return elementControl_EventStopBubble(e);
}

function galleryScroll()
{
	galleryScroll_FixPositions(true);
}

function galleryResize()
{
	galleryScroll_FixPositions(false);
}

function galleryScroll_FixPositions(isScrolling)
{
	scrollPos = gallery_getScollPosition();
	windowSize = gallery_getWindowSize();
	
	midX = (windowSize.x / 2) + scrollPos.x;
	midY = (windowSize.y / 2) + scrollPos.y;
	if (document.all==null) {
		midY = (windowSize.y / 2);
	}
	
	eTrap = document.getElementById('galleryTrap');
	eBorder = document.getElementById('galleryBorder');
	eContainer = document.getElementById('galleryContainer');
	
	if (eTrap!=null) {
		eTrap.style.left = (midX - (eTrap.offsetWidth / 2)) + 'px';
		eTrap.style.top = (midY - (eTrap.offsetHeight / 2)) + 'px';
	}

	if (eBorder!=null) {
		eBorder.style.left = (midX - (eBorder.offsetWidth / 2)) + 'px';
		eBorder.style.top = (midY - (eBorder.offsetHeight / 2)) + 'px';
	}

	if (eBorder!=null) {
		eContainer.style.left = (midX - (eContainer.offsetWidth / 2)) + 'px';
		eContainer.style.top = (midY - (eContainer.offsetHeight / 2)) + 'px';
	}
}

function galleryClose()
{
	eBody = parent.document.body;
	if (eBody==null) return;
	
	eTrap = parent.document.getElementById('galleryTrap');
	if (eTrap!=null) eBody.removeChild(eTrap);
	
	eBorder = parent.document.getElementById('galleryBorder');
	if (eBorder!=null) eBody.removeChild(eBorder);
	
	eContainer = parent.document.getElementById('galleryContainer');
	if (eContainer!=null) eBody.removeChild(eContainer);
}

function galleryOpenDocument(url, documentName)
{
	docWindow = window.open(url, '_blank');
	if (docWindow==null) return;
	
	//docWindow.document.title = documentName;
}

function galleryCrossFade(targetAlpha, timeStart, timeTotal)
{
	now = new Date();
	if (timeStart==null || timeStart==0)
		timeStart = now.getTime();
	timeCurrent = now.getTime() - timeStart;
	fadePosition = timeCurrent / timeTotal;
	
	if (timeCurrent > timeTotal) timeCurrent = timeTotal;
	eBorder = document.getElementById('galleryBorder');
	eContainer = parent.document.getElementById('galleryContainer');
	if (eBorder!=null) {
		opacity = fadePosition * targetAlpha;
		if (document.all) {
			eBorder.style.filter = "alpha(opacity=" + Math.round(opacity*100) + ")";
		}
		else {
			eBorder.style.opacity = opacity;
		}
		if (timeCurrent < timeTotal) {
			setTimeout("galleryCrossFade(" + targetAlpha + ", " + timeStart + ", " + timeTotal + ")", 30);
		}
		else {
			eContainer.style.visibility = 'visible';
		}
	};
}


