var main_page_array=new Array();
var main_history_array=new Array();
var main_history_pos=0;
var main_history_length=0;

function append_for_back()
{
	var s="";
	if (main_history_pos>0) s+='<a href="javascript:go_back()" title="Powr\u00F3t do poprzedniej strony">&lt;&lt;&lt;=';
	if (main_history_pos<main_history_length) {
		if (s != '') s+='&nbsp;&nbsp;';
		s+='<a href="javascript:go_fwd()" title="Przejd\u017A do nast\u0119pnej strony">=&gt;&gt;&gt;';
	}
	if (s=='') return;
	var el=document.getElementById('innerdiv');
	for (el=el.firstChild;el;el=el.nextSibling) {
		if (el.nodeName.toLowerCase() == 'div') break;
	}
	var div=document.createElement('div');
	div.innerHTML='<div style="float:right;padding-top:5px">'+s+'</div>';
	el.insertBefore(div.firstChild,el.firstChild);
}

function go_back()
{
	main_history_pos-=2;
	set_html(main_history_array[main_history_pos+1]);
}

function go_fwd()
{
	set_html(main_history_array[main_history_pos+1]);
}

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'));
		main_history_pos++;
		if (main_history_array[main_history_pos]!=uri) {
			main_history_array[main_history_pos]=uri;
			main_history_length=main_history_pos;
		}
		else if (main_history_length<main_history_pos) main_history_length=main_history_pos;
		/*
		add_price();
		append_for_back();
		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 && cl != "druk") {
			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>');
}

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}; 
	}
      main_history_array[main_history_pos=0]=uri;
      main_history_length=0;
      pager_remake();
      /*
      add_price();
      rebelia();
      */
    }
}

var startup_strings=['<TABLE align="center" style="table-layout:fixed;background-color:white" class="owetable" BORDER="0" CELLPADDING="0" CELLSPACING="0" WIDTH="740"><TR><TD><TABLE BORDER="0" CELLPADDING="0" CELLSPACING="0" WIDTH="740" HEIGHT="127"><TR><TD ROWSPAN="1" COLSPAN="2" WIDTH="740" HEIGHT="91">   <IMG SRC="gfx/preview_1x1.jpg" WIDTH="740" HEIGHT="91" BORDER="0"></TD></TR><TR><TD ROWSPAN="1" COLSPAN="1" WIDTH="533" HEIGHT="19"><IMG SRC="gfx/preview_2x1.png" WIDTH="533" HEIGHT="19" BORDER="0"></TD><TD ROWSPAN="1" COLSPAN="1" WIDTH="207" HEIGHT="19"><IMG SRC="gfx/preview_2x2.jpg" WIDTH="207" HEIGHT="19" BORDER="0"></TD></TR><TR><TD ROWSPAN="1" COLSPAN="2" WIDTH="740" HEIGHT="17"><IMG SRC="gfx/preview_3x1.jpg" WIDTH="740" HEIGHT="17" BORDER="0"></TD></TR></TABLE></TD></TR><tr><table width="740" align="center" cellpadding="0" cellspacing="0" border="0" style="table-layout:fixed;background-color:white"><tr><td width="160"><img src="gfx/nic.gif" width=160 height=1></td><td width="580"><img src="gfx/nic.gif" width=580 height=1></td></tr><tr>   <td class="menutd">','</td><td class="innertd">','</td></tr></table></td></tr></table>'

];

function startup_table(n)
{
	document.write(startup_strings[n]);
}


