scrollStarted = false;

function showFullPic(picId) {
	picIsDisplayed = true;
	/*document.getElementById('buldingFlash').style.visibility = 'hidden';*/
	document.getElementById('gallFullPicImgObj').src = picsArr[picId];
	
	var gallNavStr = '<a href="javascript:closeFullPic();" class="closeLink">x</a>';
	
	if (picId > 0) {
		gallNavStr += '<a href="javascript:showFullPic('+(picId-1)+')" class="prevLink"><strong>&lt;</strong></a>';
	}
	
	if (picId < picsArr.length - 1 ) {
		gallNavStr += '<a href="javascript:showFullPic('+(picId+1)+')" class="nextLink"><strong>&gt;</strong></a>';
	}

	document.getElementById('gallFullPicNav').innerHTML = gallNavStr;
	positionPicFrame();
	
	windowAddFunction('onresize',positionPicFrame);
	windowAddFunction('onscroll',positionPicFrame);
}

function closeFullPic() {
	document.getElementById('galFullPicCnt').style.display = 'none';
	picIsDisplayed = false;
	/*document.getElementById('buldingFlash').style.visibility = 'visible';*/

	fogOfWarHide();

	windowRemoveFunction('onscroll');
	windowRemoveFunction('onresize');
}

function fogOfWarShow() {
	windowSize = getWindowSize();
	siteWidth = document.getElementById('siteContents').offsetWidth;
	
	fogDiv = document.getElementById('fogOfWar');
	fogDiv.style.height = document.getElementById('siteBody').offsetHeight+'px';
	
	
	if (windowSize[0] < siteWidth ) {
		fogDiv.style.width = siteWidth+'px';
	} else {
		fogDiv.style.width = '100%';
	}

	fogDiv.style.display = 'block';
} 
	
function fogOfWarHide() {
	fogDiv.style.height = '10px';
	fogDiv.style.display = 'none';		
}

function positionPicFrame() {
	fogOfWarShow();
	document.getElementById('galFullPicCnt').style.display = 'block';

	picContainer = document.getElementById('galFullPicInPlaceHolder');
	
	windowSize = getWindowSize();
	scrollOffset = getScrollOffset();
	//alert(windowSize[1]);

	if (windowSize[1] > 720) {
		picContainerTopOffset = ((windowSize[1] - 650) / 2 )- 53;
		if (!scrollStarted) {
			windowAddFunction('onscroll',positionPicFrame);
			scrollStarted = true;
		}
	} else {
		windowRemoveFunction('onscroll');
		scrollStarted = false;
		picContainerTopOffset = 0;
	}
	
	picContainer.style.top = (scrollOffset[1]+picContainerTopOffset)+'px';

}

function windowAddFunction(onEvent,f) {
	if (onEvent == 'onload') {
		var prev = window.onload;
		window.onload = function() {
				if(prev)prev(); f(); 
			}
	}	
	if (onEvent == 'onresize') {
		var prev = window.onresize;
		window.onresize = function() {
			if(prev)prev(); f(); 
		}
	}
	if (onEvent == 'onscroll') {
		var prev = window.onscroll;
		window.onscroll = function() {
			if(prev)prev(); f(); 
		}
	}
}

function windowRemoveFunction(onEvent) {
	if (onEvent == 'onscroll') {
		window.onscroll = null
	}
	if (onEvent == 'onresize') {
		window.onresize = null;
	}
}

function getWindowSize() {
	var myWidth = 0, myHeight = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	}
	return [ myWidth, myHeight ];
}

function getScrollOffset() {
	var scrOfX = 0, scrOfY = 0;
	if( typeof( window.pageYOffset ) == 'number' ) {
		//Netscape compliant
		scrOfY = window.pageYOffset;
		scrOfX = window.pageXOffset;
	} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
		//DOM compliant
		scrOfY = document.body.scrollTop;
		scrOfX = document.body.scrollLeft;
	} else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
		//IE6 standards compliant mode
		scrOfY = document.documentElement.scrollTop;
		scrOfX = document.documentElement.scrollLeft;
	}
	return [scrOfX,scrOfY ];
}

function fixFlashHeight() {
	windowSize = getWindowSize();
	if (windowSize[1] > 645 ) {
		document.getElementById('flashContIndex').style.height = (windowSize[1] - 78)+'px';
	}
}

function initGal() {
	galCont = document.getElementById('gallPicsList');
	linksArr = galCont.getElementsByTagName('a');
	picsArr = new Array();
	var count = 0;
	
	for (x in linksArr) {
		if (linksArr[x].href != undefined) {
			picsArr[count] = linksArr[x].href;
			imgPath = linksArr[x].href
			linksArr[x].href = 'javascript:showFullPic('+count+');';
			count++;
		}
	}
}

var picIsDisplayed = false;
