// Set up

if (typeof($)=="undefined")  throw("Required JQuery library is not loaded.");
$(function(){
aria2layout();
$("#menu li.selected a").removeAttr("href");
js2toplist("#toplist");
});

// Common functions

function aria2layout()
{
$("#menu").attr({
 role:"navigation",
 "aria-labelledby":"hdr-menu"
});
$("#content").attr({
 role:"main",
 "aria-labelledby":"hdr-content"
}).focus();
$("#footer").attr({
 role:"contentinfo",
 "aria-labelledby":"hdr-footer"
});
$("#header").attr("role","banner");
}

function js2toplist(container)
{
img=$("img",container);
src=img.attr("src")
+"&http="+escape(document.referrer)
+"&wi="+escape(window.screen.width)
+"&he="+escape(window.screen.height)
+"&cd="+escape(window.screen.colorDepth)
+"&t="+escape(document.title);
img.attr("src",src);
}

function openWindow(uri)
{
return (!window.open(uri));
}

// SectionSwitcher class

SectionSwitcher.prototype={

show:function(ref,section)
{
$(">div:visible",ref.container).each(function(){
if (ref.speed>0) $(this).slideUp(ref.speed);
else $(this).hide();
element=$(ref.selector+"."+$(this).attr("class"),ref.container);
element.click(function(){
ref.show(ref,this);
return true;
}).attr("href",element.data("hrefbak")).removeClass("selected");
});
element=$(">div."+$(section).attr("class"),ref.container);
if (ref.speed>0) element.slideDown(ref.speed);
else element.show();
window.location.hash=$(section).attr("href");
$(section).unbind("click").removeAttr("href").addClass("selected");
}

}
function SectionSwitcher(container,defaultSection)
{
this.container=$("."+container);
if ($(">:header",this.container).length>0)
{
$(">ul",this.container).hide();
this.selector=":header";
this.speed=500;
}
else
{
this.selector="ul";
this.speed=0;
}
this.selector=">"+this.selector+" a";
ref=this;
$(this.selector,this.container).each(function(){
$(this).click(function(){
ref.show(ref,this);
return true;
}).data("hrefbak",$(this).attr("href"));
});
$(">div:visible",this.container).hide();
$(this.selector+"[href='#"+defaultSection+"']",this.container).click();
}

// form functions

function setupForm()
{
$("form dt:has(label.required)").next("dd").find(":input").attr("aria-required",true);
}

function setupAppCoworker(submitted)
{
setupForm();
if (window.location.hash!="#zadost"&&!submitted) $("#zadost").hide();
$("#btn_zadost").click(function(){
$('#zadost').toggle(function(){
if (!$(this).is(":visible")) window.location.hash="";
});
});
}

