

function f_clientWidth() {
	return f_filterResults (
		window.innerWidth ? window.innerWidth : 0,
		document.documentElement ? document.documentElement.clientWidth : 0,
		document.body ? document.body.clientWidth : 0
	);
}
function f_clientHeight() {
	return f_filterResults (
		window.innerHeight ? window.innerHeight : 0,
		document.documentElement ? document.documentElement.clientHeight : 0,
		document.body ? document.body.clientHeight : 0
	);
}
function f_scrollLeft() {
	return f_filterResults (
		window.pageXOffset ? window.pageXOffset : 0,
		document.documentElement ? document.documentElement.scrollLeft : 0,
		document.body ? document.body.scrollLeft : 0
	);
}
function f_scrollTop() {
	return f_filterResults (
		window.pageYOffset ? window.pageYOffset : 0,
		document.documentElement ? document.documentElement.scrollTop : 0,
		document.body ? document.body.scrollTop : 0
	);
}
function f_filterResults(n_win, n_docel, n_body) {
	var n_result = n_win ? n_win : 0;
	if (n_docel && (!n_result || (n_result > n_docel)))
		n_result = n_docel;
	return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}



function externalLinks()
{
   if (!document.getElementsByTagName) return;
   var anchors = document.getElementsByTagName("a");

   for (var i=0; i<anchors.length; i++)
   {
	  var anchor = anchors[i];
	  var kon = anchor.getAttribute("href").match(/\.(jpg|jpeg|png|mp3|avi|swf|mpeg|mpg)$/);

	  if(kon)
	  {

		 switch(kon[1])
		 {
			case 'jpg':
			case 'jpeg':
			case 'png':
			case 'gif':
			anchor.onclick = popup_slika;
			break;

		 }

	  }

	  if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external")
	  {
		 anchor.target = "_blank";
	  }
   }
}

function popup_slika(e)
{


   var ev = e ||window.event;
   var tg = ev.target || ev.srcElement

   /*alert('Pokažemo sliko: ' + tg.href);
   return;
   */
   if(document.getElementById('popup_slika'))
   {
	  var parentx = document.getElementById('popup_slika');
	  var sir = false;
	  var vis = false;

	  if(window.innerWidth && window.innerHeight)
	  {
		  sir = window.innerWidth;
		  vis = window.innerHeight;
	  }
	  else if(document.body.offsetWidth && document.body.offsetHeight)
	  {
		  sir = document.body.offsetWidth;
		  vis = document.body.offsetHeight;
	  }

	  newimg = document.createElement('img');
	  newimg.style.display = 'block';
	  newimg.src = tg.href;
	  newimg.onclick = function()
		 {
		   this.parentNode.removeChild(this);
		   parentx.style.display = 'none';
		 };

	  levo =  parseInt((f_clientWidth()/2) + f_scrollLeft() -160);
	  zgoraj = parseInt((f_clientHeight()/2) + f_scrollTop() - 160);

	  parentx.appendChild(newimg);
	  parentx.style.position = 'absolute';
	  parentx.style.left = levo + 'px';
	  parentx.style.top = zgoraj + 'px';
	  parentx.style.display = 'block';

	  //document.getElementById('statusx').innerHTML = 'sirina: ' + newimg.width + ' visina: ' + newimg.height + '<br>' + f_clientWidth()+ 'x' + f_clientHeight() + '<br>' + ((f_clientHeight()/2) - (newimg.height/2)) + '<br>' + levo + 'x'+ zgoraj;

	  return false;
   }
   else
   {

	  return true;
   }

}


externalLinks();


