
preload_images = Array ();
timer = null;
to_left = false;
var PosunCyklicky_Smer = true;

function Posun2 ( tl )
{
	to_left = tl;

	timer = window.setInterval ( "Posun(to_left)", 1000 );
}

function _RemoveTimer ()
{
	window.clearInterval ( timer );

	timer = null;
}

function _SelectPage ( pos )
{
	var pages = document.getElementById ( "strankovanie" );

	if (pages == null)
		return;

	var pagesc = pages.childNodes.length;

	for ( var i=1; i<=pagesc; i++ )
	{
		var a = pages.childNodes[i-1];

		var an = a.tagName.toUpperCase ();

		if ( an == "A" )
		{
			var img = a.firstChild;

			img.src = i == ( pagesc - pos + 1 ) ? imgselsrc : imgsrc;
		}
	}
}

function PosunNa ( pos )
{
	var left = one * ( pos - 1 ) * per * -1;

	if ( left < min )
	{
		left = min;
	}

	var div = document.getElementById ( "galeria" );

	_SelectPage ( pos );

	clearInterval(timer);

	$(div).morph("left: " + left + "px;");
//	div.style.left = left + "px";
}

function Posun ( to_left, stop_timer )
{
	var div = document.getElementById ( "galeria" );

	if (div == null)
		return;

	var left = parseInt ( div.style.left );

	if ( isNaN ( left ) )
	{
		left = 0;
	}

	if ( to_left )
	{
		left -= one;

	}else
	{
		left += one;
	}

	if ( left > 0 )
	{
		left = 0;
	}else if ( left < min )
	{
		left = min;
	}

	if ( ( left % ( 4 * one ) ) == 0 || left == min )
	{
		var pos = Math.abs ( left / ( 4 * one ) );

		if ( left == min )
		{
			pos = pag - 1;
		}

		_SelectPage ( pos + 1 );
	}

	if (stop_timer) {
		clearInterval(timer);
	}

	$(div).morph("left: " + left + "px;");
//	div.style.left = left + "px";
}

function PosunCyklicky() {
	var div = document.getElementById ( "galeria" );

	if (div == null) return;

	var left = parseInt ( div.style.left );

	if (isNaN(left)) left = 0;

	if (left == 0) PosunCyklicky_Smer = true;
	if (left == min) PosunCyklicky_Smer = false;

	Posun(PosunCyklicky_Smer, false);
}

function _OdznacOznac ( ul, which )
{
	var ulc = ul.childNodes.length;

	for ( var i=0; i<ulc; i++ )
	{
		var li = ul.childNodes[i];

		var lin = li.tagName.toUpperCase ();

		if ( lin == "LI" )
		{
			li.className = i == which ? "sel" : "";
		}
	}
}

function UkazMapu(kraj)
{
	var muzea_mapa = document.getElementById("muzea_mapa");

	muzea_mapa.src = map_images[kraj];

	for (var i=1; i<=8; i++) {
		var div = document.getElementById("kraj" + i);

		if (div == null)
			continue;

		div.style.display = i == kraj ? "block" : "none";
	}
}

function UkazObrazok ( elem, which )
{
	if ( typeof museum_images != "undefined" )
	{
		if ( typeof museum_images[which] != "undefined" )
		{
			_OdznacOznac ( elem.parentNode.parentNode, which );

			var main_flash = document.getElementById ( "main_flash" );

			if ( main_flash != null )
			{
				main_flash.style.display = which == 0 ? "block" : "none";
			}

			var slidebox = document.getElementById ( "slidebox" );

			slidebox.style.backgroundImage = "url('" + museum_images[which] + "')";
		}
	}
}

function UkazObrazokMuzea ( which, obj )
{
	var img = document.getElementById ( "museum_image" );

	if ( img == null ) return;

	img.src = "/swift_data/source/muzea_uvod_rozdelenie/" + which + ".jpg";

	var p = img.nextSibling;

	if ( p == null || typeof p.tagName == "undefined" || p.tagName.toLowerCase () != "p" ) return;

	p.innerHTML = obj.innerHTML;

	ZrusZvyraznenie ( which );
}

function UkazKontakt ( id )
{
	var div = document.getElementById ( "kontakty" + id );

	if ( div == null ) return;

	div.style.display = div.style.display == "none" ? "block" : "none";
}

function ZvyrazniMuzeum ( id )
{
	var a = document.getElementById ( "muzeum-" + id );

	if ( a == null ) return;

    UkazObrazokMuzea ( id, a );

    ZrusZvyraznenie ( id );
}

function ZrusZvyraznenie ( id )
{
    var zoznam = document.getElementById ( "zoznam_muzei" );

    if ( zoznam == null ) return;

    var acka = zoznam.getElementsByTagName ( "a" );

    for ( var i=0; i<acka.length; i++ )
    {
    	var acko = acka[i];

    	if ( typeof acko.id == "undefined" ) continue;

    	if ( acko.id == "muzeum-" + id )
    	{    	
    		acko.className = "selm";
    	}else
    	{
    		acko.className = "";
    	}
    }
} 

function PreLoadImages ( images )
{
	preload_image_object = new Image ();

	for ( var i=0; i<images.length; i++ )
	{
		preload_image_object.src = images[i];
	}

	var slideboxul = document.getElementById ( "slideboxul" );

	if ( slideboxul != null )
	{	
		var li = slideboxul.firstChild;

		li.className = "sel";
	}
}

function SetupAnchors ()
{
	var anchors = document.getElementsByTagName ( "a" );

	for ( var i = 0; i < anchors.length; i++ )
	{
		var anchor = anchors[i];

		var relAttribute = String(anchor.getAttribute("rel"));

		if (anchor.getAttribute("href"))
		{
			if ( relAttribute.match ( /^Posun2/ ) )
			{
				eval ( "anchor.onmouseover = function () { " + relAttribute + "; return false; }" );
				eval ( "anchor.onmouseout = function () { _RemoveTimer(); return false; }" );

				var tmp = relAttribute.replace ( "Posun2", "Posun" );

				eval ( "anchor.onclick = function () { " + tmp + "; return false; }" );

				anchor.href = "javascript:void(0)";
			}else if ( relAttribute.match ( /^Posun/ ) || relAttribute.match ( /^UkazGaleriu/ ) || relAttribute.match ( /^UkazKontakt/ ) )
			{
				eval ( "anchor.onclick = function () { " + relAttribute + "; return false; }" );

				anchor.href = "javascript:void(0)";
			}
		}
	}

	var anchors = document.getElementsByTagName ( "area" );

	for ( var i = 0; i < anchors.length; i++ )
	{
		var anchor = anchors[i];

		var onmouseoverAttribute = String(anchor.getAttribute("onmouseover"));

		if (anchor.getAttribute("href"))
		{
			if ( onmouseoverAttribute.match ( /^UkazMapu/ ) )
			{
				eval ( "anchor.onclick = function () { " + onmouseoverAttribute + "; return false; }" );

				anchor.href = "javascript:void(0)";
			}
		}
	}
}

function _OpenWindow ( url, w, h, b_scrollbars, b_resizable )
{
	var twidth = w;
	var theight = h;

	var i_scrollbars = b_scrollbars ? 1 : 0;
	var i_resizable = b_resizable ? 1 : 0;

	if(twidth > screen.width - 40) twidth = screen.width - 40;
	if(theight > screen.height - 40) theight = screen.height - 40;

	var pos_x = (screen.width - twidth - 10)/2;
	var pos_y = (screen.height - theight - 29)/2;

	if(typeof(okno) == "undefined" || okno.closed)
		okno = window.open(url,'okno','status=no,menubar=0,toolbar=0,location=0,scrollbars=' + i_scrollbars + ',screenX='+pos_x+',screenY='+pos_y+',left='+pos_x+',top='+pos_y+',width='+twidth+',height='+theight+',resizable=' + i_resizable );
	else okno.location.href = url;

	okno.focus();
}

function UkazGaleriu ( url )
{
	_OpenWindow ( url, 660, 720, true, false );
}

function AjaxRequest ( not_cached )
{
	this.req = null;
	this.not_cached = not_cached;
}

AjaxRequest.prototype = 
{
	sendRequest : function ( url, callback, post_data )
	{
		var ar = this;

		ar._createXMLHTTPObject ();

		if ( !ar.req ) return;

		var method = ( post_data ) ? "POST" : "GET";

		try
		{
			if ( !this.not_cached )
			{
				if ( url.indexOf ( "?" ) == -1 ) url += "?" + Math.random ();
				else url += "&" + Math.random ();
			}

			ar.req.open ( method, url, true );
		}catch ( e )
		{
			return;
		}

		ar.req.setRequestHeader ( 'User-Agent', 'XMLHTTP/1.0' );

		if ( post_data ) ar.req.setRequestHeader ( 'Content-Type', 'application/x-www-form-urlencoded' );

		ar.req.onreadystatechange = function ()
		{
			if ( ar.req.readyState != 4 ) return;

			if ( ar.req.status != 200 && ar.req.status != 304 )
			{
				return;
			}

			callback ( ar.req );
		}

		if ( ar.req.readyState == 4 ) return;

		try
		{
			ar.req.send ( post_data );
		}catch ( e )
		{
			return;			
		}
	},

	_createXMLHTTPObject : function ()
	{
		var factories = [
			function () {return new XMLHttpRequest()},
			function () {return new ActiveXObject("Msxml2.XMLHTTP")},
			function () {return new ActiveXObject("Msxml3.XMLHTTP")},
			function () {return new ActiveXObject("Microsoft.XMLHTTP")}
		];

		for ( var i=0; i<factories.length; i++ )
		{
			try
			{
				this.req = factories[i]();
			}catch (e)
			{
				continue;
			}

			break;
		}
	}
}

function OnLoad ()
{
	if ( typeof preload_images != "undefined" )
	{
		PreLoadImages ( preload_images );	
	}

	SetupAnchors ();

	var div = document.getElementById ( "galeria" );

	if (div != null)
		timer = window.setInterval ( "PosunCyklicky()", 5000 );
}

if ( window.addEventListener )
{
	window.addEventListener ( "load", OnLoad, false );
}else if ( window.attachEvent )
{
	window.attachEvent ( "onload", OnLoad );
}else
{
	window.onload = function () { OnLoad (); }
}