//chyba pri ajaxe
$(document).ajaxError(function (request,settings,e) {
    alert('Error requesting URL: '+e.url);
});

//funkcia na ziskanie URL routera
var Router = function (route,params) {
    //parametre
    if (typeof(params) == 'object') {
        var p = '';
        $.each(params,function (name,value) {
            if (p != '') {
                p += '&';
            }
            p += escape(name)+'='+escape(value);
        });
        return Router(route)+'?'+p;
    }
    else {
        return registry.langroot + '/' + route;
    }
};
Router.route = function (route,params) {
    var url = Router(route,params);
    location.href = url;
}

//hlavne menu
$(function () {
    $('dl.mainmenu ul li a').click(function () {
        $('>ul',$(this).parent('li').eq(0)).toggle("fast");
    });
});

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.clear();
	NewWindow.document.write(
         "<html><head><title>"+ title +"</title>"
        +"</head>\n"
        +"<body style=\"text-align:left;margin:15px;\">\n"
        +"<img onclick=\"window.close();\" src=\"" + IMG.src + "\" border=\"0\" alt=\""+title+"\" />\n"
        +"</body>\n"
        +"</html>"
	);
	NewWindow.document.close();
	NewWindow.focus();
	timer = setInterval("resize()",250);
}

function resize(plusW,plusH) {
    if(!IMG.complete){ return; }
    clearInterval(timer);
    var windowW = IMG.width+(plusW ? plusW : 50);
    var windowH = IMG.height+(plusH ? plusH : 70);
    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);
	}
}

