//http://www.astahost.com/info.php/sweet-titles_t11175.html
function addEvent(elm, evType, fn, useCapture) {
    if (elm.addEventListener) {
    elm.addEventListener(evType, fn, useCapture);
    return true;
    }
    else if (elm.attachEvent) {
    var r = elm.attachEvent('on' + evType, fn);
    EventCache.add(elm, evType, fn);
    return r;
    }
    else {
    elm['on' + evType] = fn;
    }
}
function getEventSrc(e) {
    if (!e) e = window.event;

    if (e.originalTarget)
    return e.originalTarget;
    else if (e.srcElement)
    return e.srcElement;
}
function addLoadEvent(func) {
var oldonload = window.onload;
    if (typeof window.onload != 'function') {
    window.onload = func;
    } else {
    window.onload =
    function() {
    oldonload();
    func();
    }
    }
}
var EventCache = function(){
    var listEvents = [];
    return {
    listEvents : listEvents,
    
    add : function(node, sEventName, fHandler, bCapture){
        listEvents.push(arguments);
    },
    
    flush : function(){
        var i, item;
        for(i = listEvents.length - 1; i >= 0; i = i - 1){
        item = listEvents[i];
        
        if(item[0].removeEventListener){
            item[0].removeEventListener(item[1], item[2], item[3]);
        };
        
        /* From this point on we need the event names to be prefixed with 'on" */
        if(item[1].substring(0, 2) != "on"){
            item[1] = "on" + item[1];
        };
        
        if(item[0].detachEvent){
            item[0].detachEvent(item[1], item[2]);
        };
        
        item[0][item[1]] = null;
        };
    }
    };
}();


addEvent(window,'unload',EventCache.flush, false);





/*
Sweet Titles (c) Creative Commons 2005
http://creativecommons.org/licenses/by-sa/2.5/
Author: Dustin Diaz | http://www.dustindiaz.com
*/
var toolTipLib = {
    xCord : 0,
    yCord : 0,
    obj : null,
    tipElements : ['img','a','span','area'],
    attachToolTipBehavior: function() {
    if ( !document.getElementById ||
        !document.createElement ||
        !document.getElementsByTagName ) {
        return;
    }
    var i,j;    
    if ( document.captureEvents ) { // FF
        addEvent(document,'mousemove',toolTipLib.updateXY,false); //iii mousemove
        document.captureEvents(Event.MOUSEMOVE);
    } else addEvent(document,'mouseover',toolTipLib.updateXY,false); // IE
    for ( i=0;i<toolTipLib.tipElements.length;i++ ) {
        var current = document.getElementsByTagName(toolTipLib.tipElements[i]);
        for ( j=0;j<current.length;j++ ) if (current[j].getAttribute('title') != null &&
current[j].getAttribute('title') != "") {
        addEvent(current[j],'mouseover',toolTipLib.tipOver,false);
        addEvent(current[j],'mouseout',toolTipLib.tipOut,false);
        current[j].setAttribute('tip',current[j].title);
        current[j].removeAttribute('title');
        current[j].removeAttribute('alt');
       }
    }
    },
    updateXY : function(e) {
    if ( document.captureEvents ) {
        toolTipLib.xCord = e.pageX;
        toolTipLib.yCord = e.pageY;
    } else if ( window.event.clientX ) {
        toolTipLib.xCord = window.event.clientX+document.documentElement.scrollLeft;
        toolTipLib.yCord = window.event.clientY+document.documentElement.scrollTop;
    }
    },
tipOut: function(e) {// OUT
    if ( window.tID ) {
        clearTimeout(tID);
    }
    if ( window.opacityID ) {
        clearTimeout(opacityID);
    }
    var l = getEventSrc(e);
    
    var div = document.getElementById('toolTip');
    if ( div ) {
        div.parentNode.removeChild(div);  
    }
},
    
checkNode : function(obj) { // CHECK
    var trueObj = obj;
    if ( trueObj.nodeName.toLowerCase() == 'a' || trueObj.nodeName.toLowerCase() == 'span' || trueObj.nodeName.toLowerCase() == 'img' || trueObj.nodeName.toLowerCase() == 'area') {
        return trueObj;
    } else {
        return trueObj.parentNode;
    }
    },
    tipOver : function(e) {   // OVER
    toolTipLib.obj = getEventSrc(e);
    tID = setTimeout("toolTipLib.tipShow()",50)
},
    
    

tipShow : function() {
    
    var scrX = Number(toolTipLib.xCord);
    var scrY = Number(toolTipLib.yCord);
    var tp = parseInt(scrY+15);
    var lt = parseInt(scrX+10);
    var anch = toolTipLib.checkNode(toolTipLib.obj);
    var addy = '';
    var access = '';


    var div = document.getElementById('toolTip');
    if ( div ) {
        div.parentNode.removeChild(div);  
    }

    var newDiv = document.createElement('div');
    newDiv.id = 'toolTip';
    document.getElementsByTagName('body')[0].appendChild(newDiv);
      ac = anch.getAttribute('accessKey');
  			if (ac) {
  			 if (ac.indexOf('maps.google.com')>=0) {
  			   newDiv.style.width = '506px'; // static google maps tooltip			   
			     this.maxOpacity = 99;
			     ac = ac+ '&key=ABQIAAAAW3qEvYZ4aY8hZKGg7WtX1xQ1I3m53hC4g-nVEvJPsXkf_invGxRjGEaBXem-FoWEQpm9fF8nLOwpkA';			     
			     //ac = ac.replace(/amp/g,'');
			     access = '<center><img src=\'http://'+ac+'\'></center>';
         } else {
  			   newDiv.style.width = '162px';			   
  			   this.maxOpacity = 99;
  			   access = '<center><img src=\'/files/'+ac+'\'></center>';
  			  }
			} else {
			     this.maxOpacity = 80;  
            attr=anch.getAttribute('tip');          
            if (!attr || attr.length<50) newDiv.style.width = null; 
                else newDiv.style.width = '180px';
        }     
       
    if ((anch.nodeName.toLowerCase() == 'img' ) && !anch.getAttribute('tip')) return; 		
    
    
    
		if (anch.nodeName.toLowerCase() == 'a' ) {		  
   
   /*
      if (anch.href.substring(0,19)!='http://www.efoto.lt' && anch.href.substring(0,10)!='javascript') {  // išorinis linkas
        //this.tip.style.width = '400px';
      var link = anch.href.substring(7);
      slen = link.length;
      if (link.charAt(slen-1)=='/') link=link.substr(0,slen-1); 
			addy = (link.length > 53 ? link.substring(0,51)+"..." : link);
			} else */ 
      addy = '';
		} else {
		  /*  if (anch.firstChild) {
          if (anch.firstChild.nodeValue.length>1) addy = anch.firstChild.nodeValue;
        } else if (anch.nodeValue && anch.nodeValue.length>1) addy = anch.nodeValue;*/ 
		}    
   
        
    newDiv.style.opacity = '.1';
    newDiv.innerHTML = "<p>"+anch.getAttribute('tip')+"<em>"+access+addy+"</em></p>";
    if ( parseInt(document.documentElement.clientWidth+document.documentElement.scrollLeft) < parseInt(newDiv.offsetWidth+lt) ) {
        newDiv.style.left = parseInt(lt-(newDiv.offsetWidth+10))+'px';
    } else {
        newDiv.style.left = lt+'px';
    }
    if ( parseInt(document.documentElement.clientHeight+document.documentElement.scrollTop) < parseInt(newDiv.offsetHeight+tp) ) {
        newDiv.style.top = parseInt(tp-(newDiv.offsetHeight+10))+'px';
    } else {
        newDiv.style.top = tp+'px';
    }
    toolTipLib.tipFade('toolTip',10);
    },
    tipFade: function(div,opac) {
    var obj = document.getElementById(div);
    if (!obj) return;
    var passed = parseInt(opac);
    var newOpac = parseInt(passed+15);
    if ( newOpac < 80 ) {
        obj.style.opacity = '.'+newOpac;
        obj.style.filter = "alpha(opacity:"+newOpac+")";
        opacityID = setTimeout("toolTipLib.tipFade('toolTip','"+newOpac+"')",50);
    }
    else {
        obj.style.opacity = '.'+this.maxOpacity;
			  obj.style.filter = "alpha(opacity:"+this.maxOpacity+")";
    }
    }
};
addEvent(window,'load',toolTipLib.attachToolTipBehavior,false);






// INLINE POPUPS

var mousexx = 0;
var mouseyx = 0;

document.onmousedown = function (e) {
  if (!e) e = window.event; // works on IE, but not NS (we rely on NS passing us the event)
  if (e)
  { 
    if (e.clientX || e.clientY)
    { // works on IE6,FF,Moz,Opera7
      mousexx = e.clientX;// + document.body.scrollLeft;
      mouseyy = e.clientY;// + document.body.scrollTop;
    } else if (e.pageX || e.pageY)
    { // this doesn't work on IE6!! (works on FF,Moz,Opera7)
      mousexx = e.pageX;
      mouseyy = e.pageY;
    }
  }
}

function mouseX() {
return mousexx + (document.documentElement.scrollLeft ?  document.documentElement.scrollLeft : document.body.scrollLeft);
}
function mouseY() {return mouseyy + (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);
}



// http://www.blakems.com/sandbox/inline-popups.html
function expandCollapse() {
  var element = document.getElementById(expandCollapse.arguments[0]);
  
 // alert(mousexx+'   '+mouseyy);
  element.style.top = mouseY()+22 + 'px';
  element.style.left = mouseX()-130 + 'px';

	for (var i=0; i<expandCollapse.arguments.length; i++) {
		var element = document.getElementById(expandCollapse.arguments[i]);
		element.style.display = (element.style.display == "none") ? "block" : "none";
	}	
}


function Browser() {

  var ua, s, i;

  this.isIE    = false;
  this.isNS    = false;
  this.version = null;

  ua = navigator.userAgent;

  s = "MSIE";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isIE = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  s = "Netscape6/";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  // Treat any other "Gecko" browser as NS 6.1.

  s = "Gecko";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = 6.1;
    return;
  }
}

var browser = new Browser();

// Global object to hold drag information.

var dragObj = new Object();
dragObj.zIndex = 1000;

/*
		var wrap2 = document.createElement('div');
		wrap2.id = 'overlay3';		
		with (wrap2.style) {
		  //backgroundImage = "url(overlay75.png)";
      background="#005500"; 
			display = 'block';
			position = 'fixed';
			top = '0px';
			left = '0px';
			zIndex = '50';
			width = '100%';
			height = '100%';			
		}
		if (browser.isIE) wrap2.style.position = 'absolute';
	*/	


function dragStart(event, id) {

  var el;
  var x, y;

  // If an element id was given, find it. Otherwise use the element being
  // clicked on.

  if (id)
    dragObj.elNode = document.getElementById(id);
  else {
    if (browser.isIE)
      dragObj.elNode = window.event.srcElement;
    if (browser.isNS)
      dragObj.elNode = event.target;

    // If this is a text node, use its parent element.

    if (dragObj.elNode.nodeType == 3)
      dragObj.elNode = dragObj.elNode.parentNode;
  }

  // Get cursor position with respect to the page.

  if (browser.isIE) {
    x = window.event.clientX + document.documentElement.scrollLeft
      + document.body.scrollLeft;
    y = window.event.clientY + document.documentElement.scrollTop
      + document.body.scrollTop;
  }
  if (browser.isNS) {
    x = event.clientX + window.scrollX;
    y = event.clientY + window.scrollY;
  }

  // Save starting positions of cursor and element.

  dragObj.cursorStartX = x;
  dragObj.cursorStartY = y;
  dragObj.elStartLeft  = parseInt(dragObj.elNode.style.left, 10);
  dragObj.elStartTop   = parseInt(dragObj.elNode.style.top,  10);

  if (isNaN(dragObj.elStartLeft)) dragObj.elStartLeft = 0;
  if (isNaN(dragObj.elStartTop))  dragObj.elStartTop  = 0;

  // Update element's z-index.

  dragObj.elNode.style.zIndex = ++dragObj.zIndex;

  // Capture mousemove and mouseup events on the page.

  if (browser.isIE) {
    document.attachEvent("onmousemove", dragGo);
    document.attachEvent("onmouseup",   dragStop);
    window.event.cancelBubble = true;
    window.event.returnValue = false;
  }
  if (browser.isNS) {
    document.addEventListener("mousemove", dragGo,   true);
    document.addEventListener("mouseup",   dragStop, true);
    event.preventDefault();
  }
}

function dragGo(event) {

  var x, y;

  // Get cursor position with respect to the page.

  if (browser.isIE) {
    x = window.event.clientX + document.documentElement.scrollLeft
      + document.body.scrollLeft;
    y = window.event.clientY + document.documentElement.scrollTop
      + document.body.scrollTop;
  }
  if (browser.isNS) {
    x = event.clientX + window.scrollX;
    y = event.clientY + window.scrollY;
  }

  // Move drag element by the same amount the cursor has moved.

  dragObj.elNode.style.left = (dragObj.elStartLeft + x - dragObj.cursorStartX) + "px";
  dragObj.elNode.style.top  = (dragObj.elStartTop  + y - dragObj.cursorStartY) + "px";

  if (browser.isIE) {
    window.event.cancelBubble = true;
    window.event.returnValue = false;
  }
  if (browser.isNS)
    event.preventDefault();
}

function dragStop(event) {

  // Stop capturing mousemove and mouseup events.

  if (browser.isIE) {
    document.detachEvent("onmousemove", dragGo);
    document.detachEvent("onmouseup",   dragStop);
  }
  if (browser.isNS) {
    document.removeEventListener("mousemove", dragGo,   true);
    document.removeEventListener("mouseup",   dragStop, true);
  }
}

