

function popUp(url,windowName,windowTitle,closeOnClick,width,height,t){
	if(!url)return
	function readSize(){if(t.complete)showPopup(t.width,t.height);else setTimeout(readSize,1e2)}
	function showPopup(w,h){with(window.open('',windowName||'','width='+(width||w)+',height='+(height||h)).document){open();write('<html><head><title>'+(windowTitle||'')+'</title></head><body style="margin:0;padding:0"><img src="'+url+'" style="display:block'+(closeOnClick?';cursor: pointer" onclick="self.close()" title="Zamknij okno"':'"')+'></body></html>');close()}}
	if(!width||!height)t=new Image(),t.src=url,readSize()
	else showPopup(width,height)
}


function enablePopups()
{
	var arr = getElementsByClassName("okienko");	
	for(var i = 0; i < arr.length; i++)
	{
		arr[i].onclick = function(){popUp(this.href,'','TanieKubki.pl',!0); return false;};
	}
}

function enableTooltips(id){
	var links,i,h;
	h=document.createElement("span");
	h.id="btc";
	h.setAttribute("id","btc");
	h.style.position="absolute";
	document.getElementsByTagName("body")[0].appendChild(h);
	if(id==null) {
	links = getElementsByClassName("chmurka");
	} else {
		links=document.getElementById(id).getElementsByTagName("a");
	}
	for(i=0;i<links.length;i++){
	    Prepare(links[i]);
    }
}

function getElementsByClassName(cn){
  var arr = new Array(); 
  var els = document.getElementsByTagName("*");
  var exp= new RegExp("^(.* )?"+cn+"( .*)?$", "g");
  for (var i = 0; i < els.length; i++ ){
    if (exp.test(els[i].className)){
      arr.push(els[i]);
    }
  }
  return arr;
}




function Przygotuj(el) {
	el.onmouseover=function(){ChangeImage(el);}
    el.onmouseout=function(){BackImage(el);}
}

function Przygotuj2(el) {
	el.onmouseover=function(){ChangeImage2(el);}
    el.onmouseout=function(){BackImage2(el);}
}




function Przygotuj_miniatura(el) {
	el.onclick = function(){Change_main_image(el);alert(el.getAttribute("src"));}
}

function Prepare(el){
	var tooltip,t,b,s,l;
	t=el.getAttribute("title");
	el.removeAttribute("title");
	el.removeAttribute("alt");
	tooltip=CreateEl("span","tooltip");
	s=CreateEl("span","bubbletop");
	s.appendChild(document.createTextNode(t));
	tooltip.appendChild(s);
	b=CreateEl("b","bubblebottom");
	l='';
	b.appendChild(document.createTextNode(l));
	tooltip.appendChild(b);
	setOpacity(tooltip);
	el.tooltip=tooltip;
	if(t!=null && t.length!=0) {
	    el.onmouseover=showTooltip;
	    el.onmouseout=hideTooltip;
	    el.onmousemove=Locate;
	}
}

function ChangeImage (h) {
		obrazek=h.getAttribute("src");
		podmiana = obrazek.replace(/.jpg/,'_r.jpg');
		var last = podmiana.lastIndexOf('/');
		var lastP = podmiana.lastIndexOf('/', last-1);
		h.alt = podmiana.substring(lastP, last);
		podmiana=podmiana.replace(/dlugopisy_reklamowe/,'des/preload');
		podmiana=podmiana.replace(/kubki_reklamowe/,'des/preload');
		h.src=podmiana;
}

function BackImage (h) {
		obrazek=h.getAttribute("src");
		podmiana = obrazek.replace(/_r.jpg/,'.jpg');
		podmiana=podmiana.replace(/des\/preload/, h.alt)
		h.src=podmiana;
}


function Change_main_image(h) {
	document.getElementById("obrazek_glowny").src = h.getAttribute("src");
}

function enableOver () {
	obrazki = getElementsByClassName("roll");
	for(i=0;i<obrazki.length;i++){
		Przygotuj(obrazki[i]);
	}

}
function enable_main_photo () {
	obrazki = getElementsByClassName("miniatura");
//	alert(obrazki.innerHTML);
	for(i=0;i<=obrazki.length;i++){
//	alert(obrazki[i].innerHTML);
		Przygotuj_miniatura(obrazki[i]);
	}
}



function showTooltip(e){
document.getElementById("btc").appendChild(this.tooltip);
Locate(e);
}

function hideTooltip(e){
var d=document.getElementById("btc");
if(d.childNodes.length>0) d.removeChild(d.firstChild);
}

function setOpacity(el){
el.style.filter="alpha(opacity:80)";
el.style.KHTMLOpacity="0.80";
el.style.MozOpacity="0.80";
el.style.opacity="0.80";
}

function CreateEl(t,c){
var x=document.createElement(t);
x.className=c;
x.style.display="block";
x.style.zIndex="2";
return(x);
}

function Locate(e){
var posx=0,posy=0;
if(e==null) e=window.event;
if(e.pageX || e.pageY){
    posx=e.pageX; posy=e.pageY;
    }
else if(e.clientX || e.clientY){
    if(document.documentElement.scrollTop){
        posx=e.clientX+document.documentElement.scrollLeft;
        posy=e.clientY+document.documentElement.scrollTop;
        }
    else{
        posx=e.clientX+document.body.scrollLeft;
        posy=e.clientY+document.body.scrollTop;
        }
    }
document.getElementById("btc").style.top=(posy+5)+"px";
document.getElementById("btc").style.left=(posx-235)+"px";
}


image1 = new Image();
image1.src = "http://taniekubki.pl/des/chmurka.gif";

window.onload=function(){
	obrazki = document.getElementsByTagName("img");for(i=0;i<obrazki.length;i++){obrazki[i].setAttribute('alt','');}
	inputy = document.getElementsByTagName("input");for(i=0;i<inputy.length;i++){inputy[i].setAttribute('title','');}
	enableOver()
//	enable_main_photo()
	enableTooltips()
	enablePopups()
	var inputs = document.getElementsByTagName("input"), i = inputs.length;while(i--){inputs[i].onfocus = function(){this.className += " focus";};inputs[i].onblur = function(){this.className = this.className.replace("focus", "");};};
};
