/**
 * tabber
 */
function TabPageClick(tab){

  $("Tab_"+ tab).className = "tabberactive";

  var countElement = $("tabs").getElementsByTagName("li").length;

  for(i=1;  i <= countElement; i++ ){
    obj = $("Tab_"+ i);
    if(obj && i != tab){
      obj.className = "";
    }
  }
}

function updateTabContent(syUrl){
  $('box').innerHTML = '<p><img src="/images/indicator.gif" alt="Indicator"> Loading...<\/p>';
  var opt = {
    method: 'post'
  };
  new Ajax.Updater({success: 'box'},syUrl,opt);
}

/**
 * tooltip
 */

wmtt = null;

document.onmousemove = updateWMTT;

function updateWMTT(e) {
  if (wmtt != null) {
    x = (document.all) ? window.event.x + document.body.scrollLeft : e.pageX;
    y = (document.all) ? window.event.y + document.body.scrollTop  : e.pageY;
    wmtt.style.left = (x - 20) + "px";
    wmtt.style.top 	= (y + 20) + "px";
  }
}

function showWMTT(url) {
  var id = 'tooltip';
  var opt = {
    method: 'post',
    onSuccess: function(response){
      $('tooltip_content').innerHTML = response.responseText;
    }
  };
  new Ajax.Request(url,opt);
  wmtt = $(id);
  wmtt.style.display = "block"
}

function hideWMTT() {
  if (Element.visible('tooltip'))
  {
    $('tooltip').style.display = "none";
  }
}


/**
 * livesearch for question
 */

function chk_search(url)
{  
  var field_content = $('question_search').value;
  var d = field_content.length - 1;
  
  var opt = {
    method: 'post',
    postBody: 'search='+field_content,
    onSuccess: function(response){
      $('search_result').innerHTML = response.responseText;
    },
    onComplete: function(){
      new Effect.Appear('hidden_div', { duration: 2.0 });
      new Effect.Highlight('hidden_div');
  }
  };
  if(field_content.split(" ").length>2){
    new Ajax.Request(url,opt);
  }
}

/** 
 * scrollTo workaround - Effect.ScrollTo doesnt work!
 */

var MyEffect = { };
 
MyEffect.ScrollTo = Class.create(Effect.Base, {
  initialize: function(element) {
    this.element = $(element);
    this.start(arguments[1] || {});
    this.setup();
  },
  setup: function() { 
    Position.prepare();
    var offsets = Position.cumulativeOffset(this.element);
    if(this.options.offset) offsets[1] += this.options.offset;
    var max = window.innerHeight ? 
      window.height - window.innerHeight :
      document.body.scrollHeight - 
        (document.documentElement.clientHeight ? 
          document.documentElement.clientHeight : document.body.clientHeight);
    this.scrollStart = Position.deltaY;
    this.delta = (offsets[1] > max ? max : offsets[1]) - this.scrollStart;
  },
  update: function(position) {
    Position.prepare();
    window.scrollTo(Position.deltaX, 
      this.scrollStart + (position*this.delta));
  }
});
