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');
	SetSize();
	$('#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() {
	$("#Tresc A").each(function(){
		if (UseLightbox($(this).attr('href'))) $(this).attr('name', 'UseLBox');
	});
	$("#Tresc A[name='UseLBox']").lightBox();
	$("#Tresc A[name='UseLBox']").attr("title", "Kliknij z boku zdjęcia aby zobaczyć następne.");
}
function UseLightbox(string) {
	string = string.toLowerCase();
	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 SetSize() {
	var l = $('#Menu').height() + $('#KontaktBox').height() + 50 + 11;
	var r = $('#Tresc').height() + $('#Footer').height();
	if (l > r) {
				  	nr = $('#Tresc').height() + (l - r);
					$('#Tresc').height(nr);
	} else if (l < r) {
		nl = $('#Menu').height() + (r - l);
		$('#Menu').height(nl);
	}
}
function EventsInit() {
	$('#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!');
	});
	$('.subLi A').hover(function(){
			$(this).parent().css('color', '#606441');
		}, function(){
			$(this).parent().css('color', '#ffffff');
		});
		
	$('.sub').prev().click(function(){
		if ($(this).attr('name') == '0') {
			$(this).attr('name', '2');
//			$(this).addClass('a1active');
			// -- Zamykanie otwartych menu --
				$('.a1[name="1"]').click();
			// ------------------------------
			$(this).next().animate({height: 'show'}, 300, null, function(){
																									$(this).prev().attr('name', '1');
																									SetSize();
																				  				});
		} else if ($(this).attr('name') == '1') {
			$(this).attr('name', '2');
//			$(this).removeClass('a1active');
			$(this).next().animate({height: 'hide'}, 300, null, function(){
																									$(this).prev().attr('name', '0');
																									SetSize();
																				  				});
		}
	});
}
if (window.addEventListener) {
	window.addEventListener("load", Init, false);
}else if (window.attachEvent) {
	window.attachEvent("onload", Init);
}

