function addEvent(o,e,f){
	if (o.addEventListener){ o.addEventListener(e,f,true); return true; }
	else if (o.attachEvent){ return o.attachEvent("on"+e,f); }
	else { return false; }
}

var timer = null;
var IMG = null;
var NewWindow = null;
function ViewImage(Isrc,title) {
	IMG = new Image;
	IMG.src = Isrc;
	if (typeof(title)=="undefined" || title=="") title="Gallery";
	if (NewWindow) { NewWindow.close(); }
	if (NewWindow==null || NewWindow.closed) {
		settings=
		 "left="+50+","
		 +"top="+50+","
		 +"width="+640+","
		 +"height="+480+","
		 +"toolbar=no,"
		 +"location=no,"
		 +"directories=no,"
		 +"status=no,"
		 +"menubar=no,"
		 +"scrollbars=yes,"
		 +"resizable=yes"
		 NewWindow = window.open("",'Gallery',settings);
	}
	NewWindow.document.open();
	NewWindow.document.write(
         "<html><head><title>"+ title +"</title>"
        +"</head>\n"
        +"<body style=\"text-align:left;margin:0px;padding:10px;\">\n"
        +"<img onclick=\"window.close();\" src=\"" + IMG.src + "\" border=\"0\" alt=\""+title+"\" />\n"
        +"</body>\n"
        +"</html>"
	);
	NewWindow.document.close();
	NewWindow.focus();
    // NewWindow.location.href = IMG.src;
	timer = setInterval("resize()",250);
}

function ViewGalleryImage(Isrc,galleryElement) {
	IMG = new Image;
	IMG.src = Isrc;
    var description = galleryElement.getElementsByTagName('dd').item(0).innerHTML;
	if (typeof(title)=="undefined" || title=="") title="Gallery";
	if (NewWindow) { NewWindow.close(); }
	if (NewWindow==null || NewWindow.closed) {
		settings=
		 "left="+50+","
		 +"top="+50+","
		 +"width="+640+","
		 +"height="+480+","
		 +"toolbar=no,"
		 +"location=no,"
		 +"directories=no,"
		 +"status=no,"
		 +"menubar=no,"
		 +"scrollbars=yes,"
		 +"resizable=yes"
		 NewWindow = window.open("",'Gallery',settings);
	}
	NewWindow.document.open();
	NewWindow.document.write(
         "<html><head><title>"+ title +"</title>"
        +"<style type=\"text/css\">body {font-size:0.8em;font-family:Arial;color:#000;backgroun:#FFF;margin:0em;padding:10px;}</style>\n"
        +"</head>\n"
        +"<body style=\"text-align:left;margin:0px;padding:10px;\">\n"
        +"<p>"+description+"</p>"
        +"<img onclick=\"window.close();\" src=\"" + IMG.src + "\" border=\"0\" alt=\""+title+"\" />\n"
        +"</body>\n"
        +"</html>"
	);
	NewWindow.document.close();
	NewWindow.focus();
    // NewWindow.location.href = IMG.src;
	timer = setInterval("resize(50,120)",250);
}

function resize(plusW,plusH) {
    if(!IMG.complete){ return; }
    clearInterval(timer);
    var windowW = IMG.width+(plusW ? plusW : 50);
    var windowH = IMG.height+(plusH ? plusH : 60);
    if (windowW >= screen.width - 100)
    {
        windowW = screen.width - 100;
    }
    if (windowH >= screen.height - 100)
    {
        windowH = screen.height - 100;
    }
	resizeWindowTo(NewWindow,windowW,windowH);
	IMG = null;
    clearInterval(timer);
}

function resizeWindowTo(WindowObject,w,h) {
	if (parseInt(navigator.appVersion)>3) {
		if (navigator.appName=="Netscape") {
			WindowObject.outerWidth=w;
			WindowObject.outerHeight=h;
		}
		else WindowObject.resizeTo(w,h);
	}
}

function CreateMainMenu()
{
    var m = document.getElementById('mainmenu')
    if (m)
    {
        var lis = m.getElementsByTagName('LI');
        // var sipka_span = null;
        for (var i = 0 ; i < lis.length ; i++)
        {
            // sipka_span = document.createElement('SPAN');
            // sipka_span.className = 'sipka';
            // lis[i].insertBefore(sipka_span,lis[i].firstChild);
            lis[i].onmouseover = function() {
                this.className += ' hover';
            };
            lis[i].onmouseout = function() {
                this.className = this.className.replace(' hover','');
                this.className = this.className.replace('hover','');
            };
        }
    }
}
// addEvent(window,'load',CreateMainMenu);

function ProceedViewImagers()
{
    var im = document.getElementsByTagName('a');
    if (im)
    {
        for (var i = 0 ; i < im.length ; i++)
        {
            if (im[i].className == 'viewImage')
            {
                im[i].onclick = function() {
                    ViewImage(this.href,'');
                    return false;
                };
            }
        }
    }
}
addEvent(window,'load',ProceedViewImagers);

function tagExternalLinks() {
	var aTags = document.getElementsByTagName("A");
	var URLparts = new Array();
	for (var i=0; i < aTags.length; i++) {
		URLparts = aTags[i].href.split('/');
		if (
			URLparts[2] != window.location.host && 
			    aTags[i].href.substring(0,11) != 'javascript:' && 
                aTags[i].href.substring(0,7) != 'mailto:'
			) {
			aTags[i].onclick = doExternalClick;
		}
	}
}
function doExternalClick() {
	window.open(this.href);
	return false;
}
addEvent(window,'load',tagExternalLinks);

//uprava quickSearch - vyladavanie len na 3 znaky
function quickSearch_check(f)
{
    if (f.q.value.length < 3)
    {
        return false;
    }
    else
    {
        return true;
    }
}
addEvent(window,'load',function ()
{
    document.getElementById('quickSearch').onsubmit = function ()
    {
        return quickSearch_check(this);
    };
});
