﻿// JavaScript Document
function Expand(menu) {
	element = document.getElementById("menu"+menu).style;
	cPos = element.marginLeft.replace('px','');
	if (cPos > 0) {
	  newPos = cPos-2
	  if (newPos < 0) { newPos = 0 }
	  element.marginLeft = (newPos)+'px'
	  setTimeout('Expand(\''+menu+'\')', 1)
	}
	else {
	  if (menu != 'Contact') {
		document.getElementById("navigation").style.display = 'block';		
		PrintPhoto();
	  }
	}		 
}

curPhoto = 'load';
fade = 0;
TimerID = '';
function PrintPhoto(action) {

  if (curPhoto == 'load') {
	  curPhoto = 0;
	  fade = 1;
} else if (action == 'next') {
	  curPhoto = curPhoto+1;
  } else {
      curPhoto = curPhoto-1;
  }
  if (curPhoto >= Photos.length) { curPhoto = 0 }
  if (curPhoto < 0) { curPhoto = Photos.length-1 }
  

  var imageContainer = document.getElementById("imgContainer")
  var images = document.getElementById("images")
  var path = "/photos/" + area + "/"
  
  newDiv = document.createElement("div")					      // make div
  newDiv.setAttribute("id", "images");

  if (fade == 1) {
	newDiv.setAttribute("class", "fade");
	newDiv.setAttribute("classname", "fade");	
  }

  newImg = document.createElement("img")						  // make img 1
  newImg.setAttribute("src",path + Photos[curPhoto][0])
  
  newDiv.appendChild(newImg)									  // add img to div

  if (Photos[curPhoto][1] != '') {
    newImg = document.createElement("img")						  // make img 2
    newImg.setAttribute("src",path + Photos[curPhoto][1])
    newDiv.appendChild(newImg)									  // add img to div	  
  }
  
  imageContainer.removeChild(images)
  imageContainer.appendChild(newDiv)

  if (TimerID != '') {
	 window.clearTimeout(TimerID)
  }
  FadeIn(1);
}

function FadeIn(val) {

	element = document.getElementById("images").style;
    if (val <= 100) {
		element.filter = 'alpha(opacity='+val+')';
		element.opacity = val/100;
		TimerID = setTimeout('FadeIn('+(val+1)+')', 1);		
	} 
}
function FadeInFront(val) {
	element = document.getElementById("images").style;
    if (val <= 100) {
		element.filter = 'alpha(opacity='+val+')';
		element.opacity = val/100;
		TimerID = setTimeout('FadeInFront('+(val+1)+')', 30);		
	} 
}

function preload(area) {
 if (document.images)
 {
  loadImg = new Image();
  loadImg.src='http://' + domain + '/inc/'+area+'_next.gif';
  loadImg = new Image();
  loadImg.src='http://' + domain + '/inc/'+area+'_prev.gif';
  for (x=0; x<Photos.length;x++) {
    for (xx=0;xx<=1;xx++) {
	  if (Photos[x][xx] != '') {
		  loadImg = new Image();
		  loadImg.src='http://' + domain + '/photos/'+area+'/'+Photos[x][xx];
	  }
	}
  }
 }
}

// elementwidth functions used for IE bug with element getting smaller for each sort
width = 0;

function getElementWidth(element) {
	if (width == 0) {
	  width = element.offsetWidth;
	}
}
function setElementWidth(element) {
	document.getElementById(element.name).focus()
	document.getElementById(element.name).style.width = width+'px';
}
function moveup(list) {
	//getElementWidth(list);
	var daflag = false
	for (var i = 0; i <= list.options.length-1; i++) {
		if (!list[i].selected) {
			daflag = true
		}
		if (list[i].selected && daflag) {
			list.insertBefore(list[i],list[i-1])
		}
	}
	//setElementWidth(list);
}
   
function movedown(list) {
	//getElementWidth(list);
	var daflag = false
	for (var i = list.options.length-1; i >= 0; i--) {
		if (!list[i].selected) {
			daflag = true
		}
		if (list[i].selected && daflag) {
			list.insertBefore(list[i],list[i+2])
		}
	}
	//setElementWidth(list);
}

function submitForm() {
 	var list = document.form.list; 
	var theList = "&"; 
	var count = 0;
	for (i = 0; i <= list.options.length-1; i++) {
		count = count + 1
		theList += "ID" + list.options[i].value + "=" + count;
		if (i != list.options.length-1) theList += "&"; 
	} 
	location.href = document.forms['form'].action + theList; 
	return false;
}
