// JavaScript Document
function fieldContentFocus(id, value) {
	if (document.getElementById(id).value == value) {
		document.getElementById(id).value = '';
	}
}
function fieldContentBlur(id, value) {
	if (document.getElementById(id).value == '') {
		document.getElementById(id).value = value;
	}
}
function ChangeSort (SortBy, Session) {
    remoteLink('includes/asp/set_sort.asp?script=<%=strCurrentScript%>&sort='+SortBy+'&session='+Session, 'atol')
}
var addtoLayout=2;						// 0=Horizontal 1 row, 1=Horizontal 2 rows, 2=Vertical, 3=Vertical text only 
var addtoMethod=1;						// 0=direct link, 1=popup window
var AddURL = encodeURIComponent(document.location.href);	// this is the page's URL
var AddTitle = escape(document.title);	// this is the page title

function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}

function GrayBody(){
	var objBody = document.getElementsByTagName("body").item(0);
	var arrayPageSize = getPageSize();
	var id = "over";
	
	if(!document.getElementById(id)){
		var ov = document.createElement("div");
		
		ov.setAttribute('id',id);
		ov.className = 'overlay';
		ov.style.height = document.getElementById("container").clientHeight + 196 + "px";
		ov.style.width = arrayPageSize[0]+'px';
		ov.zindex = 1;
		objBody.appendChild(ov);
	}else{
		document.getElementById("over").style.display = 'block';
		document.getElementById("over").style.height = document.getElementById("container").clientHeight + 196 + "px";
		document.getElementById("over").style.width = arrayPageSize[0]+'px';
	}
}
function MoveDiv(Div, Direction){

	if (active == 1) {
	
		//get height of div that wraps thumbnails
		var divHeight = document.getElementById(Div).offsetHeight;
		
//		alert(divHeight);
		//calculate last scroll position
		var maxTop = ((0 - divHeight) +172);
		
		//original div position
		var origTopPositon = parseInt($(Div).getStyle('top'));
			
		//if 'next images' is clicked move the thumbnails up
		if (Direction == "up") {
			
			//caculate the new top value of the thumbnails
			var newTopPosition = parseInt($(Div).getStyle('top'))-172;
			
			//scroll images if there are any 
			if (origTopPositon > maxTop) {
				
				//set up tween
				tween = new Tween(document.getElementById('Thumbs').style,'top',Tween.backEaseOut,origTopPositon,newTopPosition,1,'px');
				
				//add listener to disable buttons if tween is in motion
				var listen = new Object();
				listen.onMotionStarted = function(){
					
					//disable buttons
					active = 0;
				}
				listen.onMotionFinished = function(){
					
					//activate buttons
					active = 1;
					
					//show/hide more and previous buttons
					document.getElementById('GalPrevious').style.display = "inline";

					if (parseInt(newTopPosition) < parseInt(maxTop)) {
						document.getElementById('GalNext').style.display = "none";
					}
				}
				
				//add listener to tween
				tween.addListener(listen);
				
				//start tween
				tween.start();
			}
			
		//if 'previous images' is clicked move the thumbnails down
		} else if (Direction == "dw") {
			
			//caculate the new top value of the thumbnails
			var newTopPosition = parseInt($(Div).getStyle('top'))+172;
			
			//scroll images if there are any 
			if (origTopPositon < 0) {
				
				//set up tween
				tween = new Tween(document.getElementById('Thumbs').style,'top',Tween.backEaseOut,origTopPositon,newTopPosition,1,'px');
				
				//add listener to disable buttons if tween is in motion
				var listen = new Object();
				listen.onMotionStarted = function(){
					
					//disable buttons
					active = 0;
				}
				listen.onMotionFinished = function(){
					
					//activate buttons
					active = 1;
					
					//show/hide more and previous buttons
					var topPosition = (parseInt($(Div).getStyle('top')));
					document.getElementById('GalNext').style.display = "inline";
					if (topPosition == 0) {
						document.getElementById('GalPrevious').style.display = "none";
					}
				}
				
				//add listener to tween
				tween.addListener(listen);
				
				//start tween
				tween.start();
			}
		}
	}
}

//function MoveDiv(Div, Direction, Limit){
//	if(Direction="up"){
//		var NewTop = parseInt($(Div).getStyle('top'))-172;
//		NewTop = NewTop + "px";
//		$(Div).setStyle({
//			'top': NewTop
//		});		
//	}else if(Direction="dw"){
//		var NewTop = parseInt($(Div).getStyle('top'))+172;
//		NewTop = NewTop + "px";
//		$(Div).setStyle({
//			'top': NewTop
//		});
//	}
//}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function popup(url)
{
	window.open(url,'popup','height=520,width=720');
	if (window.focus) {newwindow.focus()}
}

function GallerySwap(Text, ImageName){
	$('GalleryText').innerHTML="<b>"+Text+"</b>";
	$('mainPic').src=ImageName;
	$('mainPic').alt = Text;
}