﻿var innerOBJ;
var tmpFja;
var comswf=['mimage','slide'];


	var meniSel=null;
	var divSel=null;
	var tid=null;

	function meniSelHide() {
		if (meniSel) {
			$(meniSel).hide(200);
			$(divSel).animate({width: parseInt($(divSel).attr('len')) + 'px'}, { queue:true, duration:200 });		
			meniSel=null;
		}
	}

	$(document).ready(function() {

		//$(window).mouseover(function() { tid=setTimeout("meniSelHide()",2000) });

		for (i=0; i<$('div[tip=meni]').size(); i++) $('div[tip=meni]:eq(' + i + ')').attr('len', $('div[tip=meni]:eq(' + i + ')').width());

		$('*[tip=meni][ima=1]').mouseover(
			function() {
				if ($(meniSel).attr('idx') != $(this).attr('idx')) {
					if (meniSel) meniSelHide();
					meniSel=$('ul[tip=smeni][idx='+$(this).attr('idx')+']');
					divSel=$('div[tip=meni][idx='+$(this).attr('idx')+']');
					clearTimeout(tid);

					$(meniSel).unbind('mouseover');
					$(meniSel).mouseover(function() { clearTimeout(tid) });

					$(this).unbind('mouseout');
					$(this).mouseout(function() { tid=setTimeout("meniSelHide()",2000) });

					$(meniSel).unbind('mouseout');
					$(meniSel).mouseout(function() { tid=setTimeout("meniSelHide()",2000) });
					$(meniSel).show(400);
					$(divSel).animate({width: "107px"}, { queue:true, duration:400 });
				}
			}
		);
		$('div[tip=link]').mouseover(function() {
			$(this).css('background','#6e96a8');
			$(this).css('cursor','pointer');
			$(this).find('a:first').css('color','lightgreen');
//$(meniSel).mouseout(function() { clearTimeout(tid); tid=setTimeout("meniSelHide()",2000) });
		});
		$('div[tip=link]').mouseout(function() {
			$(this).css('background','none');
			$(this).find('a:first').css('color','#1d3f60');
		});
		$('div[tip=slink]').mouseover(function() {
			$(this).css('background','#dddddd');
			$(this).css('cursor','pointer');
			$(this).find('a:first').css('color','maroon');
		});
		$('div[tip=slink]').mouseout(function() {
			$(this).css('background','none');
			$(this).find('a:first').css('color','black');
		});

	});


function closePixPreview() {
	//if (navigator.appName.indexOf("Microsoft") != -1) {
	var i=1;
	while (document.getElementById('swf'+i)) {
		document.getElementById('swf'+i).style.display='block';
		i++;
	}
	for (i=0;i<comswf.length;i++) {
		if (document.getElementById(comswf[i])) {
			if (navigator.appName.indexOf("Microsoft") == -1) document.getElementById(comswf[i]).style.visibility='visible'; 
			document.getElementById(comswf[i]).style.width='100%'; 
		}
	}
	//}
		
	document.getElementById('pixs').style.display='none';
}

function showImg(url,title,desc) { 
	//if (navigator.appName.indexOf("Microsoft") != -1) {
	var i=1;
	while (document.getElementById('swf'+i)) {
		document.getElementById('swf'+i).style.display='none';
		i++;
	}
	for (i=0;i<comswf.length;i++) {
		if (document.getElementById(comswf[i])) {
			if (navigator.appName.indexOf("Microsoft") == -1) document.getElementById(comswf[i]).style.visibility='hidden'; 
			document.getElementById(comswf[i]).style.width='0'; 
		}
	}
	//}
	document.getElementById('pixs').style.display=''; 
	document.getElementById('pixs').innerHTML='<center>'+AC_FL_GetContent2('codebase', 'https://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0','width', '100%','height', '100%','src', '/image.swf?'+(new Date()).getTime(),'movie', '/image.swf?'+(new Date()).getTime(),'quality', 'high','pluginspage', 'https://www.macromedia.com/go/getflashplayer','play', 'true','loop', 'true','scale', 'noscale','wmode', 'transparent','devicefont', 'false','id', '','bgcolor', '#6299B3','name', 'cro','menu', 'false','allowScriptAccess','sameDomain','salign', '','flashvars','pix=' + url + '&naslov=' + title + '&opis=' + desc) + '</center>'; 

}



function getSWF(movieName) {
    if (navigator.appName.indexOf("Microsoft") != -1) {
        return window[movieName];
    }
    else {
      if(document[movieName].length != undefined){
          return document[movieName][1];
      }
        return document[movieName];
    }
}

function showMImage(adr) {
	getSWF('mimage').showMImage(adr);
}


var xmlHttp;
function GetXmlHttpObject()
{
var xmlHttp=null;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttp;
}

function callWSsml(str, postdata, method, inner)
{
innerOBJ=bID(inner);
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 

if (method == "GET") {
	xmlHttp.onreadystatechange=callWSsmlState;
	xmlHttp.open("GET",str+"?"+postdata,true);
	xmlHttp.send(null);
}
else if (method == "POST")
{
	xmlHttp.onreadystatechange=callWSsmlState;
	xmlHttp.open("POST",str,true);
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded; charset=UTF-8");
	xmlHttp.setRequestHeader("Content-length",postdata.length);
	xmlHttp.send(postdata);
}
}

function callWSsml(str, postdata, method, inner, fja)
{
tmpFja=fja;
innerOBJ=bID(inner);
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 

if (method == "GET") {
	xmlHttp.onreadystatechange=callWSsmlState;
	xmlHttp.open("GET",str+"?"+postdata,true);
	xmlHttp.send(null);
}
else if (method == "POST")
{
	xmlHttp.onreadystatechange=callWSsmlState;
	xmlHttp.open("POST",str,true);
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded; charset=UTF-8");
	xmlHttp.setRequestHeader("Content-length",postdata.length);
	xmlHttp.send(postdata);
}
}

function callWSsmlState()
{ 
  if (xmlHttp.readyState==4)
  { 
  txt=xmlHttp.responseText;
  if (txt.substring(0,11) == "javascript:") {
    var newFun=new Function(txt.substring(11));
    innerOBJ.innerHTML="";
    newFun();
  }
  else
  {
    innerOBJ.innerHTML=txt;
  }
    if (tmpFja!='') {
	var newFja=new Function(tmpFja);
	tmpFja='';
	newFja();
    }
  }
  else if (xmlHttp.readyState==1)
  {
  innerOBJ.innerHTML="<center><img src='/img/wait.gif' width=16 height=16 border=0 align=top vspace=1></center>";
  }
}

function callWSsml2(str, postdata, method, inner)
{
innerOBJ=bID(inner);
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 

if (method == "GET") {
	xmlHttp.onreadystatechange=callWSsml2State;
	xmlHttp.open("GET",str+"?"+postdata,true);
	xmlHttp.send(null);
}
else if (method == "POST")
{
	xmlHttp.onreadystatechange=callWSsml2State;
	xmlHttp.open("POST",str,true);
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded; charset=UTF-8");
	xmlHttp.setRequestHeader("Content-length",postdata.length);
	xmlHttp.send(postdata);
}
}

function callWSsml2(str, postdata, method, inner, fja)
{
tmpFja=fja;
innerOBJ=bID(inner);
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 

if (method == "GET") {
	xmlHttp.onreadystatechange=callWSsml2State;
	xmlHttp.open("GET",str+"?"+postdata,true);
	xmlHttp.send(null);
}
else if (method == "POST")
{
	xmlHttp.onreadystatechange=callWSsml2State;
	xmlHttp.open("POST",str,true);
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded; charset=UTF-8");
	xmlHttp.setRequestHeader("Content-length",postdata.length);
	xmlHttp.send(postdata);
}
}

function callWSsml2State()
{ 
  if (xmlHttp.readyState==4)
  { 
  txt=xmlHttp.responseText;
  if (txt.substring(0,11) == "javascript:") {
    var newFun=new Function(txt.substring(11));
    innerOBJ.innerHTML="";
    newFun();
  }
  else
  {
    innerOBJ.innerHTML=txt;
  }
    if (tmpFja!='') {
	var newFja=new Function(tmpFja);
	tmpFja='';
	newFja();
    }
  }
  else if (xmlHttp.readyState==1)
  {
  //innerOBJ.innerHTML="<table border=0 style='width:100%; height:auto'><tr><td align=center valign=middle style='color:lightsteelblue'><img src='/img/lightbox-ico-loading.gif' width=32 height=32 border=0 align=top vspace=1></td></tr></table>";
innerOBJ.innerHTML="<img src='/img/wait2.gif' width=16 height=16 border=0 align=top>";
  }
}

function callWSsml3(str, postdata, method, inner)
{
innerOBJ=bID(inner);
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 

if (method == "GET") {
	xmlHttp.onreadystatechange=callWSsml3State;
	xmlHttp.open("GET",str+"?"+postdata,true);
	xmlHttp.send(null);
}
else if (method == "POST")
{
	xmlHttp.onreadystatechange=callWSsml3State;
	xmlHttp.open("POST",str,true);
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded; charset=UTF-8");
	xmlHttp.setRequestHeader("Content-length",postdata.length);
	xmlHttp.send(postdata);
}
}

function callWSsml3State()
{ 
  if (xmlHttp.readyState==4)
  { 
  txt=xmlHttp.responseText;
  if (txt.substring(0,11) == "javascript:") {
    var newFun=new Function(txt.substring(11));
    innerOBJ.innerHTML="";
    newFun();
  }
  else
  {
    innerOBJ.innerHTML=txt;
  }
    if (tmpFja!='') {
	var newFja=new Function(tmpFja);
	tmpFja='';
	newFja();
    }
  }
  else if (xmlHttp.readyState==1)
  {
  innerOBJ.innerHTML="<img src='/img/wait_s.gif' width=16 height=16 border=0>";
  }
}

function bID(id) {return document.getElementById(id);}

function URLEncode(strToEncode)
{
	
	// The Javascript escape and unescape functions do not correspond
	// with what browsers actually do...
	var SAFECHARS = "0123456789" +					// Numeric
					"ABCDEFGHIJKLMNOPQRSTUVWXYZ" +	// Alphabetic
					"abcdefghijklmnopqrstuvwxyz" +
					"-_.!~*'()";					// RFC2396 Mark characters
	var HEX = "0123456789ABCDEF";
	var cro = "šđžčćŠĐŽČĆ";
	var croH = new Array("%9A","%26%23273%3B","%9E","%26%23269%3B","%26%23263%3B","%8A","%26%23272%3B","%8E","%26%23268%3B","%26%23262%3B");

	var plaintext = strToEncode;
	var encoded = "";
	for (var i = 0; i < plaintext.length; i++ ) {
		var ch = plaintext.charAt(i); //substring(i,i+1);
	    if (ch == " ") {
		    encoded += "+";				// x-www-urlencoded, rather than %20
		} else if (SAFECHARS.indexOf(ch) != -1) {
		    encoded += ch;
		} else if (cro.indexOf(ch) != -1) {
		    encoded += ch; //croH[cro.indexOf(ch)];
		}
		  else if (ch.charCodeAt(0)==34) {
		    encoded +="%27";
		} else {
		    var charCode = ch.charCodeAt(0);
			if (charCode > 255) {
			    alert( "Unicode Character '" 
                        + ch 
                        + "' cannot be encoded using standard URL encoding.\n" +
				          "(URL encoding only supports 8-bit characters.)\n" +
						  "A space (+) will be substituted." );
				encoded += "+";
			} else {
				encoded += "%";
				encoded += HEX.charAt((charCode >> 4) & 0xF);
				encoded += HEX.charAt(charCode & 0xF);
			}
		}
	} // for

	return encoded;
}

function appendHead(file) {
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = file;
document.getElementsByTagName('head')[0].appendChild(script);  
}

function resizeImage(obj,maxX,maxY) {
	if (obj.width>maxX) {
		k=obj.height/obj.width;
		obj.width=maxX;
		obj.height=k*maxX;
		if (obj.height>maxY) {
			k=obj.width/obj.height;
			obj.height=maxY;
			obj.width=k*maxY;
		}		
	}
}
