window.onload = function() {
	external_links();
	rounded_corners();
	popup_img_init();
	ie_hover();
	menu_left();
}

function external_links() {
	if (!document.body.getElementsByTagName) {return false;}
  var anchors = document.getElementsByTagName("a");
  for (var i=0; i<anchors.length; i++) {
    var anchor = anchors[i];
    if (anchor.getAttribute("href") &&
        anchor.getAttribute("rel") == "external")
      anchor.target = "_blank";
    }
}

rounded_corners = function() {
	if(!document.getElementById || !document.createElement) {return false;}
	/* Take all divs */
	var divs = document.getElementsByTagName('div');
	var rounded_divs = [];
	/* Take rounded divs divs = with class RC */
	for (var i = 0; i < divs.length; i++) {
		if (/\brc\b/.exec(divs[i].className)) {
			rounded_divs[rounded_divs.length] = divs[i];
		}
	}
	for (var i = 0; i < rounded_divs.length; i++) {
		var original = rounded_divs[i];
		/* Make it the inner div of the four */
		original.className = original.className.replace('rc', '');
		/* Create the outer-most div */
		var tr = document.createElement('div');
		tr.className = 'rc-around';
		/* Swap out the original (we'll put it back later) */
		original.parentNode.replaceChild(tr, original);
		/* Create the two other inner nodes */
		var tl = document.createElement('div');
		var br = document.createElement('div');
		/* Glue the nodes back in to the document */
		tr.appendChild(tl);
		tl.appendChild(br);
		br.appendChild(original);
	}
}

function popup_img_init()
{
	if (!document.body.getElementsByTagName) {return false;}

	var as = document.body.getElementsByTagName('a');
	for(i=0;i<as.length;i++)
		if (as[i].className == 'popup_img')
			as[i].onclick = popup_img;

	return true;
}

function popup_img()
{
	var imgs = this.getElementsByTagName('img');
	var title = imgs[0].getAttribute('title');
	var alt = imgs[0].getAttribute('alt');

	/* finds dimensions in given string, format: (<width>x<height>), output: width=<width>,height=<height> */
	if (title)
	{
		var reg = title.match(new RegExp('\(([0-9]+)x([0-9]+)\)'));
		img_size = "width="+(parseInt(reg[2]))+",height="+(parseInt(reg[3])+5);
	}
	else { var img_size = "width=640,height=480"; }
	
	/* window options */
	var win_options = "dependent=1,resizable=1,scrollbars=0,location=0,menubar=0,statusbar=0,"+img_size;

	/* creates new window */
  if (win = window.open(this.href,'_blank',win_options))
  {
		win.document.open();
		win.document.write('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">');
		win.document.write('<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="pl" lang="pl">');
		win.document.write('<head><title>'+alt+'</title>');
		win.document.write('<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />');
		win.document.write('<style type="text/css">body {margin:0;	padding:0; background:#666;}</style>');
		win.document.write('</head><body onclick="window.close()">');
		win.document.write('<img title="'+title+'" src="'+this.href+'" alt="'+alt+'"></body></html>');
		win.document.close();
		return false;
  }
	
  /* follows link on failure */
	return true; 
}

function ie_hover() {
	if (!document.all || !document.getElementsByTagName) {return false;}
	
	var tags = document.getElementsByTagName("ul");
	for (var i=0; i<tags.length; i++) {
		if (tags[i].className == 'iehover') {
			for (j=0; j<tags[i].childNodes.length; j++) {
				var node = tags[i].childNodes[j];
				if (node.nodeName=="LI") {
					node.onmouseover=function() {	this.className+=" hover"; }
					node.onmouseout=function() { this.className=this.className.replace(" hover", ""); }
				}
			}
		}
	}
}

function menu_left() {
	if (!document.body.getElementsByTagName) {return false;}
	var tags = document.body.getElementsByTagName('li');
	for(i=0;i<tags.length;i++)
		if (tags[i].className == 'current')
			tags[i].onclick = menu_left_show_hide;
	return true;
}
function menu_left_show_hide() {
	// schowanie wszystkich
	var tags = document.body.getElementsByTagName('li');
	for(i=0;i<tags.length;i++)
	{
		if (tags[i].className == 'current')
		{	
			var uls = tags[i].getElementsByTagName('ul');
			if (uls[0])
			{
				uls[0].style.display = 'none';
			}
		}
	}
	// wyswietlenie kliknietego	
	var uls = this.getElementsByTagName('ul');
	uls[0].style.display = 'block';
/*
if (uls[0].style.display == 'block') uls[0].style.display = 'none'
	else uls[0].style.display = 'block';
*/	
}

