// JavaScript Document

//* Přidání vstupního textu do rozšířeného vyhledávání *//
var num_of_lines = 0;  

function plus( element )
{  
  // zvýšít globální proměnnou počtu řádků
  num_of_lines ++;
  
  // najít element, do kterého se budou přidávat prvky
  var x = document.getElementById( element );
  
  // vztvořit potřebné prvky a nastavit jejich artibury
  var text = document.createTextNode('Klíčové slovo: ');  
  var input = document.createElement('input');
  input.setAttribute('type','text');
  input.setAttribute('class','text');
  input.setAttribute('name','keyword[]');
  //input.setAtrtibute('style','width:120px;');
  var br = document.createElement('br');

  // vztvořit span kterým se obalí text a input
  var p = document.createElement('div');
  p.setAttribute('id', 'div_' + num_of_lines);
  p.setAttribute('style','margin:5px');
  
  // vložít prvky do spanu
  p.appendChild(text);
  p.appendChild(input);  
  p.appendChild(br);
  
  // vložit celý span do elementu 
  x.appendChild(p);
}
  
//* Odstranění elementu z rozšířeného vyhledávání *//
 
function minus(element)
{  
  if( num_of_lines < 1 ) return;
  var d = document.getElementById( element );
  var olddiv = document.getElementById( 'div_' + num_of_lines );
  num_of_lines--;
  d.removeChild(olddiv);
}

//* Zobrazení náhledu obrázku *//
var offsetfrommouse=[10,10]; //image x,y offsets from cursor position in pixels. Enter 0,0 for no offset
var displayduration=0; //duration in seconds image should remain visible. 0 for always.
var currentimageheight = 800;	// maximum image size.
var padding=5; // padding must by larger than specified div padding in stylessheet

// Global variables for sizes of hoverimg
// Defined in "showtrail()", used in "followmouse()"
var zoomimg_w=0;
var zoomimg_h=0;

if (document.getElementById || document.all){
  document.write('<div id="trailimageid">');
  document.write('</div>');
}

function getObj(name) 
{
  if (document.getElementById) 
  {
  	  this.obj = document.getElementById(name);
      this.style = document.getElementById(name).style;
  } 
  else if (document.all) 
  {
    this.obj = document.all[name];
    this.style = document.all[name].style;
  } 
  else if (document.layers) 
  {
    this.obj = document.layers[name];
    this.style = document.layers[name];
  }
}

function gettrail()
{
  return new getObj("trailimageid");
}

function truebody()
{
  return (!window.opera && document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function showtrail(imagename,title,zoomimgwidth,zoomimgheight, image)
{
  zoomimg_w=zoomimgwidth;
  zoomimg_h=zoomimgheight;
  if (zoomimgheight > 0){ currentimageheight = zoomimgheight; }
  trailobj = gettrail().obj;
  trailobj.style.width=(zoomimgwidth+(2*padding))+"px";
  trailobj.style.height=(zoomimgheight+(2*padding))+"px";
  trailobj.setAttribute("width",zoomimgwidth);
  trailobj.setAttribute("height",zoomimgheight);
  trailobj.setAttribute("imagename",imagename);
  trailobj.setAttribute("imgtitle",title);
  //document.body.onscroll=followmouse;
  document.onmousemove=followmouse;
}

function hidetrail(){
  trailstyle = gettrail().style;
  trailstyle.visibility = "hidden";
  document.onmousemove = "";
  trailstyle.left = "-2000px";
  trailstyle.top = "-2000px";
}

function followmouse(e)
{
  trail = gettrail();

  width     = trail.obj.getAttribute("width");
  height    = trail.obj.getAttribute("height");
  imagename = trail.obj.getAttribute("imagename");
  title     = trail.obj.getAttribute("imgtitle");

  //  ----------- window size
  var WWidth = 0;
  var WHeight = 0;
  
  if( typeof( window.innerWidth ) == 'number' )
  {
    //Non-IE
    WWidth = window.innerWidth;
    WHeight = window.innerHeight;
  }
  else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) 
  {
    //IE 6+ in 'standards compliant mode'
    WWidth = document.documentElement.clientWidth;
    WHeight = document.documentElement.clientHeight;
  }

  // ----------- scroll offset
  var scrOffX = 0;
  var scrOffY = 0;
      
  if( typeof( window.pageYOffset ) == 'number' ) 
  {
     //Netscape compliant
     scrOffY = window.pageYOffset;
     scrOffX = window.pageXOffset;
  }
  else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) 
  {
     //DOM compliant
     scrOffY = document.body.scrollTop;
     scrOffX = document.body.scrollLeft;
  }
  else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) 
  {
     //IE6 standards compliant mode
     scrOffY = document.documentElement.scrollTop;
     scrOffX = document.documentElement.scrollLeft;
  }
  
  myWidth = document.body.clientWidth;
  myHeight = document.body.clientHeight;

  // ----------- Mouse position
  var mouse_x;
  var mouse_y;
  //mouse position
  if (!e) var e = window.event;
  if (e.pageX || e.pageY) 	
  {
     mouse_x = e.pageX;
     mouse_y = e.pageY;
  }
  else if (e.clientX || e.clientY) 	
  {
     mouse_x = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
     mouse_y = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
  }
  
  //  ----------- picture positionm
  var X_pos = WWidth/2 + scrOffX - zoomimg_w/2;
  var Y_pos = WHeight/2 + scrOffY - zoomimg_h/2;
  //var Y_pos = mouse_y - zoomimg_h - 10;
  
  
  // ------------ setting image style
  trail.style.left = X_pos + "px";
  trail.style.top =  Y_pos + "px";
  
  if (trail.style.visibility != "visible") 
  {
      newHTML = '<div style="padding: 5px; border:1px solid #000000; cursor: pointer;" onclick="hidetrail();">';
      newHTML = newHTML + '<img src="' + imagename + '" alt="' + title + '">';
      newHTML = newHTML + '</div>';
      trail.obj.innerHTML = newHTML;
      trail.style.visibility="visible";
  }
}


