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

function go_to_pic(pic_id) {
  c_id = $('current_pic').value;
  if(pic_id == c_id) return false;
  _current_pic = $("pic_"+c_id);
  new Effect.Fade(_current_pic);
  new Effect.Appear("pic_"+pic_id);
  move_class('pic_select_'+c_id,'pic_select_'+pic_id,"current");
  Element.removeClassName('prev_pic','dim');
  Element.removeClassName('next_pic','dim');
  if(pic_id == 0) Element.addClassName('prev_pic','dim');
  if(pic_id == $('num_pics').value-1) Element.addClassName('next_pic','dim');
  $('current_pic').value = pic_id;
}
function move_class(from,to,class_name){
  Element.removeClassName(from,class_name);
  Element.addClassName(to,class_name);
}

function next_pic(e){
  if(Element.hasClassName(e,'dim')) return false;
  go_to_pic($('current_pic').value-0+1);
}
function prev_pic(e){
  if(Element.hasClassName(e,'dim')) return false;
  go_to_pic($('current_pic').value-1);
}

function next_t(e)
{
  if(Element.hasClassName(e,'dim')) return false;
  new Effect.Fade('testimonial_'+get_current_t());
  new Effect.Appear('testimonial_'+(get_current_t()+1));
  Element.removeClassName('prev_t','dim');
  if(get_current_t()+1 == get_num_t()-1 ) Element.addClassName('next_t','dim');
  set_current_t(get_current_t()+1);
}
function prev_t(e)
{
  if(Element.hasClassName(e,'dim')) return false;
  new Effect.Fade('testimonial_'+get_current_t());
  new Effect.Appear('testimonial_'+(get_current_t()-1));
  Element.removeClassName('next_t','dim');
  if(get_current_t()-1 == get_num_t()-1 ) Element.addClassName('prev_t','dim');
  set_current_t(get_current_t()-1);
}

function get_num_t() {
  return $('num_t').innerHTML - 0;
}
function get_current_t() {
  return $('current_t').innerHTML - 1;
}
function set_current_t(value) {
  $('current_t').innerHTML = value + 1; 
}


window.onload = function() {
  $('current_pic').value = 0; //Firefox oddness
}