$(document).ready(function(){
  
  Cufon.replace('h1, .cufon1', {
    fontFamily: 'Rabiohead'
  });
  Cufon.replace('h2, .cufon2', {
    fontFamily: 'Lacuna Regular',
    hover: true
  });

  $('#banner .image').cycle();

  slide("#quick_links", 15, 0, 150, .8);
  slide("#sitemap", 15, 0, 150, .8);

  var home_scroll = null;
  $('#banner .pad_paper .down').hover(function(){
    detail=$('#banner .pad_paper .detail');
    home_scroll = setInterval("scroll_y(detail, 2)", 10);
  },function(){
    clearInterval(home_scroll);
  });

  $('#banner .pad_paper .up').hover(function(){
    detail=$('#banner .pad_paper .detail');
    home_scroll = setInterval("scroll_y(detail, -2)", 10);
  },function(){
    clearInterval(home_scroll);
  });

  $('#banner .pad_paper .controls a').click(function(){
    return false;
  });

  $(".colorbox").colorbox();
  
  $("#site_search").click(function(){
    val = $(this).val();
    t = $(this).attr("title")
    if(val==t){
      $(this).val("");
      $(this).css("color","#000000");
    }
  });
  $("#site_search").blur(function(){
    val = $(this).val();
    t = $(this).attr("title")
    if(val==""){
      $(this).val(t);
      $(this).css("color","#1E64AA")
    }
  });
  
  $("#accordion").accordion({autoHeight: false, active: false});
});


function scroll_y(obj, increment){
  if(obj.css("height")!=obj.scrollTop()){
    y = obj.scrollTop();
    obj.scrollTop(y+increment);
  }
}

function flash_background(obj, normal_color, middle_color){
  duration = 200
  obj.animate( {
    backgroundColor: middle_color
  }, duration).animate( {
    backgroundColor: normal_color
  }, duration);
}

function toggle_field(self,activate,deactivate,no_clean){
  deactivate_field(self,deactivate,no_clean);
  activate_field(self,activate,no_clean);
}

function activate_field(self,objs,no_clean){
  if(defined(no_clean) && no_clean==true){
  //do nothing
  }else{
    clean_sibling_fields(self);
  }

  for(i=0;i<objs.length;i++){
    $(objs[i]).removeAttr("disabled");
    $(objs[i]).parent('li').slideDown();
  }
  
}

function deactivate_field(self,objs,no_clean){
  if(defined(no_clean) && no_clean==true){
  //do nothing
  }else{
    clean_sibling_fields(self);
  }
  
  for(i=0;i<objs.length;i++){
    $(objs[i]).attr("disabled","disabled");
    $(objs[i]).parent('li').slideUp();
  }
}

function clean_sibling_fields(self){
  h=$(self).parent().nextAll("li");
  h.slideUp();
  h.children("input").each(function(){
    $(this).attr("disabled","disabled");
    $(this).removeAttr("selected");
    $(this).removeAttr("checked");
  });
  h.children("textarea").each(function(){
    $(this).attr("disabled","disabled");
    $(this).html("");
  });
  h.children("select").each(function(){
    $(this).attr("disabled","disabled");
    $(this).removeAttr("selected");
  });
}

function defined(variable){
  if(typeof(variable)=="undefined"){
    return false;
  }else {
    return true;
  }
}

function combine_fields(values){
  if($(values[0]).attr("disabled")!=true){
    b = "";
    for(i=0;i<values.length;i++){
      b+= ($(values[i]).val()+" ");
      $(values[i]).attr("disabled","disabled");
    }
    $(values[0]).val(b);
    $(values[0]).removeAttr("disabled");
    return true;
  }
  return false;
}

