var AKTIVNA; // aktivna soba
var MAPTITLE; // naslov sobe
var RIBBON; // aktivni trak
var MAPLEFT; // x koordinata tlorisa
var MAPTOP; // y koordinata tlorisa
var SWIDTH = 5000; // dolzina tlorisa
var SHEIGHT = 3000; // visina tlorisa
var KORAKI_X;
var KORAKI_Y;
var STEP_X;
var STEP_Y;
var TIMER;
var KONTAKT_STATE = 0;


/*var XY = new Array(23);
for (i = 0; i < XY.length; ++ i) XY[i] = new Array(2); 
*/

var XY = new Array(23);
for (i = 0; i < XY.length; ++ i) XY[i] = new Array(3); 

// void
XY[0][0] = 0; 
XY[0][1] = 0;
XY[0][2] = "";
// galerija
XY[1][0] = 207; 
XY[1][1] = 2144;
XY[1][2] = "galerija";
// arhiv
XY[2][0] = 207; 
XY[2][1] = 2792;
XY[2][2] = "arhiv";
// Zanimivosti
XY[3][0] = 207; 
XY[3][1] = 3434;
XY[3][2] = "zanimivosti";
// Čakalnica
XY[4][0] = 849; 
XY[4][1] = 1500;
XY[4][2] = "cakalnica";
// Dnevna soba
XY[5][0] = 849; 
XY[5][1] = 2144;
XY[5][2] = "dnevnasoba";
// Recepcija
XY[6][0] = 849; 
XY[6][1] = 2792;
XY[6][2] = "recepcija";
// Resne stvari
XY[7][0] = 849; 
XY[7][1] = 3434;
XY[7][2] = "resnestvari";
// Debatnica
XY[8][0] = 1492; 
XY[8][1] = 2144;
XY[8][2] = "debatnica";
// Sproščevalnica
XY[9][0] = 1492; 
XY[9][1] = 2792;
XY[9][2] = "sproscevalnica";
// Garderoba
XY[10][0] = 2140; 
XY[10][1] = 2144;
XY[10][2] = "garderoba";
// Bižuterija
XY[11][0] = 2140; 
XY[11][1] = 2792;
XY[11][2] = "bizuterija";
// Muzika
XY[12][0] = 2140; 
XY[12][1] = 3434;
XY[12][2] = "muzika";
// Sabina
XY[13][0] = 207; 
XY[13][1] = 202;
XY[13][2] = "sabina";
// Nina
XY[14][0] = 531; 
XY[14][1] = 202;
XY[14][2] = "nina";
// Jure
XY[15][0] = 531; 
XY[15][1] = 849;
XY[15][2] = "jure";
// Zdenko
XY[16][0] = 855; 
XY[16][1] = 202;
XY[16][2] = "zdenko";
// Matic
XY[17][0] = 855; 
XY[17][1] = 849;
XY[17][2] = "matic";
// Jelena
XY[18][0] = 1179; 
XY[18][1] = 202;
XY[18][2] = "jelena";
// Matjaž
XY[19][0] = 1179; 
XY[19][1] = 849;
XY[19][2] = "matjaz";
// Ernest
XY[20][0] = 1503; 
XY[20][1] = 202;
XY[20][2] = "ernest";
// Luka
XY[21][0] = 1503; 
XY[21][1] = 849;
XY[21][2] = "luka";
// Dejan
XY[22][0] = 1827; 
XY[22][1] = 202;
XY[22][2] = "dejan";


function getQueryVariable(variable) 
{
	var query = window.location.search.substring(1);
	var vars = query.split("&");
	for (var i=0;i<vars.length;i++) 
	{
		var pair = vars[i].split("=");
		if (pair[0] == variable) return pair[1];
	}
		return false;
} 

function chgLang(el)
{
	var postParam = "wpID=" + el.id;
	new ajax ('chgLang.php', {
		postBody: postParam,
		onComplete: ReloadMe
	});
	
	return false;
}

function ReloadMe(request)
{	
	//writeSessionCookie("language", request.responseText);
	document.location.reload();
}

function getCookieValue (cookieName) {
  var exp = new RegExp (escape(cookieName) + "=([^;]+)");
  if (exp.test (document.cookie + ";")) {
    exp.exec (document.cookie + ";");
    return unescape(RegExp.$1);
  }
  else return false;
}


function writeSessionCookie (cookieName, cookieValue) {
  if (testSessionCookie()) {
    document.cookie = escape(cookieName) + "=" + escape(cookieValue) + "; path=/";
    return true;
  }
  else return false;
}

function testSessionCookie () {
  document.cookie ="testSessionCookie=Enabled";
  if (getCookieValue ("testSessionCookie")=="Enabled")
    return true 
  else
    return false;
}


function postar()
{
	
	var ime = document.getElementById('mkIme').value;
	var mail = document.getElementById('mkMejl').value;
	var sporocilo = document.getElementById('mkSporocilo').value;
	var subject = document.getElementById('mkSubject').value;

	var postP = 'ime='+ime+'&mail='+mail+'&sporocilo='+sporocilo+'&subject='+subject;

	document.getElementById('mkForm').style.display='none';
	document.getElementById('miniKontakt').innerHTML='<div style="text-align: center; height: 185px; line-height: 170px;"><img src="P/Ura.gif" /></div>';
	
	new ajax ('postar.php?F=kontakt', 
		{
			postBody: postP, 
			update: $('miniKontakt'),
			onComplete: aFinish
		}
	);
	//wAjax(postP, F, 'miniKontakt', 'postar');
	return false;
	
	
}

function aFinish()
{
	document.getElementById('miniKontakt').innerHTML = "";
	KONTAKT_STATE = 1;
	return false;
}

function resetKontakt()
{
	var mkForm = '<div style="float:right; height: 185px;"></div>';
	mkForm += '<form id="mkForm" action="index.php">';
	mkForm += '<p><input type="hidden" id="mkSubject" name="subject" value="'+cForm_subject+'" /></p>';
	mkForm += '<p><label>'+cForm_name+'<input id="mkIme" class="txt" name="mkIme" type="text" value="" title="'+cForm_name_title+'" /></label></p>';
	mkForm += '<p><label>'+cForm_mail+'<input id="mkMejl" class="txt" name="mkMejl" type="text" value="" title="'+cForm_mail_title+'" /></label></p>';
	mkForm += '<p><label>'+cForm_msg+'<textarea id="mkSporocilo" name="mkSporocilo" rows="60" cols="7" class="txt"></textarea></label></p>';
	mkForm += '<p><a href="#" class="mkLink" onclick="postar(\'kontakt\')" id="mkSubmit" title="click to send">'+cForm_send+'</a></p>';
	mkForm += '</form>';
	document.getElementById('miniKontakt').innerHTML = mkForm;
	return false;
}

// get visible screen size
function screenSize(widthORheight) 
{
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) 
  {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else 
  		if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) 
     {
    	//IE 6+ in 'standards compliant mode'
    		myWidth = document.documentElement.clientWidth;
    		myHeight = document.documentElement.clientHeight;
  		} else 
  			if (document.body && (document.body.clientWidth || document.body.clientHeight)) 
  			{
    		//IE 4 compatible
    			myWidth = document.body.clientWidth;
   	 		myHeight = document.body.clientHeight;
  			}

	retValue = widthORheight == 'w' ? myWidth : myHeight;

	return retValue;
}

function mapInit()
{
	sobe = document.getElementById("ardimap").getElementsByTagName("a");
	rExp = / aktivna/gi;
	for (i=0; i < sobe.length; i++)
	{
		if (sobe[i].className.match(rExp)) izbrani = sobe[i].id;
	}
	AKTIVNA = document.getElementById(izbrani);
	AKTIVNA.className += " mapA";
	RIBBON = "r" + AKTIVNA.id.substring(1);
	document.getElementById(RIBBON).style.display = "block";
	MAPTITLE = AKTIVNA.firstChild.firstChild.data;
	document.getElementById("napis").firstChild.data = MAPTITLE;
}



function tloris()
{
	theClip = document.getElementById("okno");
	theHandle = document.getElementById("zunanji");

	w0 = theClip.clientWidth;
	h0 = theClip.clientHeight;
	w1 = theHandle.clientWidth;
	h1 = theHandle.clientHeight;
	wB = document.body.clientWidth;
	hB = document.body.clientHeight;
	wB = (wB - w0) / 2;

	xMin = ((w0-wB) - w1) + 48;
	yMin = (h0 - h1);

	Drag.init(theHandle, null, xMin, 0, yMin, 0);
	//Drag.init(theHandle, null, 0, -xMin, 0, -yMin);

}

function setRemote()
{
	theRemote = document.getElementById("remote");
	remoteTitle = document.getElementById("ARDI");

	wB = document.body.clientWidth;
	hB = document.body.clientHeight;

	//alert("rh1="+theRemote.clientHeight);
	Drag.init(remoteTitle, theRemote, 0, wB-160, 0, hB-(theRemote.clientHeight));
	
	if ((parseInt(theRemote.style.top)+theRemote.clientHeight) > hB) theRemote.style.top =  (hB-(theRemote.clientHeight)) + 'px';
	if (parseInt(theRemote.style.top) < 0) theRemote.style.top =  '0px';

	if ((parseInt(theRemote.style.left)+160) > wB) theRemote.style.left =  (wB-160) + 'px';
	if (parseInt(theRemote.style.left) < 0) theRemote.style.left =  '0px';
	
}

function goCenter()
{
	theHandle = document.getElementById("zunanji");
	aktivna = 1*(AKTIVNA.id.substring(1));
	lw = (screenSize('w')-548)/2; // 548 = sirina = visina sobe
	
	th = (screenSize()-548)/2;

	ww = 1*(XY[aktivna][1]-lw*1);
	hh = 1*(XY[aktivna][0]-th*1);
	//ww = (ww<0) ? 0 : ww;
	hh = (hh<0) ? 0 : hh;
	theHandle.style.top = (hh)*-1 + 'px';
	theHandle.style.left = (ww)*-1 + 'px';
	MAPLEFT = ww * -1; //(XY[aktivna][1]) * -1;
	MAPTOP = hh * -1; //(XY[aktivna][0]) * -1;

	theHandle.style.display = "block"; 
	
	theRemote = document.getElementById("remote");
	theRemote.style.top = th + "px";
	theRemote.style.left = (lw -168) + "px"; // 168 = remote.width + 10px
	setRemote();

	theRemote.style.display = "block";
}


// set drag objects
function xywh(isLoad) 
{
	tloris();
	if (isLoad==1) 
	{
		goCenter();
	}
	else
	{
		setRemote();
	}
}


function pageStart()
{
	
	myHeight = new fx.Height('ardimap', {duration: 400});
	mkContact = new fx.Height('miniKontakt', {duration: 400});
	mkPodatki = new fx.Height('ardiInfo', {duration: 400});
	mapInit();
	xywh(1);
	
}


function inverseHandle(obj)
{
	obj.onmouseover = function ()
  {
		document.getElementById("zunanji").onmousedown = null;
	};

	obj.onmouseout = function ()
	{
		tloris();
	};
	
}

// record ID, switch, target ID, include file
function wAjax(postParam, func, target, Ajax)
{	
	//var postParam = "wpID="+id;
	new ajax (Ajax+'.php?F='+func, {
	postBody: postParam, 
	update: $(target)
	});

}



// klik, klik, klik ....
var FO = { movie:"klik.swf", width:"1", height:"1",
      majorversion:"6", build:"40", id:"klik", name:"klik", swliveconnect:"true", 
      allowscriptaccess:"samedomain", menu:"false", quality:"best", 
      wmode:"transparent" };
UFO.create(FO, "flashMovie"); 



 

    
var oldhandler = window.onload;
window.onload = (typeof oldhandler == "function")
    ? function() { oldhandler(); pageStart(); } : pageStart;


var oldhandler = window.onresize;
window. onresize = (typeof oldhandler == "function")
    ? function() { oldhandler(); xywh(0); } : xywh; 

