/* Zarządzanie wykonywaniem skryptow po doczytaniu strony */
var EditoStart =
{
	functions: [],
	functionsFlash: [],
	Add: function(f)
	{
		$.merge(EditoStart.functions, [f]);
	},
	AddFlash: function(f)
	{
		$.merge(EditoStart.functionsFlash, [f]);
	},
	init: function()
	{
		$.map(EditoStart.functions, function(n) { n(); });
	},
	initFlash: function()
	{
		$.map(EditoStart.functionsFlash, function(n) { n(); });
	}

}

$(document).ready(function(){
	EditoStart.init();
});

$(window).bind('load', function(){
	EditoStart.initFlash();
});


function insertActiveX(html)
{
	document.write(html);
}


/* Galeria zdjec */
var EditoImg = new Object();
EditoImg.Keyword = new String("editoimg");
EditoImg.BorderSize = 1;
EditoImg.Index = 0;
EditoImg.Images = new Array();

EditoImg.init = function()
{
	var anchors = document.getElementsByTagName('a');
	
	for(var i=0; i<anchors.length; i++)
	{
		var anchor = anchors[i];
		var rel = anchor.getAttribute('rel');
		
		if(anchor.getAttribute('href') && rel && rel.toLowerCase().match(EditoImg.Keyword))
		{
			anchor.onclick = EditoImg.Click;
		}
	}
	
	var html = '';
	html += '<div id="EditoImg$Overlay" class="PopupOverlay" style="display:none;"></div>';
	html += '<iframe src="/szablony/blank.html" id="EditoImg$Background" style="display:none;"></iframe>';
	html += '<table cellspacing="0" cellpadding="0" border="0" id="EditoImg$Panel" class="Popup" style="display:none;">';
	html += '	<tr>';
	html += '		<td id="EditoImg$Container" class="ImageContainer">';
	html += '			<img id="EditoImg$Preview" class="Preview"/>';
	html += '			<div id="EditoImg$Loader" class="Loader"></div>';
	html += '		</td>';
	html += '	</tr>';
	html += '	<tr id="EditoImg$Bottom"><td>';
	html += '		<table width="100%" cellspacing="0" cellpadding="0" border="0">';
	html += '			<tr>';
	html += '				<td id="EditoImg$Prev" class="Prev"><div></div></td>';
	html += '				<td id="EditoImg$Caption" class="Caption"></td>';
	html += '				<td id="EditoImg$Next" class="Next"><div></div></td>';
	html += '			</tr>';
	html += '		</table>';
	html += '	</td></tr>';
	html += '</table>';
	
	var body = document.getElementsByTagName("body")[0];
	var span = document.createElement("span");
	span.innerHTML = html;
	body.appendChild(span);
	
	EditoImg.Item("Prev").onclick = EditoImg.PrevImage;
	EditoImg.Item("Next").onclick = EditoImg.NextImage;
}

EditoImg.Item = function(id)
{
	return document.getElementById("EditoImg$" + id);
}

EditoImg.Screen = function()
{
	if( typeof( window.innerWidth ) == 'number' )
	{
		//Non-IE
		return [window.innerWidth, window.innerHeight];
	}
	else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) )
	{
		//IE 6+ in 'standards compliant mode'
		return [document.documentElement.clientWidth, document.documentElement.clientHeight];
	}
	else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) )
	{
		//IE 4 compatible
		return [document.body.clientWidth, document.body.clientHeight];
	}
}

EditoImg.Scroll = function()
{
	if( typeof( window.pageYOffset ) == 'number' )
	{
		//Netscape compliant
		return [window.pageXOffset, window.pageYOffset];
	}
	else if( document.documentElement && ( typeof(document.documentElement.scrollLeft) != 'undefined' || typeof(document.documentElement.scrollTop) != 'undefined' ) )
	{
		//IE6 standards compliant mode
		return [document.documentElement.scrollLeft, document.documentElement.scrollTop];
	}
	else if( document.body && ( typeof(document.body.scrollLeft) != 'undefined' || typeof(document.body.scrollTop) != 'undefined' ) )
	{
		//DOM compliant
		return [document.body.scrollLeft, document.body.scrollTop];
	}
}

EditoImg.Click = function()
{
	EditoImg.Images = new Array();
	EditoImg.Index = 0;
	EditoImg.Navigators(false);
	
	if(this.getAttribute('rel') != EditoImg.Keyword)
	{
		var counter = 0;
		var anchors = document.getElementsByTagName('a');
		
		for(var i=0; i<anchors.length; i++)
		{
			var anchor = anchors[i];
			var rel = anchor.getAttribute('rel');
			
			if(anchor.getAttribute('href') && rel == this.getAttribute('rel'))
			{
				EditoImg.Images[EditoImg.Images.length] = anchor;
				
				if(this == anchor)
				{
					EditoImg.Index = counter;
				}
				
				counter++;
			}
		}
		
		EditoImg.Navigators(true);
	}
	
	EditoImg.Show(this, EditoImg.Images);
	
	return false;
}

EditoImg.Show = function(imgLink, images)
{
	EditoImg.Item("Preview").style.display = "none";
	EditoImg.Item("Bottom").style.display = "none";
	EditoImg.Item("Loader").style.display = "";
	
	EditoImg.Item("Container").style.width = "500px";
	EditoImg.Item("Container").style.height = "400px";
	EditoImg.Item("Panel").style.width = "500px";
	EditoImg.Item("Panel").style.height = "400px";
	EditoImg.Item("Panel").style.position = "absolute";
	EditoImg.Item("Panel").style.display = "";
	EditoImg.ChangePosition();
	
	var img = new Image();
	img.onload = EditoImg.ImageLoad;
	img.title = imgLink.title;
	img.src = imgLink.href;
}

EditoImg.NextImage = function()
{
	EditoImg.Item("Preview").style.display = "none";
	EditoImg.Item("Loader").style.display = "";
	
	EditoImg.Index++;
	
	var img = new Image();
	img.onload = EditoImg.ImageLoad;
	img.title = EditoImg.Images[EditoImg.Index].title;
	img.src = EditoImg.Images[EditoImg.Index].href;
}

EditoImg.PrevImage = function()
{
	EditoImg.Item("Preview").style.display = "none";
	EditoImg.Item("Loader").style.display = "";
	
	EditoImg.Index--;
	
	var img = new Image();
	img.onload = EditoImg.ImageLoad;
	img.title = EditoImg.Images[EditoImg.Index].title;
	img.src = EditoImg.Images[EditoImg.Index].href;
}

EditoImg.ChangePosition = function()
{
	var screen = EditoImg.Screen();
	var scroll = EditoImg.Scroll();
	
	var offsetWidth = parseInt(EditoImg.Item("Panel").style.width);
	var offsetHeight = parseInt(EditoImg.Item("Panel").style.height);
	
	var left = ((screen[0] - offsetWidth) / 2);
	var top = ((screen[1] - offsetHeight) / 2);
	
	EditoImg.Item("Panel").style.zIndex = "100";
	EditoImg.Item("Panel").style.left = ((left > 0) ? left : 0) + "px";
	EditoImg.Item("Panel").style.top = scroll[1] + ((top > 0) ? top : 0) + "px";
	
	var overlayHeight = document.body.offsetHeight;
	if(overlayHeight < screen[1])
	{
		overlayHeight = screen[1];
	}
	if(parseInt(EditoImg.Item("Panel").style.top) + offsetHeight > overlayHeight)
	{
		overlayHeight = parseInt(EditoImg.Item("Panel").style.top) + offsetHeight;
	}
	
	if(!((document.getElementById && !document.all) || window.opera))
	{
		EditoImg.Item("Background").style.position = "absolute";
		EditoImg.Item("Background").style.zIndex = "95";
		EditoImg.Item("Background").style.left = EditoImg.Item("Panel").style.left;
		EditoImg.Item("Background").style.top = EditoImg.Item("Panel").style.top;
		EditoImg.Item("Background").style.height = offsetHeight;
		EditoImg.Item("Background").style.width = offsetWidth;
		EditoImg.Item("Background").style.display = "";
	}
	
	EditoImg.Item("Overlay").style.position = "absolute";
	EditoImg.Item("Overlay").style.zIndex = "90";
	EditoImg.Item("Overlay").style.left = "0px";
	EditoImg.Item("Overlay").style.top = "0px";
	EditoImg.Item("Overlay").style.height = overlayHeight + "px";
	EditoImg.Item("Overlay").style.display = "";
}

EditoImg.Navigators = function(visibility)
{
	var display = visibility  ? "" : "none";
	
	EditoImg.Item("Prev").style.display = display;
	EditoImg.Item("Next").style.display = display;
	
	if(visibility && EditoImg.Index == 0)
	{
		EditoImg.Item("Prev").style.display = "none";
	}
	if(visibility && EditoImg.Index == (EditoImg.Images.length - 1))
	{
		EditoImg.Item("Next").style.display = "none";
	}
}

EditoImg.ImageLoad = function()
{
	EditoImg.Item("Background").style.display = "none";
	EditoImg.Item("Panel").style.width = "";
	EditoImg.Item("Panel").style.height = "";
	
	var sWidth = parseInt(EditoImg.Item("Container").style.width);
	var sHeight = parseInt(EditoImg.Item("Container").style.height);
	
	var pWidth = EditoImg.Item("Panel").offsetWidth - sWidth;
	var pHeight = EditoImg.Item("Panel").offsetHeight - sHeight;
	
	EditoImg.Item("Container").style.width = this.width + 2 * EditoImg.BorderSize + "px";
	EditoImg.Item("Container").style.height = this.height + 2 * EditoImg.BorderSize + "px";
	EditoImg.Item("Panel").style.width = this.width + 2 * EditoImg.BorderSize + pWidth + "px";
	EditoImg.Item("Panel").style.height = this.height + 2 * EditoImg.BorderSize + pHeight + "px";
	
	EditoImg.Item("Loader").style.display = "none";
	
	EditoImg.Item("Preview").onclick = EditoImg.Close;
	EditoImg.Item("Preview").src = this.src;
	EditoImg.Item("Preview").style.display = "";
	
	EditoImg.Item("Caption").innerHTML = this.title;
	
	if(EditoImg.Images.length == 0)
	{
		EditoImg.Navigators(false);
	}
	else
	{
		EditoImg.Navigators(true);
	}
	
	if(this.title.replace(/^\s*|\s*$/g, "") != "" || EditoImg.Images.length > 0)
	{
		EditoImg.Item("Bottom").style.display = "";
	}
	
	EditoImg.ChangePosition();
}

EditoImg.Close = function()
{
	EditoImg.Item("Preview").style.display = "none";
	EditoImg.Item("Panel").style.display = "none";
	EditoImg.Item("Overlay").style.display = "none";
	EditoImg.Item("Background").style.display = "none";
}

//EditoStart.Add(EditoImg.init);


/* Pozostale skrypty */
function findObj(obj) {
	return document.getElementById(obj);
}

function preloadimages(images) {
	if (!images) {
		var images = new Array();
	}
	var img = new Array();
	for (i=0; i<images.length; i++) {
		img[i] = new Image();
		img[i].src = images[i];
	}
}

function swapImage(id, img) {
	o = findObj(id);
	if(o) {
		o.src = img;
	}
}

function SendTo(before, after, user, host, label) {
	label = label.replace(' // ', '@');
	document.write('<a' + before + 'href="mailto:' + user + '@' + host + '"' + after+'>' + label + '</a>');
}

// zdjęcie bez opisu
function showImage(src, w, h) {
	noweOkienko = null;
	if (window.screen) {
		aw = screen.availWidth;
		ah = screen.availHeight;
	} else {
		aw = 640;
		ah = 450;
	}
	if (noweOkienko==null || noweOkienko.closed) {
		ustawienia=
		"left=" + (aw-w)/2 + ","
		+"top=" + (ah-h)/2 + ","
		+"screenX=" + (aw-w)/2 + ","
		+"screenY=" + (ah-h)/2 + ","
		+"width=" + w + ","
		+"height=" + h + ","
		+"innerWidth=" + w + ","
		+"innerHeight=" + h + ","
		+"toolbar=no,"
		+"location=no,"
		+"directories=no,"
		+"status=yes,"
		+"menubar=no,"
		+"scrollbars=no,"
		+"resizable=no"
		noweOkienko = window.open("/showImage.php?src="+src, 'obrazek', ustawienia);
	}
	try {
		noweOkienko.focus();
	}
	catch (e) {
	}
}

// zdjęcie z opisem
function showOImage(src, w, h, opis) {
	noweOkienko = null;
	if (window.screen) {
		aw = screen.availWidth;
		ah = screen.availHeight;
	} else {
		aw = 640;
		ah = 450;
	}
	if (noweOkienko==null || noweOkienko.closed) {
		w = w + 32;
		oldH = h;
		h = h + 45;
		ustawienia=
		"left=" + (aw-w)/2 + ","
		+"top=" + (ah-h)/2 + ","
		+"screenX=" + (aw-w)/2 + ","
		+"screenY=" + (ah-h)/2 + ","
		+"width=" + w + ","
		+"height=" + h + ","
		+"innerWidth=" + w + ","
		+"innerHeight=" + h + ","
		+"toolbar=no,"
		+"location=no,"
		+"directories=no,"
		+"status=yes,"
		+"menubar=no,"
		+"scrollbars=yes,"
		+"resizable=no"
		noweOkienko = window.open("/showImage.php?src="+src+":"+opis, 'obrazek', ustawienia);
	}
	try {
		noweOkienko.focus();
	}
	catch (e) {
	}
}

// popup
function popUpWindow(src, w, h) {
	noweOkienko = null;
	if (window.screen) {
		aw = screen.availWidth;
		ah = screen.availHeight;
	} else {
		aw = 640;
		ah = 450;
	}
	if (noweOkienko==null || noweOkienko.closed) {
		ustawienia=
		"left=" + (aw-w)/2 + ","
		+"top=" + (ah-h)/2 + ","
		+"screenX=" + (aw-w)/2 + ","
		+"screenY=" + (ah-h)/2 + ","
		+"width=" + w + ","
		+"height=" + h + ","
		+"innerWidth=" + w + ","
		+"innerHeight=" + h + ","
		+"toolbar=no,"
		+"location=no,"
		+"directories=no,"
		+"status=yes,"
		+"menubar=no,"
		+"scrollbars=yes,"
		+"resizable=no"
		var url = '/' + src; 
		noweOkienko = window.open(url, 'plik', ustawienia);
		
	}
	try {
		noweOkienko.focus();
	}
	catch (e) {
	}
}

// drukuj
function printWindow(src) {
	popUpWindow(src, 640, 450);
}

// base64 decode script
function decode64(input) {
	var output = "";
	var chr1, chr2, chr3 = "";
	var enc1, enc2, enc3, enc4 = "";
	var i = 0;
	var keyStr = 	"ABCDEFGHIJKLMNOP" +
					"QRSTUVWXYZabcdef" +
					"ghijklmnopqrstuv" +
					"wxyz0123456789+/" +
					"=";

	// remove all characters that are not A-Z, a-z, 0-9, +, /, or =
	var base64test = /[^A-Za-z0-9\+\/\=]/g;
	if (base64test.exec(input)) {
		alert("There were invalid base64 characters in the input text.\n" +
					"Valid base64 characters are A-Z, a-z, 0-9, '+', '/', and '='\n" +
					"Expect errors in decoding.");
	}
	input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");

	do {
		enc1 = keyStr.indexOf(input.charAt(i++));
		enc2 = keyStr.indexOf(input.charAt(i++));
		enc3 = keyStr.indexOf(input.charAt(i++));
		enc4 = keyStr.indexOf(input.charAt(i++));

		chr1 = (enc1 << 2) | (enc2 >> 4);
		chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
		chr3 = ((enc3 & 3) << 6) | enc4;

		output = output + String.fromCharCode(chr1);

		if (enc3 != 64) {
			output = output + String.fromCharCode(chr2);
		}
		if (enc4 != 64) {
			output = output + String.fromCharCode(chr3);
		}

		chr1 = chr2 = chr3 = "";
		enc1 = enc2 = enc3 = enc4 = "";

	} while (i < input.length);

	return output;
}

// rozwijanie listy wynikow w wyszukiwarce
function showResult(id) {
	$('#' + id).slideToggle('slow');
}

function limiter(obj, limit) {
	if (obj.value.length > limit) {
		obj.value = obj.value.substring(0,limit);
	}
}

// obliczanie pozostalych znakow w textarea
function limit(obj, limit, msg) {
	if (obj.value.length > limit) {
		obj.value = obj.value.substring(0,limit);
		alert(msg);
	}
}

function getCookie(name)
{
	var dc = document.cookie;
	var cname = name + "=";
	var clen = dc.length;
	var cbegin = 0;
	
	while (cbegin < clen)
	{ 
		var vbegin = cbegin + cname.length;
	
		if (dc.substring(cbegin, vbegin) == cname)
		{ 
			var vend = dc.indexOf (";", vbegin);
			if (vend == -1) vend = clen;
			return unescape(dc.substring(vbegin, vend));
		}
	
		cbegin = dc.indexOf(" ", cbegin) + 1;
	
		if (cbegin== 0) break;
	}
	
	return null;
}

function setCookie(name, value, days, path, domain, secure) 
{
	var expires = null;
	
	if(days)
	{
		expires = new Date();
		var theDay = expires.getDate();
		theDay = theDay + days;
		expires.setDate(theDay);
	}
	
	var ciacho = name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires.toGMTString() : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
    document.cookie = ciacho;
	
	// zapisanie do bazy dla zalogowanego uzytkownika
	$.post($.ajaxUrl('user', 'setcookie'), {
		'name': name,
		'value': value,
		'days': days
	});
}


/* generowanie url dla ajaxa - !! zmienna lang definiowana globalnie w szablonie !! */
$.extend({
	ajaxUrl: function (className, method, type){
		if (!type) type = 'lib'; 
		return '/ajax/' + lang + '/' + type + '/' + className + '/' + method + '/'; 
	}
});

/* ladowanie bannerow - ajax */
var bannerLoaded = new Array();
function getBanner(bannerId, domId)
{
	// zabezpieczenie przed przeladowaniem
	if (!bannerLoaded[bannerId])
	{
		$.ajax({
			type: "POST",
			url: $.ajaxUrl('banner', 'get'),
			data: 'id=' + bannerId,
			success: function(response){
				if(response.length > 0)
				{
					$('#' + domId).append(response);
					$('#' + domId).show();
				}
				bannerLoaded[bannerId] = true;
			}
		});
	}
}

/* oznaczanie blednych pol - bledy uzytkownika */
function markErrorFields(fields, className, errorField)
{
	if (!className) className = 'userErrorField';
	if (!errorField) errorField = 'userError_';
	
	for (field in fields)
	{
		$('#' + errorField + fields[field]).addClass(className);
	}
}

// male powiadomienia i bledy
function showAlert(el, msg, error, czas)
{
	el.before(
		$('<div>')
		.hide()
		.text(msg)
		.addClass(error ? 'userErrorsMini' : 'userMessagesMini')
		.fadeIn('slow')
		.animate({opacity: 1.0}, czas ? czas : 3000)
		.fadeOut('slow', function() {
			$(this).remove();
		})
	);
}


// slidery - opcje wyswietlania bloczkow
function showBlockElements(blockId, def, max)
{
	show = getCookie('block_show_' + blockId);
	if (show == null) show = def;
	if (show > max) show = max;
	
	setBlockElements(blockId, show, true);
}

function setBlockElements(blockId, show, firstLoad)
{
	$('#block_' + blockId + ' .block_row:lt(' + show + ')').show();
	$('#block_' + blockId + ' .block_row:gt(' + (show - 1) + ')').hide();
	
	$('#block_' + blockId + '_content a[rel=block_show]').removeClass('checked');
	$('#block_' + blockId + '_content a[rel=block_show]:eq(' + (show - 1) + ')').addClass('checked');

	if (!firstLoad) setCookie('block_show_' + blockId, show, 30, '/');
	
	if (!firstLoad && eyeCandy) $('#block_' + blockId + '_container').parent().find('.block').eyeCandy();
}

// opcje ustawien blokow aktualnosci
var blockList = new Array();
var blockOrder;
var blockIndex = 0;

function array_search(needle, haystack)
{
    for(var i in haystack)
    {
        if(haystack[i] == needle) return i;    
    }
    return false;
}

function addBlock(blockId)
{
	blockList[blockIndex] = blockId;
	blockIndex++;
}

function showBlocks()
{
	blockOrder = getCookie('block_order');
	if (blockOrder == null)
	{
		blockOrder = blockList;
	}
	else
	{
		blockOrder = blockOrder.split(',');
	}

	var blockListTemp = blockList.slice();
	var blockOrderTemp = new Array();
	// sprawdzenie wystepowania blokow na liscie uzytkownika
	for (var i = 0; i < blockOrder.length; i++)
	{
		exists = array_search(blockOrder[i], blockListTemp)
		if (exists !== false)
		{
			blockOrderTemp[blockOrderTemp.length] = blockOrder[i];
			// usuniecie elementu z tablicy
			blockListTemp.splice(exists, 1);
		}
	}
	// ustawienie na koniec pozostalych blokow,ktore nie wystapily na liscie
	blockOrderTemp = blockOrderTemp.concat(blockListTemp);
	
	// wyswietlenie blokow
	for (var i = 0; i < blockList.length; i++)
	{
		var blockContent = $('#block_' + blockOrderTemp[i] + '_content');
		var blockTargetContainer = $('#block_' + blockList[i] + '_container');
		if (blockOrderTemp[i] != blockList[i])
		{
			blockTargetContainer.append(blockContent);
		}
		
		blockTargetContainer.show();
	}

	blockOrder = blockOrderTemp.slice();
	setBlocksMoveImages();

	//setCookie('block_order', blockOrder.join(','), 30, '/');
}

function moveBlock(blockId, move)
{
	position = array_search(blockId, blockOrder);
	if ((move == 'up' && position <= 0) ||
		(move == 'down' && position >= blockOrder.length - 1)) return false;
		
	positionTarget = (move == 'up' ? parseInt(position) - 1 : parseInt(position) + 1);
	blockTargetId = blockOrder[positionTarget];
	var blockBaseContent = $('#block_' + blockOrder[position] + '_content');
	var blockTargetContent = $('#block_' + blockOrder[positionTarget] + '_content');
	var blockBaseContainer = $('#block_' + blockList[position] + '_container');
	var blockTargetContainer = $('#block_' + blockList[positionTarget] + '_container');

	if (useEyeCandy) blockBaseContent.find('.block').removeEyeCandy();
	
	blockBaseContent.fadeOut("slow", function(){
		blockBaseContainer.append(blockTargetContent);
		blockTargetContainer.append(blockBaseContent);
		setBlocksMoveImages();
	}).fadeIn("slow", function(){
		if (useEyeCandy)
		{
			blockBaseContent.find('.block').eyeCandy();
			blockTargetContent.find('.block').eyeCandy();
		}
	});

	blockOrder[position] = blockTargetId;
	blockOrder[positionTarget] = blockId;
	
	setCookie('block_order', blockOrder.join(','), 30, '/');
}

function setBlocksMoveImages()
{
	$('a[rel=block_up] img').attr('src', 'images/lay/' + lang + '/slide_option_up.gif');
	$('a[rel=block_down] img').attr('src', 'images/lay/' + lang + '/slide_option_down.gif');

	$('a[rel=block_up] img:first').attr('src', 'images/lay/' + lang + '/slide_option_up_off.gif');
	$('a[rel=block_down] img:last').attr('src', 'images/lay/' + lang + '/slide_option_down_off.gif');
}

// chowanie i pokazywanie blokow (menu,opisy), wywoluj blockShowHide
function blockShowHide(blockId, hideDefault)
{
	hide = getCookie('block_hide_' + blockId);
	if (hide == null)
	{
		hide = hideDefault;
	}

	if (hide == '1')
	{
		$('#block_' + blockId + '_content').hide();
		$('#block_' + blockId + '_slide').addClass("blockShow");	
		blockBindShow(blockId);
	}
	else blockBindHide(blockId);
}
function blockBindHide(blockId)
{
	$('#block_' + blockId + '_slide').unbind();
	$('#block_' + blockId + '_slide').bind("click", function(){
		$('#block_' + blockId + '_content').slideUp("slow", function(){
			$('#block_' + blockId + '_slide').addClass("blockShow");
			setCookie('block_hide_' + blockId, '1', 30, '/');
			blockBindShow(blockId);

			if (useEyeCandy) $('#block_' + blockId).eyeCandy().nextAll('.block').eyeCandy();
		});
	});
}

function blockBindShow(blockId)
{
	$('#block_' + blockId + '_slide').unbind();	
	$('#block_' + blockId + '_slide').bind("click", function(){
		$('#block_' + blockId + '_content').slideDown("slow", function(){
			$('#block_' + blockId + '_slide').removeClass("blockShow");
			setCookie('block_hide_' + blockId, '0', 30, '/');
			blockBindHide(blockId);
			
			if (useEyeCandy) $('#block_' + blockId).eyeCandy().nextAll('.block').eyeCandy();
		});
	});
}

// chowanie i pokazywanie blokow (menu,opisy), wywoluj blockShowHide
function blockKontoShowHide(blockId, hideDefault)
{
	hide = getCookie('block_konto_hide_' + blockId);
	if (hide == null)
	{
		hide = hideDefault;
	}

	if (hide == '1')
	{
		$('#block_konto_' + blockId + '_content').hide();
		$('#block_konto_' + blockId + '_slide').addClass("blockShow");	
		blockKontoBindShow(blockId);
	}
	else blockKontoBindHide(blockId);
}

function blockKontoBindHide(blockId)
{
	$('#block_konto_' + blockId + '_slide').unbind();
	$('#block_konto_' + blockId + '_slide').bind("click", function(){
		$('#block_konto_' + blockId + '_content').slideUp("slow", function(){
			$('#block_konto_' + blockId + '_slide').addClass("blockShow");
			setCookie('block_konto_hide_' + blockId, '1', 30, '/');
			blockKontoBindShow(blockId);
			if (useEyeCandy) $('#block_konto_' + blockId).eyeCandy().nextAll('.block').eyeCandy();
		});
	});
}

function blockKontoBindShow(blockId)
{
	$('#block_konto_' + blockId + '_slide').unbind();	
	$('#block_konto_' + blockId + '_slide').bind("click", function(){
		$('#block_konto_' + blockId + '_content').slideDown("slow", function(){
			$('#block_konto_' + blockId + '_slide').removeClass("blockShow");
			setCookie('block_konto_hide_' + blockId, '0', 30, '/');
			blockKontoBindHide(blockId);
			
			if (useEyeCandy) $('#block_konto_' + blockId).eyeCandy().nextAll('.block').eyeCandy();
		});
	});
}


// ankiety
var allAnswers = new Array();
function selectAnswer(blockId, answerId)
{
	for (i = 1; i <= allAnswers[blockId]; i++)
	{
		document.getElementById('block_' + blockId + '_answer_' + i).src = 'images/lay/radio_off.gif';
	}
	document.getElementById('block_' + blockId + '_answer_' + answerId).src = 'images/lay/radio_on.gif';
	document.getElementById('block_' + blockId + '_id_odpowiedzi').value = answerId;
} 

function checkAnswers(blockId)
{
	if (!document.getElementById('block_' + blockId + '_id_odpowiedzi').value)
		return false;
	return true;
}

//rozmiar okna
function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}

//podgląd posta
function podglad(){
	post = $('#EditorArea').val();

	if($("#podglad:visible").size()==0){
		$.ajax({
			type: "POST",
			url: '/parseBBcode.php',
			data: 'post=' + post,
			dataType: "xml",
			success: function(xml){
				html = $("html", xml).text();
				$("div#podglad_all").html('<div id="podglad">'+html+'</div>');
			}
		});
	}
	else
	{
		$("#podglad").remove();
		$.ajax({
			type: "POST",
			url: '/parseBBcode.php',
			data: 'post=' + post,
			dataType: "xml",
			success: function(xml){
				html = $("html", xml).text();
				$("div#podglad_all").html('<div id="podglad">'+html+'</div>');
			}
		});
	}
}

//słownik
$(document).ready(
	function() 
	{
		$(".forumRow-slownik").hover(
			function ()
			{
				$(this).attr('class','forumRow-slownikHover');
			},
			function ()
			{
				
				$(this).attr('class','forumRow-slownik');
			} 
		);
	}
);

function pokaz_odpowiedz(){
	$("#EditorArea").css("width", "500px");
	$("#odpowiedz").slideToggle("slow");
}

//przenoszenie tematów
function okresl_temat(id_tematu, id_projektu, id_kategorii, lang){
	var html = '';
	$.ajax({
		type: "POST",
		url: '/getSubjectList.php',
		data: 'id_projektu='+id_projektu+'&id_kategorii='+id_kategorii+'&lang='+lang,
		dataType: "xml",
		success: function(xml){
					$('forum', xml).each(function(){
						html += $('nazwa', this).text() +'<ul>';
						$('dzial', this).each(function(){
							html += '<li><a href="javascript:void(0)" onclick="javascript:przekieruj(\'/'+$('prefix', xml).text()+'/go:przenies_temat,'+ id_tematu+','+$('id_dzialu', this).text() + '\')">' + $('nazwa_dzialu', this).text() +'</a></li>';
						});
						html += '</ul>'
					});
			$('body').append('<div class="overlay" onclick="javascript:ukryj_dzialy_forum(this)"></div>'+
				'<div id="dzialy_forum">'+
					'<div class="zolta_ramka_t">'+
						'<div class="zolta_ramka_r">'+
							'<div class="zolta_ramka_b">'+
								'<div class="zolta_ramka_l">'+
									'<div class="zolta_ramka_tl">'+
										'<div class="zolta_ramka_tr">'+
											'<div class="zolta_ramka_br">'+
												'<div class="zolta_ramka_bl ver1">'+
													html+
					'</div></div></div></div></div></div></div></div>'+
				'</div>');
				
			var pathsize = getPageSize();
			$("div.overlay").css('height', pathsize[1] +'px');
			$('div.overlay').css('width', pathsize[2] +'px');
		}
	});
}

//przekierowanie z potwierdzeniem
function przekieruj(link){
	var klik=confirm("Czy napewno chcesz przenieść wybrany temat?");
	
	if(klik==true){
		document.location.href=link;
	}
	else{
		return false;
	}
}

//ukrywanie działów forum
function ukryj_dzialy_forum(id){
	$(id).remove();
	$("div#dzialy_forum").remove();
}

//Pobieranie listy tematów, działów i forów
function pokaz_liste_tematow(id, id_projektu, id_kategorii, lang){
	var go = $("#szukaj").val();
	
	if(go != undefined){
		//Dodanie obrazka postępu
		$('body').append('<img id="oczekiwanie" src="images/loading_black2.gif" alt="oczekiwanie"/>');
	
		$("div#dzialy_forum").remove();
		$("div#oczekiwanie").remove();
		var html = '';
		$.ajax({
			type: "POST",
			url: '/getPostList.php',
			data: 'id_postu='+id+'&id_projektu='+id_projektu+'&id_kategorii='+id_kategorii+'&lang='+lang+'&lookfor='+go,
			dataType: "xml",
			success: function(xml){
				if($('info', xml).text() != ''){
					html = $('info', xml).text();
				}
				else{
					$('forum', xml).each(function(){
						html += '<b>'+$('nazwa', this).text()+'</b>' +'<ul>';
						
						$('dzial', this).each(function(){
							html += '<li>' + $('nazwa_dzialu', this).text() +'<ul>';
							
							$('temat', this).each(function(){
								html += '<li><a href="/'+$('prefix', xml).text()+'/go:przenies_post:'+id+':'+$('id_tematu', this).text()+'" onclick="javascript:confirm(\'Czy napewno chcesz przenieść wybrany temat?\')">' + $('nazwa_tematu', this).text() +'</a></li>';
							});
							html += '</ul></li>'
						});
						
						html += '</ul>'
					});
				}
				$('body').append(
					'<div id="dzialy_forum">'+
						'<div class="zolta_ramka_t">'+
							'<div class="zolta_ramka_r">'+
								'<div class="zolta_ramka_b">'+
									'<div class="zolta_ramka_l">'+
										'<div class="zolta_ramka_tl">'+
											'<div class="zolta_ramka_tr">'+
												'<div class="zolta_ramka_br">'+
													'<div class="zolta_ramka_bl ver1">'+
														html+
						'</div></div></div></div></div></div></div></div>'+
					'</div>');
				var pathsize = getPageSize();
				$("div.overlay").css('height', pathsize[1] +'px');
				$('div.overlay').css('width', pathsize[2] +'px');
				$("img#oczekiwanie").remove();
			}
		});
	}
	else{
		$('body').append('<div class="overlay" onclick="javascript:ukryj_dzialy_forum(this)"></div>'+
							'<div id="dzialy_forum">'+
								'<div class="zolta_ramka_t">'+
									'<div class="zolta_ramka_r">'+
										'<div class="zolta_ramka_b">'+
											'<div class="zolta_ramka_l">'+
												'<div class="zolta_ramka_tl">'+
													'<div class="zolta_ramka_tr">'+
														'<div class="zolta_ramka_br">'+
															'<div class="zolta_ramka_bl ver2">'+
																'<form method="post" action="" onsubmit="javascript:pokaz_liste_tematow(\''+id+'\', \''+id_projektu+'\', \''+id_kategorii+'\', \''+lang+'\');return false;">'+ //onsubmit="return false;">'+
																	'<div class="inputGrayL">'+
																		'<div class="inputGrayR">'+
																			'<input id="szukaj" class="inputGray w220" type="text" size="60"  onblur="if(this.value == \'\')this.value=\'Wprowadź nazwę tematu do wyszukania:\'" onfocus="if(this.value == \'Wprowadź nazwę tematu do wyszukania:\')this.value=\'\'" value="Wprowadź nazwę tematu do wyszukania:"/>'+
																	'</div></div>'+
																	//'<input type="submit" name="submit" value="szukaj" class="buttonSmall ver1" onclick="javascript:pokaz_liste_tematow(\''+id+'\', \''+id_projektu+'\', \''+id_kategorii+'\', \''+lang+'\')"/>'+
																	
																'</form>'+
								'</div></div></div></div></div></div></div></div>'+
							'</div>');
		var pathsize = getPageSize();
		$("div.overlay").css('height', pathsize[1] +'px');
		$('div.overlay').css('width', pathsize[2] +'px');
	}
}

function initFileUploads() 
{
	var W3CDOM = (document.createElement && document.getElementsByTagName);
	if (!W3CDOM) return;
	
	var fakeFileUpload = document.createElement('div');
	fakeFileUpload.className = 'fakefile';
	fakeFileUpload.appendChild(document.createElement('input'));
	
	ie=(document.all)?true:false;
	if (!ie) 
	{
		var image = document.createElement('img');
		image.src='images/button_przegladaj.jpg';
		image.style.position = 'absolute';
		fakeFileUpload.appendChild(image);
	}
	var x = document.getElementsByTagName('input');
	
	for (var i=0;i<x.length;i++) 
	{
		if (x[i].type != 'file') continue;
		if (x[i].parentNode.className != 'fileinputs') continue;
		x[i+1].value = x[i].value;
	}
}

$(document).ready(function()
{
	// Przegladarka zdjec
	$('a[rel="editoimg[roadtrip]"]').addClass('thickbox');
	$('a[rel="editoimg[roadtrip]"]').attr("rel","gallery");
});

/* -- ZOOM2 --*/
function zoom2Set(blok_id,time,what){
	eval("clearTimeout("+what+")");
	eval(what + " = setTimeout(\"timedCount('"+blok_id+"')\", "+time+")");
}
function showZoom2(blok_id,id,przedrostek,opoznienie,time,what){
	zoom2Set(blok_id,time,what);
	$('#'+przedrostek+'_blok_'+blok_id+' .tabsArea li.active').removeClass();
	$('#'+przedrostek+'_blok_tab_'+blok_id+'_'+id).addClass('active');
	$('#'+przedrostek+'_blok_'+blok_id+' .zawartosc').hide();
	$('#'+przedrostek+'_blok_'+blok_id+' .zawartosc .cont').hide();
	$('#'+przedrostek+'_blok_tab_content_'+blok_id+'_'+id).show();
	//$('#'+przedrostek+'_blok_tab_content_'+blok_id+'_'+id+' .cont').fadeIn(opoznienie);
	$('#'+przedrostek+'_blok_tab_content_'+blok_id+'_'+id+' .cont').show();
	$('#'+przedrostek+'_blok_content_'+blok_id).attr('style','');
	$('#'+przedrostek+'_blok_content_'+blok_id).attr('style', $('#'+przedrostek+'_blok_tab_content_'+blok_id+'_'+id+' a.foto').attr('rel'));
	$('#'+przedrostek+'_blok_'+blok_id+'_apage').html(id);
}
function zoom2Prev(id,time){
	if($('#polecane_blok_'+id+'.polecane .tabsArea li.active').prev().size()==1)
		$('#polecane_blok_'+id+'.polecane .tabsArea li.active').prev().click();	
	else
		$('#polecane_blok_'+id+'.polecane .tabsArea li:last').click();
}
function zoom2Next(id,time){
	if($('#polecane_blok_'+id+'.polecane .tabsArea li.active').next().size()==1)
		$('#polecane_blok_'+id+'.polecane .tabsArea li.active').next().click();
	else
		$('#polecane_blok_'+id+'.polecane .tabsArea li:first').click();
}
function timedCount(id){
	if($('#polecane_blok_'+id+'.polecane .tabsArea li.active').next().size()==1)
		$('#polecane_blok_'+id+'.polecane .tabsArea li.active').next().click();
	else
		$('#polecane_blok_'+id+'.polecane .tabsArea li:first').click();
}

