// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults
function buttonStateHandler(button, enabled) {
 if (button == "prev-arrow") 
   $('prev-arrow').src = enabled ? "../images/arrow_left.gif" : "../images/arrow_left_disabled.gif"
 else 
   $('next-arrow').src = enabled ? "../images/arrow_right.gif" : "../images/arrow_right_disabled.gif"
}

function animHandler(carouselID, status, direction) {
  var region = $(carouselID).down(".carousel-clip-region")
  if (status == "before") {
    Effect.Fade(region, {to: 0.3, queue: { position:'end', scope: "carousel" }, duration: 0.2})
  }
  if (status == "after") {
    Effect.Fade(region, {to: 1, queue: { position:'end', scope: "carousel" }, duration: 0.2})
  }
}

function jemail(user, domain, suffix) {
   document.write('<a href="' + 'mailto:' + user + '@' + domain + '.' + suffix + '">' + user + '@' + domain + '.' + suffix + '</a>');
}

function reloadImage(response) {
  $('photo-viewer').innerHTML = response;
  Effect.Appear('photo',{duration: 0.3, queue: 'end'});
}

function popupImage(sURL) {
  window.open(sURL, "", "resizable=1, scrollbars=1,menubar=1,HEIGHT=550,WIDTH=800");
}

function replaceImage(response) {
  Effect.Appear('loading');
  cleaned_response = response.replace(/\r|\n/g, ' ');
  setTimeout("$('photo-viewer').innerHTML = cleaned_response;", 600);
}

function showImage() {
  Effect.Fade('loading', {duration: 0.2});
  setCustomOpacity(0, 'view');
  Effect.Appear('view')
  setTimeout("Effect.Appear('caption')", 300);
}

function setCustomOpacity(opacity, id) {
  opacity = (opacity == 100)?99.999:opacity;
  var el = document.getElementById(id).style;
  if (el.opacity != undefined) {
    el.opacity = (opacity / 100);
  } else if (el.MozOpacity != undefined) {
    el.MozOpacity = (opacity / 100);
  } else if (el.KhtmlOpacity != undefined) {
    el.KhtmlOpacity = (opacity / 100);
  } else if (el.filter != undefined) {
    if (opacity == 99.999) opacity = 100;
    el.filter = "alpha(opacity=" + opacity + ")";
  }
}

function fadeIn(id, startfade, endfade)	{
  timer = 0;
  if (startfade < endfade) {
    for (i = startfade; i <= endfade; i++) {
      setTimeout("setCustomOpacity(" + i + ",'" + id + "')", (timer * 8));
      timer++;
    }
  }
}

function fadeOut(id, startfade, endfade)	{
  timer = 0;
  if (endfade < startfade) {
    for (i = startfade; i >= endfade; i--) {
      setTimeout("setCustomOpacity(" + i + ",'" + id + "')", (timer * 8));
      timer++;
    }
  }
}
