var pop, IE=document.all?true:false;

if(!IE) {
	document.captureEvents(Event.MOUSEMOVE);
	document.onmousemove=mousePos;
	var netX, netY;
}

function initpop() {
	if(IE) pop=document.all.pop; else pop=document.getElementById("pop");
	b=document.body;
}

function mousePos(e) {
	netX=e.pageX;
	netY=e.pageY;
}

function popPrzesun(pX, pY) {
	initpop();
	if(pop.style.visibility!='visible') return;
	if(IE) {myszX=event.clientX; myszY=event.clientY;}
		else {myszX=netX-b.scrollLeft; myszY=netY-b.scrollTop;}

	tempX=myszX+pX;
	if(tempX<0) tempX=0;
	tmp=b.clientWidth-myszX-pX-pop.offsetWidth-20;
	if(tmp<0) {tempX+=tmp; if(tempX<0) tempX=0;}
	pop.style.left=b.scrollLeft+tempX+"px";

	tempY=myszY+pY;
	if(tempY<0) tempY=0;
	tmp=b.clientHeight-myszY-pY-pop.offsetHeight-15;
	if(tmp<0) {
		tmp=myszY-15-pop.offsetHeight;
		if(tmp>=0) tempY=tmp;
	}
	pop.style.top=b.scrollTop+tempY+"px";
}

function popPokaz(pX, pY, src) {
	initpop();
	pop.style.visibility='visible';
	pop.innerHTML=src;
	popPrzesun(pX,pY);
}

function popZamknij() {
	initpop();
	pop.style.visibility='hidden';
	pop.innerHTML='';
	pop.style.left=0;
	pop.style.top=0;
}

function popKom(tresc) {
	text="<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tr><td colspan=\"3\" height=\"1\" bgcolor=\"#262626\"><img src=\"/gfx/p.gif\" width=\"1\" height=\"1\" alt=\"\"/></td></tr><tr><td width=\"1\" bgcolor=\"#262626\"><img src=\"/gfx/p.gif\" width=\"1\" height=\"1\" alt=\"\"/></td><td style=\"background: #5F5F5F url('/gfx/pop/popbg.gif') repeat-x bottom;padding:3px;color:#9F9F9F;font-family:Verdana;font-size:9px;\">"+tresc+"</td><td width=\"1\" bgcolor=\"#262626\"><img src=\"/gfx/p.gif\" width=\"1\" height=\"1\" alt=\"\"/></td></tr><tr><td colspan=\"3\" height=\"1\" bgcolor=\"#262626\"><img src=\"/gfx/p.gif\" width=\"1\" height=\"1\" alt=\"\"/></td></tr></table>";

	popPokaz(20,20,text);
}

function popLinkPrzesun() {
	popPrzesun(20,20);
}

function popSrodekPrzesun() {
	popPrzesun(-90,20);
}





function mniej() {
	$('popav').style.display="none";
	$('popav2').style.display="none";
	$('popavbgp').style.display="none";
	$('popavbgpu').style.display="none";
}


version=ie=0;
if (navigator.appVersion.indexOf("MSIE")!=-1){
	temp=navigator.appVersion.split("MSIE");
	ie=1;
	version=parseFloat(temp[1]);
}

function popav(elemID,nick,onof,status) {

//		$(elemID).style.left=eval($('dastart').offsetLeft+'+596+'+ielewo)+'px';
//		$(elemID).style.top=$('dastart').offsetTop+'px';

//	alert(eval($(elemID).offsetLeft+ielewo)+'px');
//alert(eval(elemID.offsetLeft+ielewo));
//alert(elemID.offsetTop);


pos=findPos(elemID);

    var offsetTrail = elemID;
    var offsetLeft = 0;
    var offsetTop = 0;
	var obl = 0;
    while (offsetTrail) {
        offsetLeft += offsetTrail.offsetLeft;
        offsetTop += offsetTrail.offsetTop;
        offsetTrail = offsetTrail.offsetParent;
    }
    if (navigator.userAgent.indexOf("Mac") != -1 && 
        typeof document.body.leftMargin != "undefined") {
        offsetLeft += document.body.leftMargin;
        offsetTop += document.body.topMargin;
    }
	offsetTop=pos[0];
	offsetLeft=pos[1];

//alert(offsetTop+' x '+offsetLeft+"\n\n"+pos[0]+' x '+pos[1]);

	if(typeof window.opera !== "undefined") {
		operatop=42
		operaleft=3;
	} else {
		operatop=false;
		operaleft=false;
	}

	$("popav2").style.display="block";
	$("popav2").innerHTML='<a href="http://'+nick+'.digart.pl">'+elemID.innerHTML+'</a>';
	$("popav2").style.top=eval(offsetTop-39+operatop)+'px';
	$("popav2").style.left=eval(offsetLeft+operaleft)+'px';

	$("popavbgp").style.display="block";
	$("popavbgp").style.top=eval(offsetTop-42+operatop)+'px';
	$("popavbgp").style.left=eval(offsetLeft-3+operaleft)+'px';

	$("popav").style.display="block";
	$("popav").style.top=eval(offsetTop-35+operatop)+'px';
	$("popav").style.left=eval(offsetLeft+60+operaleft)+'px';

	$("popavbgpu").style.display="block";
	$("popavbgpu").style.top=eval(offsetTop-57+operatop)+'px';
	$("popavbgpu").style.left=eval(offsetLeft-6+operaleft)+'px';



	$("popav").innerHTML="<div style=\"margin-top:-2px;\"><div  style=\"font-family:Arial,sans-serif;font-size:13px;color:whitesmoke;width:158px;float:left;\">"+status+nick+"</div><img style=\"float:left;\" src=\"/gfx/pop/"+onof+".gif\" width=\"11\" height=\"13\" align=\"middle\" style=\"left:100px;\"><font style=\"font-size:7pt;\"><br/><img src=\"/gfx/p.gif\" width=\"1\" height=\"13\"/><br/><a href=\"http://"+nick+".digart.pl/digarty/\"><img src=\"/gfx/pop/digarty.gif\" width=\"57\" height=\"15\" align=\"middle\" alt=\"\"/></a> &nbsp;&nbsp; <a href=\"http://"+nick+".digart.pl/komentarze/\"><img src=\"/gfx/pop/komentarze.gif\" width=\"74\" height=\"14\" align=\"middle\" alt=\"\"/></a></font></div>";
}



function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curtop,curleft];
}

var preloadedimg=new Array();
var czekaj;
var naj=false;
function zoom(img,url,go) {
	clearTimeout(czekaj);

 
	imgsrc=$(img).src;
	
	
  po=$(img).src.split("/");
  
  //alert (po[8]);
  //alert (po[7]);
  //alert (po[6]);
  //alert (po[5]);
  //alert (po[4]);
  //alert (po[3]);
  //alert (po[2]);
  //alert (po[1]);
  //alert (po[0]);
  
	if(po[8]) {
		imgsrcn=po[0]+'/'+po[1]+'/'+po[2]+'/'+po[3]+'/'+po[4]+'/'+po[5]+'/'+po[6]+'/pracownicy/'+po[8];
		id=po[8].split("."); id=id[0];
	} else {
		imgsrcn=po[0]+'/'+po[1]+'/'+po[2]+'/pracownicy/'+po[4];
		id=po[4].split("."); id=id[0];
	}
  
  imgsrcn=po[0]+'/'+po[1]+'/'+po[2]+'/pracownicy/'+po[4];
		id=po[4].split("."); id=id[0];
		
	id='Tomek';
  imgsrcn='http://kkselekt.pl/pracownicy/Tomek.jpg';
  	
	//iw=$(img).width/2;
	//ih=$(img).height/2;
	//imgh=$(img).height*2;
	//imgw=$(img).width*2;
  
  //alert(iw);
  //alert(ih);
  //alert(imgh);
  //alert(imgw);
  
  iw=20;
	ih=20;
	imgh=225;
	imgw=300;
  
	if(!go) {
		czekaj=setTimeout("zoom('"+img+"','"+url+"',1)",500);
		naj=true;
	} else if(naj==true) {
		naj=false;

		if(preloadedimg[id] == 'jest') { imgsrc=imgsrcn; 
			if (version < 7 && ie == 1 && typeof window.opera == "undefined") {
				//$("popzoom").innerHTML='<img src="/gfx/p.gif" width="'+(imgw+20)+'" height="10" alt="" /><br/><img src="/gfx/p.gif" width="10" height="'+imgh+'" alt="" /><a href="'+url+'"><img src="'+imgsrcn+'" width="'+imgw+'" height="'+imgh+'" onmouseout\="zc(1);\" style="border: solid 2px black;"></a><img src="/gfx/p.gif" width="10" height="'+imgh+'" alt="" /><br><img src="/gfx/p.gif" width="'+(imgw+20)+'" height="10" alt="" />';
				$("popzoom").innerHTML='<a href="'+url+'"><img src="'+imgsrcn+'" width="'+imgw+'" height="'+imgh+'" onmouseout\="zc(1);\" style="border: solid 2px black;"></a>';
			} else {
				$("popzoom").innerHTML='<a href="'+url+'"><img src="'+imgsrcn+'" width="'+imgw+'" height="'+imgh+'" onmouseout\="zc(1);\" style="border: solid 2px black;"></a>';
				//$("popzoom").innerHTML='<img src="/gfx/pop/zoomt.png" width="'+(imgw+20)+'" height="10" alt="" /><br/><img src="/gfx/pop/zooml.png" width="10" height="'+imgh+'" alt="" /><a href="'+url+'"><img src="'+imgsrcn+'" width="'+imgw+'" height="'+imgh+'" onmouseout\="zc(1);\"></a><img src="/gfx/pop/zoomp.png" width="10" height="'+imgh+'" alt="" /><br><img src="/gfx/pop/zoomd.png" width="'+(imgw+20)+'" height="10" alt="" />';
			}
		}


		if(preloadedimg[id] != 'jest') {
			image2 = new Image();
			image2.src = imgsrcn;
			image2.onerror=function() { }
		} else {
			imgsrc=imgsrcn;
		}
		

		if(preloadedimg[id] != 'jest') {
			image2.onload=function() {
				preloadedimg[id]='jest';
				if (version < 7 && ie == 1 && typeof window.opera == "undefined") {
					//$("popzoom").innerHTML='<img src="/gfx/p.gif" width="'+(imgw+20)+'" height="10" alt="" /><br/><img src="/gfx/p.gif" width="10" height="'+imgh+'" alt="" /><a href="'+url+'"><img src="'+imgsrcn+'" width="'+imgw+'" height="'+imgh+'" onmouseout\="zc(1);\" style="border: solid 2px black;"></a><img src="/gfx/p.gif" width="10" height="'+imgh+'" alt="" /><br><img src="/gfx/p.gif" width="'+(imgw+20)+'" height="10" alt="" />';
				  $("popzoom").innerHTML='<a href="'+url+'"><img src="'+imgsrcn+'" width="'+imgw+'" height="'+imgh+'" onmouseout\="zc(1);\" style="border: solid 2px black;"></a>';
        } else {
					$("popzoom").innerHTML='<a href="'+url+'"><img src="'+imgsrcn+'" width="'+imgw+'" height="'+imgh+'" onmouseout\="zc(1);\" style="border: solid 2px black;"></a>';
          //$("popzoom").innerHTML='<img src="/gfx/pop/zoomt.png" width="'+(imgw+20)+'" height="10" alt="" /><br/><img src="/gfx/pop/zooml.png" width="10" height="'+imgh+'" alt="" /><a href="'+url+'"><img src="'+imgsrcn+'" width="'+imgw+'" height="'+imgh+'" onmouseout\="zc(1);\"></a><img src="/gfx/pop/zoomp.png" width="10" height="'+imgh+'" alt="" /><br><img src="/gfx/pop/zoomd.png" width="'+(imgw+20)+'" height="10" alt="" />';
				}
			}
		}

		pos=findPos($(img));
		$("popzoom").style.top=pos[0]-ih-10+'px';
		if(pos[1]-iw-10 < 0) {
			$("popzoom").style.left='0px';
		} else if(document.body.clientWidth < imgw+20+pos[1]) {
			$("popzoom").style.left=document.body.clientWidth-imgw-20+'px';
		} else {
			$("popzoom").style.left=pos[1]-iw-10+'px';
		}
		$("popzoom").style.visibility='visible';

	}
}

function zc(co) {
	if(naj==true || co == 1) {
		clearTimeout(czekaj);
		$("popzoom").style.visibility='hidden';
		$("popzoom").innerHTML='';
	}
	naj=false;
}
