
var objectMoving = false;
var objectOutside = false;

function addComment()
{
	// Captcha
	captcha_id = $('captcha_id').value;
	captcha = $('captcha').value;
	
	// Dane formularza
	idimage_src = $('idimage_src').value;
	image_comments_author = $('image_comments_author').value;
	image_comments_title = $('image_comments_title').value;
	image_comments_description = $('image_comments_description').value;
	
	new Ajax.Request('/fake/addimgcomment',
			{
				method		:	'post',
				parameters	:	{
					'captcha_id'				:	captcha_id,
					'captcha'					:	captcha,
					'idimage_src'				:	idimage_src,
					'image_comments_author'		:	image_comments_author,
					'image_comments_title'		:	image_comments_title,
					'image_comments_description':	image_comments_description
				},
				onSuccess	:	function(transport)
				{
					alert(transport.responseText);
					location.reload();
				},
				onFailure	:	function(transport)
				{
					alert('Błąd połączenia z bazą danych. Prosimy, spróbuj ponownie później');
				}
			}
	);
}

function addCommentNews()
{
	// Captcha
	captcha_id = $('captcha_id').value;
	captcha = $('captcha').value;
	
	// Dane formularza
	idnews = $('idnews').value;
	news_comments_author = $('news_comments_author').value;
	news_comments_title = $('news_comments_title').value;
	news_comments_description = $('news_comments_description').value;
	
	new Ajax.Request('/fake/addnewscomment',
			{
				method		:	'post',
				parameters	:	{
					'captcha_id'				:	captcha_id,
					'captcha'					:	captcha,
					'idnews'					:	idnews,
					'news_comments_author'		:	news_comments_author,
					'news_comments_title'		:	news_comments_title,
					'news_comments_description'	:	news_comments_description
				},
				onSuccess	:	function(transport)
				{
					alert(transport.responseText);
					location.reload();
				},
				onFailure	:	function(transport)
				{
					alert('Błąd połączenia z bazą danych. Prosimy, spróbuj ponownie później');
				}
			}
	);
}

function moveToSite(obID)
{
	if(!objectOutside)
	{
		if(objectMoving == false)
		{
			objectMoving = true;
			new Effect.Move(obID, { x: -292, y: 0, mode: 'relative', queue: { position: 'end', scope: 'fbscope'}});
			objectMoving = false;
			objectOutside = true;
			return false;
		}
		else
		{
			return false;
		}
	}
	else
	{
		return false;
	}
}

function moveFromSite(obID)
{
	if(objectOutside == true)
	{
		if(!objectMoving)
		{
			objectMoving = true;
			new Effect.Move('community-plugs', { x: 292, y: 0, mode: 'relative', queue: { position: 'end', scope: 'fbscope'}}); 
			objectMoving = false;
			objectOutside = false;
			return false;
		}
		else
		{
			return false;
		}
	}
	else
	{
		return false;
	}
}

var url = location.href;
var baseURL = url.substring(0, url.indexOf('/', 14));

function obrazek(nr, nr2)
{    
	backside = $('background-image2');
	backside.style.backgroundImage = 'url('+baseURL+'/public/images/layout/tlo'+nr2+'.png)';
	
	element = $('background-image');
	element.style.backgroundImage = 'url('+baseURL+'/public/images/layout/tlo'+nr+'.png)';
}

var lock = -1;
var i = 1;
var ilosc = 4;
var time = 12000;

function tlo()
{
	if(lock==-1)
	{
		if((i>ilosc) || (i == 1)) 
		{
			i = 1;	// resetuj licznik gdy dojdzie do końca
			nr2 = ilosc;
		}
		else nr2 = i-1;
		element = $('background-image');		
		lock = setTimeout('obrazek('+i+', '+nr2+'); element.hide(); element.appear({ duration: 3.0 }); i++; lock=-1; tlo()', time);
	}
}

// preload images
pic1 = new Image(1250,318);
pic1.src = baseURL+'/public/images/layout/tlo.png';

pic2 = new Image(1250,318);
pic2.src = baseURL+'/public/images/layout/tlo1.png';

pic3 = new Image(1250,318);
pic3.src = baseURL+'/public/images/layout/tlo2.png';

pic4 = new Image(1250,318);
pic4.src = baseURL+'/public/images/layout/tlo3.png';

pic5 = new Image(1250,318);
pic5.src = baseURL+'/public/images/layout/tlo4.png';
