// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults
actWN=0;

var tooltip=function(){
  var id = 'tt';
  var top = -18;
  var left = 13;
  var maxw = 300;
  var speed = 10;
  var timer = 20;
  var endalpha = 90;
  var alpha = 0;
  var tt,t,c,b,h;
  var ie = document.all ? true : false;
  return{
    show:function(v,w){
      if(tt == null){
        tt = document.createElement('div');
        tt.setAttribute('id',id);
        t = document.createElement('div');
        t.setAttribute('id',id + 'top');
        c = document.createElement('div');
        c.setAttribute('id',id + 'cont');
        b = document.createElement('div');
        b.setAttribute('id',id + 'bot');
        tt.appendChild(t);
        tt.appendChild(c);
        tt.appendChild(b);
        document.body.appendChild(tt);
        tt.style.opacity = 0;
        tt.style.filter = 'alpha(opacity=0)';
        document.onmousemove = this.pos;
      }
      tt.style.display = 'block';
      c.innerHTML = v;
      tt.style.width = w ? w + 'px' : 'auto';
      if(!w && ie){
        t.style.display = 'none';
        b.style.display = 'none';
        tt.style.width = tt.offsetWidth;
        t.style.display = 'block';
        b.style.display = 'block';
      }
      if(tt.offsetWidth > maxw){tt.style.width = maxw + 'px'}
      h = parseInt(tt.offsetHeight) + top;
      clearInterval(tt.timer);
      tt.timer = setInterval(function(){tooltip.fade(1)},timer);
    },
    pos:function(e){
      var u = ie ? event.clientY + document.documentElement.scrollTop : e.pageY;
      var l = ie ? event.clientX + document.documentElement.scrollLeft : e.pageX;
      tt.style.top = (u - h) + 'px';
      tt.style.left = (l + left) + 'px';
    },
    fade:function(d){
      var a = alpha;
      if((a != endalpha && d == 1) || (a != 0 && d == -1)){
        var i = speed;
        if(endalpha - a < speed && d == 1){
          i = endalpha - a;
        }else if(alpha < speed && d == -1){
          i = a;
        }
        alpha = a + (i * d);
        tt.style.opacity = alpha * .01;
        tt.style.filter = 'alpha(opacity=' + alpha + ')';
      }else{
        clearInterval(tt.timer);
        if(d == -1){tt.style.display = 'none'}
      }
    },
    hide:function(){
      clearInterval(tt.timer);
      tt.timer = setInterval(function(){tooltip.fade(-1)},timer);
    }
  };
}();
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function sw_over(owner,twin,lang){
var own=$(owner).src;
var twn=$(twin).src;
 $(owner).src=own.replace('0.gif','1.gif');
 $(twin).src=twn.replace("1.gif","0.gif");
}
function sw_out(owner,twin,lang){
	if(lang!=1){
		$('eng0').src=$('eng0').src.replace('0.gif','1.gif');
		$('rus0').src=$('rus0').src.replace('1.gif','0.gif');	 
		 }else{
		$('rus0').src=$('rus0').src.replace('0.gif','1.gif');
		$('eng0').src=$('eng0').src.replace('1.gif','0.gif');
	}
}
function lexilite(term){
if(term){
$('loader').style.display='';
new Ajax.Request('/lexicon/lexilite', { method:'post', parameters: {'term':term},
			onSuccess:function(transport){$('lexilite').innerHTML=transport.responseText;},
			onFailure:function(){$('lexilite').innerHTML='Sorry, something went wrong. We have been notified about it and work on the problem.';},
			onComplete:function(){$('LiteRow').style.display='';$('loader').style.display='none';$('tSearch').focus();$('lexbottom').style.display='';}
	  });
}
}
function closeLite(){
	$('LiteRow').style.display='none';
	$('lexbottom').style.display='none';
}
function aj(div, url,params){
  ajReq=new Ajax.Updater(div, url, {asynchronous:true, evalScripts:true, parameters: params, method:'post'});	
}