// Let's make document.getElementById shorter ;-) (by-id)
function bid(name)
{
	return document.getElementById(name);
}

// <body> onload
function bodyStart()
{
	putTop();
	toolTip();
}

// *Top* HTML
function putTop()
{
	box=bid('tb');
	box.style.padding='0';
	box.innerHTML='<div id="preloadTop"><div id="preloadTop-content"><img src="download/design-2.0-top.jpg" alt="ProfiSpy" usemap="#map"><map name="map"><!-- #$-:Image map file created by GIMP Image Map plug-in --><!-- #$-:GIMP Image Map plug-in by Maurits Rijk --><!-- #$-:Please do not edit lines starting with "#$" --><!-- #$VERSION:2.3 --><!-- #$AUTHOR:Walerian Walawski --><area shape="poly" coords="101,147,93,104,120,101,127,110,150,104,152,107,169,98,179,102,185,85,199,81,204,82,213,81,216,87,226,78,240,76,247,85,311,73,304,121,286,125,283,111,266,118,268,130,252,132,250,116,231,126,222,125,187,131,159,137,150,127,145,139,131,141,128,131,115,134,114,144" onmouseover="funny(\'lowFast\');" onmouseout="funny(\'high\');" href="/"><area shape="poly" coords="495,80,514,113,521,118,526,130,544,127,605,130,607,111,585,101,601,69,626,53,622,47,633,40,620,11,604,22,592,20,574,30,548,26,523,45,517,61,512,67,511,67" href="o-profispy"><area shape="poly" coords="651,111,651,126,713,126,707,111,703,111,728,86,728,53,743,41,739,37,752,27,733,8,723,21,697,22,634,23,635,32,637,45,633,50,633,92,660,106" href="zamow"><area shape="poly" coords="732,94,751,116,761,114,761,127,800,127,797,112,823,100,836,75,837,43,841,36,852,23,835,4,819,18,810,17,789,14,762,15,760,24,746,40,742,59,739,78" href="faq"><area shape="poly" coords="855,113,865,114,866,127,926,127,925,113,940,113,939,9,853,9,856,23,851,35,851,107" href="kontakt"></map></div></div>';
}

// Tooltip
function toolTip()
{
	// Add :->
	for(var i=0,d,dE,D=document,span;d=D.getElementsByTagName('*')[i++];)
	{
		if(d.getAttribute('title'))
		{
			d.onmouseover=function(e)
			{
				var e=e||event;
				box=D.createElement('span');
				box.id='tooltip';
				box.appendChild(D.createTextNode(this.getAttribute('title')));
				with(box.style)
				{
					position='absolute';
					top=e.clientY+(dE=D.documentElement).scrollTop+15+'px';
					left=e.clientX+dE.scrollLeft+15+'px';
				}
				// Old box? (Gecko [maybe not only] bug) - part 1
				if(this.title!=null&&this.title!='')
				{
					this.title_ex=this.title;
				}
				this.title='';
				D.body.appendChild(box);
			}
			d.onmouseout=function()
			{
				this.title=this.title_ex;
				D.body.removeChild(box);
				// Old box? (Gecko [maybe not only] bug) - part 2
				if(bid('tooltip')!=null)
				{
					D.body.removeChild(bid('tooltip'));
				}
			}
		}
	}
}

// Funny top efect ;-)
function funny(set)
{
	if(set=='low')
	{
		setTimeout('bid("preloadTop-content").style.opacity=0.0;',1000);
		setTimeout('bid("preloadTop-content").style.opacity=0.1;',900);
		setTimeout('bid("preloadTop-content").style.opacity=0.2;',800);
		setTimeout('bid("preloadTop-content").style.opacity=0.3;',700);
		setTimeout('bid("preloadTop-content").style.opacity=0.4;',600);
		setTimeout('bid("preloadTop-content").style.opacity=0.5;',500);
		setTimeout('bid("preloadTop-content").style.opacity=0.6;',400);
		setTimeout('bid("preloadTop-content").style.opacity=0.7;',300);
		setTimeout('bid("preloadTop-content").style.opacity=0.8;',200);
		setTimeout('bid("preloadTop-content").style.opacity=0.9;',100);
	}
	if(set=='lowFast')
	{
		setTimeout('bid("preloadTop-content").style.opacity=0.0;',100);
		setTimeout('bid("preloadTop-content").style.opacity=0.1;',90);
		setTimeout('bid("preloadTop-content").style.opacity=0.2;',80);
		setTimeout('bid("preloadTop-content").style.opacity=0.3;',70);
		setTimeout('bid("preloadTop-content").style.opacity=0.4;',60);
		setTimeout('bid("preloadTop-content").style.opacity=0.5;',50);
		setTimeout('bid("preloadTop-content").style.opacity=0.6;',40);
		setTimeout('bid("preloadTop-content").style.opacity=0.7;',30);
		setTimeout('bid("preloadTop-content").style.opacity=0.8;',20);
		setTimeout('bid("preloadTop-content").style.opacity=0.9;',10);
	}
	if(set=='high')
	{
		setTimeout('bid("preloadTop-content").style.opacity=1.0;',200);
		setTimeout('bid("preloadTop-content").style.opacity=0.9;',190);
		setTimeout('bid("preloadTop-content").style.opacity=0.8;',180);
		setTimeout('bid("preloadTop-content").style.opacity=0.7;',170);
		setTimeout('bid("preloadTop-content").style.opacity=0.6;',160);
		setTimeout('bid("preloadTop-content").style.opacity=0.5;',150);
		setTimeout('bid("preloadTop-content").style.opacity=0.4;',140);
		setTimeout('bid("preloadTop-content").style.opacity=0.3;',130);
		setTimeout('bid("preloadTop-content").style.opacity=0.2;',120);
		setTimeout('bid("preloadTop-content").style.opacity=0.1;',110);
	}
	if(set=='full')
	{
		setTimeout('bid("preloadTop-content").style.opacity=1.0;',2000);
		setTimeout('bid("preloadTop-content").style.opacity=0.9;',1900);
		setTimeout('bid("preloadTop-content").style.opacity=0.8;',1800);
		setTimeout('bid("preloadTop-content").style.opacity=0.7;',1700);
		setTimeout('bid("preloadTop-content").style.opacity=0.6;',1600);
		setTimeout('bid("preloadTop-content").style.opacity=0.5;',1500);
		setTimeout('bid("preloadTop-content").style.opacity=0.4;',1400);
		setTimeout('bid("preloadTop-content").style.opacity=0.3;',1300);
		setTimeout('bid("preloadTop-content").style.opacity=0.2;',1200);
		setTimeout('bid("preloadTop-content").style.opacity=0.1;',1100);
		setTimeout('bid("preloadTop-content").style.opacity=0.0;',1000);
		setTimeout('bid("preloadTop-content").style.opacity=0.1;',900);
		setTimeout('bid("preloadTop-content").style.opacity=0.2;',800);
		setTimeout('bid("preloadTop-content").style.opacity=0.3;',700);
		setTimeout('bid("preloadTop-content").style.opacity=0.4;',600);
		setTimeout('bid("preloadTop-content").style.opacity=0.5;',500);
		setTimeout('bid("preloadTop-content").style.opacity=0.6;',400);
		setTimeout('bid("preloadTop-content").style.opacity=0.7;',300);
		setTimeout('bid("preloadTop-content").style.opacity=0.8;',200);
		setTimeout('bid("preloadTop-content").style.opacity=0.9;',100);
	}
}

// Find
function find()
{
	var wtf=document.getElementById('find').value;
	if(wtf)
	{
		parent.location.href='wyszukiwarka-'+wtf+'-0';
	}
	else
	{
		alert('Wpisz słowo lub frazę dla wyszukiwania.\nNie można szukać niczego...chyba, że wpiszesz "niczego" ;-)');
	}
}

// secondsAgo
function secondsAgo(startingDate)
{
	this.currentTime=new Date();
	this.startingDate=new Date(startingDate);
	this.timesup=false;
	this.currentTime.setSeconds(this.currentTime.getSeconds()+1);
	var reg=/(.*)\./;
	var result=reg.exec(timediff=(this.currentTime-this.startingDate)/1000);
	document.getElementById('secondsAgo').innerHTML=result[1];
}

// Cookies
function getCookieVal(offset)
{
	var endstr = document.cookie.indexOf (";", offset);
	if (endstr == -1)
	endstr = document.cookie.length;
	return unescape(document.cookie.substring(offset, endstr));
}
function getCookie(name)
{
	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	while (i < clen)
	{
		var j = i + alen;
		if (document.cookie.substring(i, j) == arg)
		return getCookieVal (j);
		i = document.cookie.indexOf(" ", i) + 1;
		if (i == 0)
		break;
	}
	return null;
}
function setCookie(name,value)
{
	var cdate=new Date();
	cdate.setTime(cdate.getTime()+1000*60*60*24*7);
	document.cookie=name+'='+escape(value)+";expires="+cdate.toGMTString();
}
