var main_page_array=new Array();

function set_html(uri)
{
	var i;
	for (i=0;i<main_page_array.length;i++) if (main_page_array[i].uri == uri) {
		document.getElementById('innerdiv').innerHTML = main_page_array[i].content;
		pager_remake_el(document.getElementById('innerdiv'));
		rebelia();
		return;
	}
	workframe.location.href='http://'+window.location.host+"/embedjs/"+uri;
}


function pager_remake_image_title(el)
{
	var v;
	if (el.nodeName.toUpperCase()=="IMG") {
		if (el.hasAttribute('title')) {
			v=el.getAttribute('title');
		}
		else v='';
		if (v=='') {
			if (el.hasAttribute('alt')) v=el.getAttribute('alt');
		}
		if (v != '') v+=' - ';
		v+='Kliknij aby obejrze\u0107 powi\u0119kszenie'
		el.setAttribute('title',v);
	}
	for (el=el.firstChild;el;el=el.nextSibling) pager_remake_image_title(el);
}

function pager_remake_el(el)
{
	var fl,cs,cl;
	if (el.nodeName.toUpperCase() == 'A') {
		cs=el.href;
		cl=el.getAttribute('class');
		if (cs) {
			var n,f;
			n=cs.lastIndexOf('/');
			cs=cs.substr(n+1);
			n=cs.lastIndexOf('.');
			f='set_html';
			if (cl=='pop') {
				f='openpop'
				pager_remake_image_title(el);
			}
			if (cs.substr(n+1)=='html') el.href="javascript:"+f+"('"+cs+"')";
			else if (cs.substr(n+1)=='jpg' || cs.substr(n+1)=='png' || cs.substr(n+1)=='gif') el.href="javascript:showimage('"+el.href+"')";
		}
	}
	for (fl=el.firstChild;fl;fl=fl.nextSibling) pager_remake_el(fl);
	
}
		
function pager_remake()
{
	pager_remake_el(document.body);
}


var popup_window,popup_image;

function openpop(a)
{
	if (popup_window) popup_window.close();
	popup_window=window.open(a,'POPUP_WINDOW','width=540,height=100,scrollbars=yes');
}

function showimage(a)
{
	if (popup_window) popup_window.close();
	popup_image=a;
	popup_window=window.open("/popup_image.html",'POPUP_WINDOW','width=100,height=100');
}

function closepop()
{
	if (popup_window) popup_window.close();
}

function write_workframe()
{
	document.writeln('<iframe name="workframe" src="/workframe/dummy.html" scrolling=no width=1 height=1 style="visibility:hidden"></iframe>');
}

var css_fontsizes=[10,12,14,18];
var css_wides=[760,980,1200,1500];
var last_typ=0;

function chansa()
{
	var f=document.body.clientWidth;
	var g=document.body.scrollWidth;
	if (g<f) f=g;
	if (window.innerWidth) {
		g=window.innerWidth;
		if (g<f) f=g;
	}
	var typ=0;
	if (f>=1500) typ=3;else
	if (f>=1200) typ=2;else
	if (f>=980) typ=1;
	else typ=0;
	if (last_typ != typ) {
		last_typ=typ;
		document.body.style.fontSize=css_fontsizes[typ]+"px";
		document.documentElement.style.fontSize=css_fontsizes[typ]+"px";
		document.getElementById('navbar').style.width=css_wides[typ]+"px";
	}
	f-=20;
	f=Math.floor((f-document.getElementById('navbar').offsetWidth)/2);
	if (f<0) f=0;
	document.getElementById('navbar').style.marginLeft=f+'px';
	rebelia();
}

function init()
{
    
    if (document.getElementById)
    {
      var inn = document.getElementById('innerdiv');
      if (inn) {
      	var uri=window.location.pathname;
	if (uri == '/') uri="index.html";
	else uri=uri.substr(1);
	main_page_array[0]={uri:uri,content:inn.innerHTML};   	
	}
      pager_remake();
      /*
      window.onresize=chansa;
      chansa();
      */
      return;
	var di=document.getElementById('navbar');
	var w=document.body.clientWidth;
	if (window.innerWidth) w=window.innerWidth;
	w=Math.round((w-780)/2);if (w<0) w=0;
	di.parentNode.style.marginLeft=w+'px';
  
    }
}

var left_height;

function rebelia()
{
	return;
	if (!left_height) left_height=document.getElementById('menuleft').offsetHeight;
	var hr=document.getElementById('innerdiv').offsetHeight-4;
	if (hr<left_height) hr=left_height;
	document.getElementById('menuleft').style.height=hr+'px';
	
}
