// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults

window.onload = reNice;
window.onresize = reNice;
window.onscroll = reNice;

//############################################################################
function init_fotoframe(){
  reNice();
  var imagewindow = document.getElementById("imagewindow");
  var fotoframe = document.getElementById("fotoframe");
  fotoframe.style.display = '';
  fotoframe.innerHTML = '<div style="position:relative; top:350px; left:0px;"><img src="/images/site_imgs/loading.gif"></div>';
  new Effect.BlindDown(imagewindow, {duration: 1.0});
}

//############################################################################
function js_show_info(obj,frame,orientation){
  var infoframe = document.getElementById(frame);
  var infoframe_width = parseInt(getComputedStyleForElement(infoframe,"width"));
  var infolink = document.getElementById("infolink");
  infoframe.style.top = findPosY(obj) - parseInt(getComputedStyleForElement(infoframe,"height")) + 20;
  infoframe.style.left = findPosX(obj) - infoframe_width + 70;
  if (orientation=='L') new Effect.Appear(infoframe, {duration: 1.0});
  if (orientation=='P') new Effect.Appear(infoframe, {duration: 1.0});
}

//###########################################################################
function animate(obj){
   var obj_item = document.getElementById(obj);
   //new Effect.Opacity(obj, { duration: 1.0, transition: Effect.Transitions.linear, from: 0.0, to: 1.0 });
   new Effect.BlindDown(obj, {duration: 1.0});
   obj_item.style.display='';
}

//###########################################################################
function resetWindowState(){
   var imagewindow = document.getElementById('imagewindow');
   var infoframe = document.getElementById('infoframe');

   infoframe.style.display = 'none';
   imagewindow.style.display = 'none';
}


/************************************************************************
   reNice handles window resizing and any additional window actions 
************************************************************************/
function reNice(){
return;
  var windowWidth = getWidth();

  var imagewindow = document.getElementById('imagewindow');
  imagewindow.style.top = getScrollY() + 5;

  var imagewindow_close = document.getElementById('imagewindow_close');
  imagewindow_close.style.left = parseInt(getComputedStyleForElement(imagewindow,"width")) - 50;  

  if (windowWidth < 800) return;

  var imagewindow_width = windowWidth - 30;
  imagewindow.style.width = imagewindow_width;
  imagewindow.style.left = (windowWidth - imagewindow_width) / 2 - 5;

  imagewindow_close.style.left = imagewindow_width - 50;  


  var fotoframe = document.getElementById('fotoframe');
  var fotoframe_width = imagewindow_width - 20;
  fotoframe.style.width = fotoframe_width;
  fotoframe.style.left = (imagewindow_width - fotoframe_width) / 2;
}


function getWidth() {
  if (parseInt(navigator.appVersion)>3) {
    if (navigator.appName=="Netscape") {
      return window.innerWidth;
    }
    if (navigator.appName.indexOf("Microsoft")!=-1) {
      return document.body.offsetWidth;
    }
  }

}

function getScrollY() {
  var scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
  } else if( document.documentElement &&
      ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
  }
  return scrOfY;
}


function getComputedStyleForElement (element, cssPropertyName) {
   if (element) {
     if (window.getComputedStyle) {
       return window.getComputedStyle(element,'').getPropertyValue(cssPropertyName.replace(/([A-Z])/g,"-$1").toLowerCase());
     }
     else if (element.currentStyle) {
       return element.currentStyle[cssPropertyName];
     }
     else {
       return null;
     }
   }
   else {
     return null;
   }
} 

function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}


//##################################################################//
function js_showimg(url){
owindow = window.open(url,'viewer','top=0,left=50,width=1000,height=750,align=center,valign=center,status=no,scrollbars=1,toolbar=no,menubar=no,location=no,resizable=yes');
owindow.focus()
}

function js_validate(){
  var proceed = true;
  var register_form = document.getElementById("register");
  var email = document.getElementById("email");
  var password = document.getElementById("password");
  var confirmpassword = document.getElementById("confirmpassword");
  message = "";

  if (check_email(email.value)==0) {
	proceed = false;
	message += "Email address is invalid.\n";
  } 
  if (password.value.length < 4) {
	proceed = false;
	message += "Password length is too short. Enter 4 characters or more.\n";
  }
  if (confirmpassword.value.length>0 && password.value != confirmpassword.value){
	proceed = false;
	message += "Confirmation password does not match password.\n";
  }
  if (!proceed) {
	alert(message);
	return false;
  }
  else { register_form.submit(); }
}

//#####################################
function check_email(email){
  if (email.length < 10) return 0
  return 1
}

//######################################
function menu_rollover(my_id,prefix){
	obj = document.getElementById('menu'+my_id);
	obj.src = "/images/site_imgs/"+prefix+"_"+my_id+".png";	
}
