/*var fotyIlosc;
window.onload = function () {
	fotyIlosc = pobierzObrazki ();
}
*/

var nInterval = 0;
var nLicznik = 0;
var nKierunek = 1;
var nZnakow;
var oEl;

function przewinPlay (el) {
	oEl = el;
	nZnakow = el.innerHTML.length;
	
	if (nInterval > 0) clearInterval (nInterval);
	if (navigator.appName.indexOf('Netscape') != -1) czas = 5;
		else czas = 20;
	nInterval = setInterval ("przewijanie()", czas);
}
function przewinStop () {
	clearInterval (nInterval);
	nLicznik = 0;
	oEl.style.left = '0px';
}
function przewijanie () {
	if (nLicznik > nZnakow*2.5) nKierunek = 0;
	if (nLicznik < 1) nKierunek = 1;
	if (nKierunek > 0) nLicznik++;
		else nLicznik--;
	oEl.style.left = -nLicznik+'px';
}

	function findPosX (obj){
		var curleft = 0;
		if (obj.offsetParent)
		{
			while (obj.offsetParent)
			{
				curleft += obj.offsetLeft
				obj = obj.offsetParent;
			}
		}
		else if (obj.x)
			curleft += obj.x;
		return curleft;
	}
	function findPosY (obj){
		var curtop = 0;
		if (obj.offsetParent)
		{
			while (obj.offsetParent)
			{
				curtop += obj.offsetTop
				obj = obj.offsetParent;
			}
		}
		else if (obj.y)
			curtop += obj.y;
		return curtop;
	}

	/*window.document.body.onlick = function (event) {
	alert (event.srcElement)
	}*/

function showPoll (el) {
	var objX = findPosX (el) - 250;
	var objY = findPosY (el) + 35;
	with (document.getElementById('poll').style) {
		top = objY + 'px';
		left = objX + 'px';
		display = 'block'
	}
}

function pollHigh (el, type, color) {
	if (type) el.style.backgroundColor = 'white';
		else el.style.backgroundColor = '#ff'+color+'33';
}

function pollVote (note,uid) {
	document.getElementById('poll').style.display = 'none';
	var rBody = window.document.body;
	var rForm = document.createElement ('form');
	rForm.setAttribute ('method', 'post');
	rForm.setAttribute ('action', '/ludzie/ocen');
	var rFormEl1 = document.createElement ('input');
	rFormEl1.setAttribute ('type', 'text');
	rFormEl1.setAttribute ('name', 'uid');
	rFormEl1.setAttribute ('value', uid);
	rForm.appendChild (rFormEl1);
	var rFormEl2 = document.createElement ('input');
	rFormEl2.setAttribute ('type', 'text');
	rFormEl2.setAttribute ('name', 'user_ocena');
	rFormEl2.setAttribute ('value', note);
	rForm.appendChild (rFormEl2);
	rBody.appendChild (rForm);
	rForm.submit ();
}

function przelaczFotke(path, bigsize)
{
	new Effect.Pulsate('glowna_fotka_div', {duration: 1.0, pulses: 1  });
	new_path = path.replace("thumb", "normal");
	$('glowna_fotka').src = new_path;
	$('glowna_fotka').alt = bigsize;
}

function pobierz_user_akcje(optPar) {
	if(!optPar) { optPar = ''; }
	script = '/_ajax/aktywnosc_'+optPar+'.php?rand='+ new Date();
	new Ajax.PeriodicalUpdater('user_action_box', script,
	{ method: 'get',
	  frequency: 3,
	  onSuccess: function(){ setTimeout("animuj_nowe();", 300); }
	});
}
	
var old_time = new Date().getTime(); 
function animuj_nowe()
{
	var act_time = $('new').getAttribute('rel');
		act_time =  act_time;
		//i = act_time-old_time;
		//$('action_box').innerHTML = act_time + '/' + old_time + '/' + i;
		//alert(act_time-old_time);
		//alert(old_time + "<=>" + act_time);
		if(act_time>old_time)
		{
	
			if($('new'))
			{
				new Effect.Pulsate('new', {duration: 1.5, pulses:3});
				//new Effect.Shake('new');
				//new Effect.Highlight('new');
				//new Effect.BlindDown('new');
				//new Effect.Grow('new');
			}
		}
	
		old_time = $('new').getAttribute('rel');
}

function displayConfirmBox(akcja, nazwa, url, ClickDiv)
{
	//new Effect.Appear('confirm_box');
	$('confirm_box').style.display = 'inline';
	//$('confirm_box').style.top = document.body.scrollTop+myHeight-400+'px';
	if(ClickDiv != null)
	{	$('confirm_box').style.top = findPosY($(ClickDiv)) + 'px';	}
	$('ajax_box_msg').innerHTML = 'Czy na pewno chcesz '+akcja+' '+nazwa+' ?<br />	<form method="POST" action="'+url+'"><input type="hidden" name="is_confirmed" value="1"><input type="submit" value="TAK">  <input type="button" onclick="new Effect.SwitchOff(\'confirm_box\'); " value="Anuluj" /></form>';

}

function search_friends( plec, wiek, miejscowosc, zdjecie)
{
	if(zdjecie == '1')
	{ zdjecie = 'tylko_z_fotka'; }
	else { zdjecie = 'wszyscy'; }
	script = 'http://www.8.pl/szukarka/szukaj/'+plec+'/'+wiek+'/'+miejscowosc+'/'+zdjecie;
	location.href = script;
}

function search_adv( plec, wiek, miejscowosc, zdjecie, woj, nick, zainteresowania)
{
	if(zdjecie == '1')
	{ zdjecie = 'tylko_z_fotka'; }
	else { zdjecie = 'wszyscy'; }
	script = 'http://www.8.pl/szukarka/zaawansowane/'+plec+'/'+wiek+'/'+miejscowosc+'/'+zdjecie+'/'+woj+'/'+nick+'/'+zainteresowania;
	location.href = script;
}

function radioVal(el, radioGroup)
{
	var res = $(el).getInputs('radio', radioGroup).find(function(re) {return re.checked;});
	if(res != null) {
		return $F(res);
	} 
	else {
		return "";
	}	
}

function get_records(load_div, module, start, orderby, order)
{
	script = '_ajax/'+module+'.php';
	pars = 'start='+start+'&orderby='+orderby+'&order='+order;
	new Ajax.Updater(load_div, script,
	{ 
	  method: 'post', parameters: pars,
	  onLoading: function(){ $('loading').style.display = 'inline'; },
	  onSuccess: function(){ $('loading').style.display = 'none'; }
	});
}

function sendFormContact(nick, email, temat, tresc)
{
	script = '../_ajax/send_contact_form.php';
  	var pars = 'hesk_name=' + nick + '&hesk_email=' + email + '&hesk_subject=' + temat + '&hesk_message=' + tresc +'&hesk_priority=2&hesk_category=16&kolektyw=osemka' ;
  	new Ajax.Updater('info',
		script, 
		{
			method: 'post',
			parameters: pars,
			onLoading: function(){ $('loading').style.display = 'inline'; },
			onComplete: function(){ $('loading').style.display = 'none'; new Effect.Highlight('info',{startcolor:'#99CCFF', endcolor:'#FFFFFF', duration: 2.0}); }
		});	
}

function sprawdz_alias(alias,hash)
{
	if(alias != '')
	{
		script = '/_ajax/zaloz_alias.php?alias='+alias+'&hash='+hash;
		new Ajax.Updater('info', script,
		{ 
		  onLoading: function(){ $('loading').style.display = 'inline'; },
		  onSuccess: function(){ $('loading').style.display = 'none'; new Effect.Highlight('info',{startcolor:'#99CCFF', endcolor:'#FFFFFF', duration: 2.0}); }
		});
	}
}

function findPosX(obj){
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
	curleft += obj.x;
	return curleft;
}

function findPosY(obj){
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
	curtop += obj.y;
	return curtop;
}
	
function showHint (text, obj) {

//	alert (obj.getAttribute('title'));
	$('hint_content').innerHTML = text;
	// ustawienie hintu
	var posnX = findPosX (obj);
	var posnY = findPosY (obj);
	
	winSizeW = document.body.offsetWidth;
	
	if ((posnX+150) > winSizeW)
	{
		with ($('hint_content').style) {
		left = (posnX-200)+'px';
		top = (posnY+30)+'px';
		display = 'block';
		}
	} 
	else {

	with ($('hint_content').style) {
	left = (posnX+30)+'px';
	top = (posnY+30)+'px';
	display = 'block';
	
	}	
		}
		
}

function hideHint () {
	with ($('hint_content').style) {
		display = 'none';
	}
}

function zaznacz_wszystkie(thisForm)
{
	for (i = 0; i < thisForm.zaznacz_id.length; i++)
	{
		thisForm.zaznacz_id[i].checked=true
	}
}

function odznacz_wszystkie(thisForm)
{
	for (i = 0; i < thisForm.zaznacz_id.length; i++)
	{
		thisForm.zaznacz_id[i].checked=false
	}
} 

function implodeOptions(thisForm)
{
	var ideki = '';
	for (i = 0; i < thisForm.zaznacz_id.length; i++)
	{
		if(thisForm.zaznacz_id[i].checked == true)
		{
			ideki += thisForm.zaznacz_id[i].value+',';
		}
	}
	return ideki;
}

var bigPic = new Image ();

function showBigPicLoaded () {
	ww = bigPic.width;
	hh = bigPic.height;
	wycentrujPrzesun ('big_pic', ww+10, hh);
	with (document.getElementById('big_pic').style) {
		width = ww+'px';
		height = hh+'px';
		backgroundImage = 'url('+bigPic.src+')';
		display = 'block'
	}
}

function showBigPic (pic) {
	pelnyEkran ('curtain');
	bigPic.src = pic;
	if (bigPic.complete) showBigPicLoaded ();
		else bigPic.onload = showBigPicLoaded;
}

function wycentruj (obj,ww,hh) {
		var przesuniecie = document.documentElement.scrollTop | document.body.scrollTop;
		oszer =  ww;
		owys = hh;
		if (document.all) bwys = document.body.clientHeight;
		else bwys = document.documentElement.clientHeight;
		wspY = Math.round(bwys/2) - Math.round(owys/2);
		wspX = Math.round(document.body.clientWidth/2) - Math.round(oszer/2);
		with (document.getElementById(obj).style) {
			left = wspX + 'px';
			top = wspY + przesuniecie + 'px';
			zIndex = '999';
		} 	
}

// centruje i uwzglednia przewiniecie okna w dol
function wycentrujPrzesun (obj, ww, hh) {
		var przesuniecie = document.documentElement.scrollTop || document.body.scrollTop;
		oszer =  ww;
		owys = hh;
		if (navigator.appName.indexOf('Explorer') != 0) bwys = document.body.clientHeight;
		else bwys = document.documentElement.clientHeight;
		//wspY = Math.round(bwys/2) - Math.round(owys/2);
		wspY = 50;
		wspX = Math.round(document.body.clientWidth/2) - Math.round(oszer/2);
		with (document.getElementById(obj).style) {
			left = wspX + 'px';
			top = wspY + przesuniecie + 'px';
			zIndex = '999';
		}
}
		
function getPageSizeWithScroll () {
	if (window.innerHeight && window.scrollMaxY) {// Firefox
		yWithScroll = window.innerHeight + window.scrollMaxY;
		xWithScroll = window.innerWidth + window.scrollMaxX;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		yWithScroll = document.body.scrollHeight;
		xWithScroll = document.body.scrollWidth;
	} else { // works in Explorer 6 Strict, Mozilla (not FF) and Safari
		yWithScroll = document.body.offsetHeight;
		xWithScroll = document.body.offsetWidth;
  	}
	arrayPageSizeWithScroll = new Array(xWithScroll,yWithScroll);
	//alert( 'The height is ' + yWithScroll + ' and the width is ' + xWithScroll );
	return arrayPageSizeWithScroll;
}

function pelnyEkran (obj) {
	if (document.all) bwys = document.body.clientHeight;
	else bwys = document.documentElement.clientHeight;
	pagesize = getPageSizeWithScroll();
	bwys = pagesize[1];
	bszer = document.body.clientWidth;		
	with (document.getElementById(obj).style) {
		width = bszer + 'px';
		height = bwys + 'px';
		top = '0px';
		left = '0px';
		zIndex = '998';
		display = 'block'
	}	
}

function podswietlKomunikat()
{
	new Effect.Highlight('info',{startcolor:'#ff9900', duration: 3.0});	
}


