SplHint = Class.create();

SplHint.prototype = {
  initialize: function() {
    var objs = $('artykul').getElementsByTagName('a');
    for (var i = 0; i < objs.length; i++) {
      var el = $(objs[i]);

      if (el.hasClassName('podmiot') || el.hasClassName('spolka')  || el.hasClassName('waluta')) {

        var pos = Position.page(el);
        var hintobj = $(document.createElement('div'));
        hintobj.hide();
        hintobj.id =  el.className.replace(/podmiot /, "");
		hintobj.id =  el.className.replace(/spolka /, "");
		hintobj.id = 'o' + hintobj.id;
		
        hintobj.addClassName('spolkaEl');
        hintobj.innerHTML = '<br>proszę czekać<br>';
        $('artykul').appendChild(hintobj);
        Event.observe(el, 'mouseover', this.showHint.bindAsEventListener(this, el, hintobj, true, 'howerek', true));
        Event.observe(el, 'mouseout', this.hideHint.bindAsEventListener(this, el, hintobj, 'howerek', true));
        Event.observe(hintobj, 'mouseover', this.showHint.bindAsEventListener(this, el, hintobj, false, 'howerek', true));
        Event.observe(hintobj, 'mouseout', this.hideHint.bindAsEventListener(this, el, hintobj, 'howerek', true));
      } else if ((el.hasClassName('reklama1')) || (el.hasClassName('reklama2'))) {
        var hintobj = $(document.createElement('div'));
        var advType = (el.hasClassName('reklama1')) ? 1 : 2;
        var ho_t = $(document.createElement('h4'));
        ho_t.innerHTML = 'reklama';
        hintobj.hide();
        hintobj.addClassName('advHover_type'+advType);
        hintobj.appendChild(ho_t);
        hintobj.appendChild(el.getElementsByTagName('span')[0]);
        $('artykul').appendChild(hintobj);
        Event.observe(el, 'mouseover', this.showHint.bindAsEventListener(this, el, hintobj, false, 'advT'+advType+'h', false));
        Event.observe(el, 'mouseout', this.hideHint.bindAsEventListener(this, el, hintobj, 'advT'+advType+'h', false));
        Event.observe(hintobj, 'mouseover', this.showHint.bindAsEventListener(this, el, hintobj, false, 'advT'+advType+'h', false));
        Event.observe(hintobj, 'mouseout', this.hideHint.bindAsEventListener(this, el, hintobj, 'advT'+advType+'h', false));
      }
	  
	  
	  	  
    }
  },
  showHint: function(e, olink, ohint, getNew, hoverClass, applyAllStyles) {

      var pos = Position.cumulativeOffset(olink);
      if (applyAllStyles) {
        ohint.setStyle({
          background:'#fffff6',
          position:'absolute',
          border:'1px solid #d5d5d5',
          padding:'15px 15px 15px 5px',
          'z-index': '10',
          width: '280px',
          left: (pos[0] - 4) + 'px',
          top: (pos[1] + 19)+'px'
        });
      } else {
        ohint.setStyle({
          position:'absolute',
          border:'1px solid #d5d5d5',
          'z-index': '10',
          width: '280px',
          left: (pos[0] - 4) + 'px',
          top: (pos[1] + 19)+'px'
        });
      }
    ohint.show();
    if (getNew) {
      if (olink.hasClassName(hoverClass)) olink.removeClassName(hoverClass);
      var id = "";	  
	  if (olink.hasClassName('podmiot') || olink.hasClassName('spolka')) {
	  id = olink.className.replace(/podmiot /, "");
	  id = id.replace(/spolka /, "");
	  
	  new Ajax.Updater(ohint, '/aliasy/gospo/getDanePodmiotu.jsp', {
 		asynchronous: true,
        method: 'post',
        parameters: 'k='+id+'&t='+(new Date()).getTime()
      });
	  }

	   if (olink.hasClassName('waluta')) {
	  id = olink.className.replace(/waluta /, "");
	  
	  new Ajax.Updater(ohint, '/aliasy/gospo/getDaneWaluty.jsp', {
 		asynchronous: true,
        method: 'post',
        parameters: 'k='+id+'&t='+(new Date()).getTime()
      });
	  }	  

    }
    olink.addClassName(hoverClass);
  },
  hideHint: function(e, olink, ohint, hoverClass) {
    olink.removeClassName(hoverClass);
    ohint.hide();
  }
}

Event.observe(window,'load',function () {
  new SplHint();
});

