//this javascript file contains the core of the script
//please do not change anything, especially if you're unsure of what you see

//the function d is used to save up disk space
//it returns the same thing as document.getElementById would return
function d(object)
{
return document.getElementById(object);
}

//b_hint variables
//this variables are used by the b_hint core
var b_hint_x; //this represents the width of all the tooltip (including the margins)
var b_hint_y; //this represents the height of all the tooltip
var b_hint_document_x; //this represents the width of the inner window (more precisely, the width of what you actually see)
var b_hint_document_y; //this represents the height of the inner window
var b_hint_is_on=0; //this indicates if b_hint is visible or not
var b_hint_active=0; //this indicates if b_hint may start (more precisely, it indicates if the page is still loading)
var b_hint_folder="lib_b/"; //the path to the "b_hint" folder (must include "/" at the end)
var b_hint_theme="b_hint_standard";

//this sets the doc_elem as the document body tag
if (document.documentElement) doc_elem=document.documentElement;
else doc_elem=document.body;

//move this to the theme script
  //b_hint_margins
  var b_hint_left=6;
  var b_hint_top=6;
  var b_hint_right=12;
  var b_hint_bottom=13;
  //b_hint_preloader
  var b_hint_preloader_width=30;
  var b_hint_preloader_height=30;


//b_hint images preloader
if (document.images)
  {
  b_hint_Image1= new Image();
  b_hint_Image1.src = b_hint_folder+"b_hint/themes/"+b_hint_theme+"/b_hint_br.png";
  b_hint_Image2= new Image();
  b_hint_Image2.src = b_hint_folder+"b_hint/themes/"+b_hint_theme+"/b_hint_bm.png";
  b_hint_Image3= new Image();
  b_hint_Image3.src = b_hint_folder+"b_hint/themes/"+b_hint_theme+"/b_hint_bl.png";
  b_hint_Image4= new Image();
  b_hint_Image4.src = b_hint_folder+"b_hint/themes/"+b_hint_theme+"/b_hint_mr.png";
  b_hint_Image5= new Image();
  b_hint_Image5.src = b_hint_folder+"b_hint/themes/"+b_hint_theme+"/b_hint_ml.png";
  b_hint_Image6= new Image();
  b_hint_Image6.src = b_hint_folder+"b_hint/themes/"+b_hint_theme+"/b_hint_ur.png";
  b_hint_Image7= new Image();
  b_hint_Image7.src = b_hint_folder+"b_hint/themes/"+b_hint_theme+"/b_hint_um.png";
  b_hint_Image8= new Image();
  b_hint_Image8.src = b_hint_folder+"b_hint/themes/"+b_hint_theme+"/b_hint_ul.png";
  b_hint_Image9= new Image();
  b_hint_Image9.src = b_hint_folder+"b_hint/themes/"+b_hint_theme+"/preloader.swf";
  }

//b_hint html code (is inserted dynamically when the page is fully loaded)
//it represents the needed html code to display b_hint
b_hint_html_code=
  '\
  <div id="b_hint" style="display:none; position:absolute; z-index:35000; left:0px; top:0px;">\
    <img id="b_hint_m" style="position:absolute; z-index:4; left:'+b_hint_left+'px; top:'+b_hint_top+'px;" src="" alt="" />\
    <img id="b_hint_ul" style="position:absolute; left: 0px; top: 0px; width:'+b_hint_left+'px; height:'+b_hint_top+'px;" src="'+b_hint_folder+'b_hint/themes/'+b_hint_theme+'/b_hint_ul.png" alt="" />\
    <img id="b_hint_um" style="position:absolute; top: 0px; left:'+b_hint_left+'px; height:'+b_hint_top+'px;" src="'+b_hint_folder+'b_hint/themes/'+b_hint_theme+'/b_hint_um.png" alt="" />\
    <img id="b_hint_ur" style="position:absolute; right: 0px; top: 0px; width:'+b_hint_right+'px; height:'+b_hint_top+'px;" src="'+b_hint_folder+'b_hint/themes/'+b_hint_theme+'/b_hint_ur.png" alt="" />\
    <img id="b_hint_ml" style="position:absolute; left: 0px; top:'+b_hint_top+'px; width:'+b_hint_left+'px;" src="'+b_hint_folder+'b_hint/themes/'+b_hint_theme+'/b_hint_ml.png" alt="" />\
    <img id="b_hint_mr" style="position:absolute; right: 0px; top:'+b_hint_top+'px; width:'+b_hint_right+'px;" src="'+b_hint_folder+'b_hint/themes/'+b_hint_theme+'/b_hint_mr.png" alt="" />\
    <img id="b_hint_bl" style="position:absolute; left: 0px; bottom: 0px; width:'+b_hint_left+'px; height:'+b_hint_bottom+'px;" src="'+b_hint_folder+'b_hint/themes/'+b_hint_theme+'/b_hint_bl.png" alt="" />\
    <img id="b_hint_bm" style="position:absolute; bottom: 0px; height:'+b_hint_bottom+'px; left:'+b_hint_left+'px;" src="'+b_hint_folder+'b_hint/themes/'+b_hint_theme+'/b_hint_bm.png" alt="" />\
    <img id="b_hint_br" style="position:absolute; right: 0px; bottom: 0px; width:'+b_hint_right+'px; height:'+b_hint_bottom+'px;" src="'+b_hint_folder+'b_hint/themes/'+b_hint_theme+'/b_hint_br.png" alt="" />\
    <div id="b_hint_mp" style="position:absolute; z-index:3; width:'+b_hint_preloader_width+'px; height:'+b_hint_preloader_height+'px;">\
      <embed style="position:absolute; left:0px; top:0px; width:'+b_hint_preloader_width+'px; height:'+b_hint_preloader_height+'px;" src="'+b_hint_folder+'b_hint/themes/'+b_hint_theme+'/preloader.swf" />\
    </div>\
    <div id="b_hint_mv" style="position:absolute; z-index:2; background:#FFFFFF; left:'+b_hint_left+'px; top:'+b_hint_top+'px;"></div>\
  </div>\
  ';
  
//b_hint event atacher
function p_addEvent(element, eventType, handler, triggerInside) // adds an event 
{
if(triggerInside==undefined)
  {
  if (eventType!="mouseover" && eventType!="mouseout") triggerInside=true;
  else triggerInside=false;
  }
if (element.addEventListener)
  {
  element.addEventListener(eventType, function(event)
    {
    if (triggerInside || (!triggerInside && !p_descendantTest(element, event.relatedTarget)))
    handler(event);
    }, false);
  }
else if (element.attachEvent)
  {
  element.attachEvent("on"+eventType, function()
    {
    if (triggerInside || (!triggerInside && !p_descendantTest(element, ((eventType=="mouseover")?window.event.fromElement:window.event.toElement))))
    handler(window.event);
    });
  }
}

//b_hint is available only after everything has been loaded
p_addEvent(window, "load", function()
  {
  //load theme js AJAX
  
  if (document.body.insertAdjacentHTML) document.body.insertAdjacentHTML('beforeEnd',b_hint_html_code);
  else
    {
    var b_hint_temp_document_range = document.body.ownerDocument.createRange();
		b_hint_temp_document_range.setStartBefore(document.body);
		var b_hint_html_code_parsed = b_hint_temp_document_range.createContextualFragment(b_hint_html_code);
		document.body.appendChild(b_hint_html_code_parsed);
    }
  
  b_hint_active=1;
  b_png();
  });

//dom tree functions
function p_descendantTest(suspectedParent, suspectedChild) //function that tests if suspectedChild is a descendent of suspectedParent (not necesarily direct descendent)
{
if (!suspectedChild || suspectedChild==document.body || suspectedChild==document.documentElement) return false;
else
  {
  if (suspectedParent==suspectedChild) return true;
  else return p_descendantTest(suspectedParent, suspectedChild.parentNode);
  }
}

//b_hint functions
function b_hint_on(imagine, x, y, eveniment)
{
if (!b_hint_is_on && b_hint_active)
  {
  d("b_hint_m").style.display="none";
  d("b_hint_m").style.zIndex=1;
  d("b_hint_mv").style.zIndex=2;
  d("b_hint_mp").style.display="block";

  b_hint_show_content=function()
    {
    d("b_hint_m").style.display="block";
    d("b_hint_mp").style.display="none";
    d("b_hint_m").style.zIndex=2;
    d("b_hint_mv").style.zIndex=1;
    d("b_hint_m").style.width=x+"px";
    d("b_hint_m").style.height=y+"px";
    }
  
  if (window.opera || (navigator.vendor && navigator.vendor.indexOf("Apple")>-1))
    {
    b_hint_loaded_interval=setInterval(function()
      {
      if (d("b_hint_m").complete)
        {
        clearTimeout(b_hint_loaded_interval);
        b_hint_show_content();
        }
      },100);
    }
  else d("b_hint_m").onload=function(){b_hint_show_content()};
  
  b_hint_is_on=1;
  b_hint_x=x+b_hint_left+b_hint_right;
  b_hint_y=y+b_hint_bottom+b_hint_top;
  d("b_hint").style.width=(b_hint_x)+"px";
  d("b_hint").style.height=(b_hint_y)+"px";
  d("b_hint_um").style.width=x+"px";
  d("b_hint_bm").style.width=x+"px";
  d("b_hint_ml").style.height=y+"px";
  d("b_hint_mr").style.height=y+"px";
  d("b_hint_mv").style.width=x+"px";
  d("b_hint_mv").style.height=y+"px";
  
  d("b_hint_mp").style.left=((x-b_hint_preloader_width)/2)+"px";
  d("b_hint_mp").style.top=((y-b_hint_preloader_height)/2)+"px";
  
  d("b_hint_m").src=imagine;
  
  if (eveniment) b_hint_move(eveniment)
  d("b_hint").style.display="block";
  }
}

function b_hint_move(eveniment)
{
if (b_hint_is_on && b_hint_active)
  {
  // get the inner width and height of the window
  
  if (window.innerWidth)
    {
  	b_hint_document_x = window.innerWidth;
    b_hint_document_y = window.innerHeight;
    }
  else if (document.documentElement && document.documentElement.clientWidth)
    {
  	b_hint_document_x = document.documentElement.clientWidth;
    b_hint_document_y = document.documentElement.clientHeight;
    }
  else if (document.body)
    {
	  b_hint_document_x = document.body.clientWidth;
    b_hint_document_y = document.body.clientHeight;
    }
  
  //browsers diffrences in the scrolling offset are treated below
  if (window.pageYOffset)
	  scrolltop=window.pageYOffset; // opera, mozilla, firefox, safari and older netscape browsers support this
  else if (document.documentElement && document.documentElement.scrollTop)
	  scrolltop=document.documentElement.scrollTop //internet explorer's scroll offset is found here when using a doctype
  else if (document.body)
	  scrolltop=document.body.scrollTop // standards supporting browsers should use this (not allways true though)
    
  var b_hint_mouse_x, b_hint_mouse_y;
  if(eveniment)
    {
    if( typeof( eveniment.pageX ) == 'number' )
      {
      b_hint_mouse_x = eveniment.pageX;
      b_hint_mouse_y = eveniment.pageY;
      }
    else
      {
      b_hint_mouse_x = eveniment.clientX;
      b_hint_mouse_y = eveniment.clientY;
      }
    }
  else
    {
    eveniment = window.event;
    b_hint_mouse_x = eveniment.clientX;
    b_hint_mouse_y = eveniment.clientY+scrolltop;
    }
  
  b_hint_y_offset=scrolltop + ((b_hint_mouse_y-scrolltop) * (b_hint_document_y - b_hint_y)) / b_hint_document_y;
  b_hint_x_offset=b_hint_mouse_x;
  
  if (b_hint_mouse_x + 30 < b_hint_document_x-b_hint_x) b_hint_x_offset+=15;
  else b_hint_x_offset-=15+b_hint_x;

  b_hint_x_offset=Math.floor(b_hint_x_offset);
  b_hint_y_offset=Math.floor(b_hint_y_offset);
  
  d("b_hint").style.left=(b_hint_x_offset)+"px";
  d("b_hint").style.top=(b_hint_y_offset)+"px";
  }
}

function b_hint_off()
{
if (b_hint_active)
  {
  b_hint_is_on=0;
  d("b_hint").style.display="none";
  }
}

document.onmousemove=b_hint_move;


function b_png()
{
var arVersion = navigator.appVersion.split("MSIE")
var version = parseFloat(arVersion[1])
if ((version >= 5.5) && (document.body.filters)) 
  {
  for(var i=0; i<document.images.length; i++)
    {
    var img = document.images[i]
    var imgName = img.src.toUpperCase()
    if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
      {
        var imgID = (img.id) ? "id='" + img.id + "' " : ""
        var imgClass = "class='" + img.className+"' ";
        var imgStyle = img.style.cssText 
        var strNewHTML = "<span " + imgID + imgClass + " style=\"overflow:hidden; filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'" + img.src + "\', sizingMethod='scale'); margin:0px; padding:0px; "+imgStyle+"\"></span>";
        img.outerHTML = strNewHTML
        i = i-1
      }
    }
  }
}

