

   //########################################################\\
   //#                                                        #
   //#                    MFYZ Ipucu v0.1                     #
   //#                                                        #
   //#////////////////////////////////////////////////////////#
   //#                                                        #
   //#   Author : Mehmet Fatih YILDIZ                         #
   //#   Contact : fatih@mfyz.com                             #
   //#                                                        #
   //#   License : Creative Commons 2.5                       #
   //#   Project Page :  http://www.mfyz.com/projeler&ipucu   #
   //#                                                        #
   ///#######################################################//


// degiskenler

  // global degiskenler
     var gecikme;
  // obje degiskenleri
     var obje, iW, iH, sonX, sonY, yX, yY, saX, saY;
  // mouse konumu
     var mX, mY;
  // browser degiskenleri
     var tarGW, tarGH, tarSL, tarST, tarSW, tarSH;
     var gSX, gSY;
 
  // ipucu
  var iAktif     = false;
  var toleransX  = 20;      // toleranslar
  var toleransY  = -5;
  var toleransXN = 10;
  var toleransYN = -3;


// browser tanimlamasi
var IE = ( document.all?true:false );


// olay yakalayici
if (!IE) document.captureEvents(Event.MOUSEMOVE)
document.onmousemove = mKoordinat;


// ipucu objesini degiskenlestirelim
var iObj = document.getElementById('ipucu');



// tarayici boyutlarini bulduralim
function tarayici(){

  tarGW = document.body.clientWidth;
  tarGH = document.body.clientHeight;

  tarSW = document.body.scrollWidth;
  tarSL = document.body.scrollLeft;
  tarSH = document.body.scrollHeight;
  tarST = document.body.scrollTop;

}


// mouse koordinat bulucu
function mKoordinat( e ) {

  if (IE) {
  
    mX = event.clientX + document.body.scrollLeft;
    mY = event.clientY + document.body.scrollTop;
    
  } else {  
  
    mX = e.pageX;
    mY = e.pageY;

  }

  // eger ipucu aciksa tasiyalim
  if( iAktif==true ){ iTasi(); } 

  return true;

}



// ipucu yazdirma fonksiyonu
function iYaz( yazi, stil ){

  var yazi, stil;

  // yazi icin degisimler
  yazi = yazi.replace(' ','&nbsp;','g');

  // yaziyi olusutralim
  iObj.innerHTML = '<table cellpadding="0" cellspacing="0" border="0"><tr><td><div class="' + stil + '">' + yazi + '</div></td></tr></table>';

}



// ipucu fonksiyonu
function ipucu( yazi, sure, stil ){

  var yazi, sure, ipucu;

  // eger default isteniyorsa  
  // arguman kontrolu
  if( arguments.length==3 ){
    // bos deger kontrolu
    if( sure == null ){ sure = 200; }
    if( stil == null ){ stil = 'ipucu'; }    
  }else if( arguments.length==2 ){ stil = 'ipucu';
  }else if( arguments.length==1 ){ sure = 200; stil = 'ipucu'; }

  // gosterelim
  gecikme = setTimeout("iGoster('" + yazi + "','" + stil + "');",sure);

}



// ipucu gosterim fonksiyonu
function iGoster( yazi, stil ){

  var yazi, stil;

  // ipucu yazdir
  iYaz(yazi,stil);
  
  // yazilmis ipucuna gore sabit boyutlar
  iW = iObj.offsetWidth;
  iH = iObj.offsetHeight;
  
  // ipucunu tasitalim
  iTasi();
  
  // objeyi gorunur yapalim.
  if( iObj.style ){ obje = iObj.style }else{ obje = iObj }
  obje.visibility = 'visible';
  
  // ipucu aktif
  iAktif = true;
  
  return true;

}



// ipucu tasima fonksiyonu
function iTasi(){

  // tarayici durumunu bulalim
  tarayici();
  
  // gorunur alanin sonu
  gSX = tarSL + tarGW;
  gSY = tarST + tarGH;
  
  // objenin yeni konumu
  yX = mX + toleransX;
  yY = mY + toleransY;
  
  // objenin sag alt kosesinin konumu
  saX = yX + iW;
  saY = yY + iH;
  
  // sag alt kosenin browser sinirlarini asmasi durumu
  
      // x ekseninde asma   ( saX > gSX )
      if( saX+5 > gSX ){ sonX = mX - iW - toleransXN; }else{ sonX = yX; }
      
      // y ekseninde asma   ( saY > gSY )
      if( saY+5 > gSY ){ sonY = mY - iH - toleransYN; }else{ sonY = yY; }

  // tasiyalim
  iObj.style.top  = sonY;
  iObj.style.left = sonX;

  return true;

}



// ipucu gizleme fonksiyonu
function iGizle(){

  // eger beklemede ise durduralim
  clearInterval(gecikme);

  // objeyi gizli yapalim.
  if( iObj.style ){ obje = iObj.style }else{ obje = iObj }
  obje.visibility = 'hidden';
  
  // ipucu deaktif isaretleyelim.
  iAktif = false;
  
  // gizliyken 0,0'a goturelim
  iObj.style.top  = -100;
  iObj.style.left = 0;
  
  // icerigini sifirlayalim
  iObj.innerHTML='';
  
  return true;

}

