function Init() {
	if (navigator.appName == "Microsoft Internet Explorer") var IE = true;
																		else var IE = false;
	window.speed = 250;
	if (IE) window.speed = 400;
//	if (IE) $('#Search INPUT').css('background-attachment', 'fixed');
	LightboxInit();
	EventsInit();
	$('A[rel="external"]').attr('target', '_blank');
	$('#FlashTop').each(function(){
		InsertFlash('fla/altera.swf', 717, 298, 'FlashTop');
	});
}
function CheckRegex(str, typ) {
	if (typ == 'godzina')    var regex = /^[0-9]{1,2}[/:]{1}[0-9]{1,2}$/;
	else if (typ == 'data')  var regex = /^[0-9]{4}(-[0-9]{2}){2}$/;
	else if (typ == 'email') var regex = /^[a-zA-Z0-9.\-_]+@[a-zA-Z0-9\-.]+\.[a-zA-Z]{2,4}$/;
	else return false;
	if (regex.test(str) == true) return true;
	else return false;
}
function dlh(a) {
	document.location.href = a;
}
function Zaokraglij(co, ile) {
	li = Math.pow(10, ile);
	w = Math.round(co * li) / li;
	return w;
}
function LightboxInit() {
	$("#Content A").each(function(){
		if (UseLightbox($(this).attr('href'))) $(this).attr('name', 'UseLBox');
	});
	$("#Content A[name='UseLBox']").lightBox();
	$("#Content A[name='UseLBox']").attr("title", "Kliknij z boku zdjęcia aby zobaczyć następne.");
}
function UseLightbox(string) {
	if (string.indexOf('.jpg') > 0) return true;
	if (string.indexOf('.jpeg') > 0) return true;
	if (string.indexOf('.gif') > 0) return true;
	if (string.indexOf('.png') > 0) return true;
	if (string.indexOf('.bmp') > 0) return true;
	if (string.indexOf('.tif') > 0) return true;
	return false;
}
function InsertFlash(fla, w, h, div) {
	var so = new SWFObject(fla, "mymovie", w, h, "8", "transparent");
   so.addParam("wmode", "transparent");
   so.write(div);
}
function EventsInit() {



	$('#MenuLeft A').click(function(){
		if ($(this).hasClass('mn1')) var poz = 1;
		else if ($(this).hasClass('mn2')) var poz = 2;
		if (((poz == 1) && ($(this).next().next().hasClass('sub'))) || ((poz == 2) && ($(this).next().next().next().hasClass('sub')))) {
			if (poz == 1) var ten = $(this).next().next();
			else if (poz == 2) var ten = $(this).next().next().next();
			var idBloku = ten.attr('class').substr(4);
			if (ten.hasClass('name1')) {
				ten.removeClass('name1');
				ten.addClass('name3');
				ten.animate({height: 'show'}, window.speed, null, function(){
											$(this).removeClass('name3');
											$(this).removeClass('name1');
											$(this).addClass('name2');
											if ($(this).prev().prev().hasClass('ML_link1')) $(this).prev().prev().children('SPAN').css('background-image', 'url("gfx/menuLeftArrowDown.gif")');
																							else $(this).prev().prev().children('SPAN').css('font-weight', 'bold');
																				  				}
				);
			} else if (ten.hasClass('name2')) {
			  	ten.removeClass('name2');
				ten.addClass('name3');
				ten.animate({height: 'hide'}, window.speed, null, function(){
											$(this).removeClass('name3');
											$(this).removeClass('name2');
											$(this).addClass('name1');
											if ($(this).prev().prev().hasClass('ML_link1')) $(this).prev().prev().children('SPAN').css('background-image', 'url("gfx/menuLeftArrowRight.gif")');
																							else $(this).prev().prev().children('SPAN').css('font-weight', 'normal');
																				  				}
				);
			}
		};
	});
	
	$('#FormularzKontaktowy INPUT[type="button"]').click(function(){
		var adr = $('SELECT[name="adres"]').val();
		var imi = $('INPUT[name="imie"]').val();
		var ema = $('INPUT[name="email"]').val();
		var tem = $('SELECT[name="temat"]').val();
		var tre = $('TEXTAREA[name="tresc"]').val();
		if ((imi.length > 0) && (ema.length > 0) && (tem.length > 0) && (tre.length > 0)) {
			if (CheckRegex(ema, 'email')) {
				$.ajax({
					type: "POST",
					url : "ajax/sendMail.ajax.php",
					data: "adr=" + parseInt(adr) + "&imi=" + imi + "&ema=" + ema + "&tem=" + tem + "&tre=" + tre,
					success: function(odp) {
						if (odp == 'ok') alert('Wiadomość została wysłana.');
						else alert('BŁĄD PODCZAS WYSYŁANIA!\n' + odp);
					},
					error  : function() {
						alert('Wystąpił błąd podczas komunikacji!');
					}
				});
			} else alert('Błędny format adresu e-mail!')
		} else alert('Nie wszystkie pola zostały wypełnione!');
	});
}
if (window.addEventListener) {
	window.addEventListener("load", Init, false);
}else if (window.attachEvent) {
	window.attachEvent("onload", Init);
}

