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

function tabselect(tab) {
  var tablist = $('tabcontrol1').getElementsByTagName('li');
  var nodes = $A(tablist);
  var lClassType = tab.className.substring(0, tab.className.indexOf('-') );

  nodes.each(function(node){
    if (node.id == tab.id) {
      tab.className=lClassType+'-selected';
    } else {
      node.className=lClassType+'-unselected';
    };
  });
}

function paneselect(pane) {
  var panelist = $('panecontrol1').getElementsByTagName('li');
  var nodes = $A(panelist);

  nodes.each(function(node){
    if (node.id == pane.id) {
      pane.className='pane-selected';
    } else {
      node.className='pane-unselected';
    };
  });
}

function loadPane(pane, src) {
  if (pane.innerHTML=='' || pane.innerHTML=='<img alt="Wait" src="/images/indicator.gif" style="vertical-align:-3px" /> Loading...') {
    reloadPane(pane, src);
  }
}

function reloadPane(pane, src) {
  new Ajax.Updater(pane, src, {asynchronous:1, evalScripts:true, onLoading:function(request){pane.innerHTML='<img alt="Wait" src="/images/indicator.gif" style="vertical-align:-3px" /> Loading...'}})
}

function TB_ajax_init(){
  $j("a.thickbox-ajax").click(function(event){
    // stop default behaviour
    event.preventDefault();
    // remove click border
    this.blur();
  
    // get caption: either title or name attribute
    var caption = this.title || this.name || "";
    
    // get rel attribute for image groups
    var group = this.rel || false;
    
    // display the box for the elements href
    TB_show(caption, this.href, group);
  });
}

// show a hidden block
// toggles onclick to hide the block again
// can't find docs on this to determine if this is unecessary
function show_block(target, id) {
  new Effect.Appear(id)
  new Effect.Highlight(id, { queue: 'end'})
  target.onclick = function() {
    hide_block(target, id)
  }
  target.innerHTML = 'Close'
}

// related to show_block
function hide_block(target, id) {
  new Effect.Fade(id)
  target.onclick = function () {
    show_block(target, id)
  }
  target.innerHTML = 'Edit'
}

function change_image(parent_div, image_path) {
    image = new Image();
    image.src = image_path
    $(parent_div).innerHTML = "<img src=\"" + image_path + "\" />";
}
function clear_image(parent_div) {
    $(parent_div).innerHTML = "&nbsp;"
}
