/* ProfiSpy.pl JavaScript - Copyright (C) ProfiSpy.pl 2008-2011
 * Created by o8 / Walerian Walawski - http://o8.com.pl/
 */

// Shortcut
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"><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(\'low\')" 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('funnyNow(0.0)',540);
		setTimeout('funnyNow(0.1)',480);
		setTimeout('funnyNow(0.2)',420);
		setTimeout('funnyNow(0.3)',360);
		setTimeout('funnyNow(0.4)',300);
		setTimeout('funnyNow(0.5)',240);
		setTimeout('funnyNow(0.6)',180);
		setTimeout('funnyNow(0.7)',120);
		setTimeout('funnyNow(0.8)',60);
		setTimeout('funnyNow(0.9)',2);
	}
	if(set=='lowFast')
	{
		funny('low');
	}
	if(set=='high')
	{
		setTimeout('funnyNow(1.0)',540);
		setTimeout('funnyNow(0.9)',480);
		setTimeout('funnyNow(0.8)',420);
		setTimeout('funnyNow(0.7)',360);
		setTimeout('funnyNow(0.6)',300);
		setTimeout('funnyNow(0.5)',240);
		setTimeout('funnyNow(0.4)',180);
		setTimeout('funnyNow(0.3)',120);
		setTimeout('funnyNow(0.2)',60);
		setTimeout('funnyNow(0.1)',2);
	}
	if(set=='full')
	{
		funny('low');
		setTimeout('funny("high")',500);
	}
}
function funnyNow(value)
{
	bid('preloadTop-content').style.opacity=value;
}

// 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();
}

