function question() {
	var res=confirm('Are you sure?');
	if (res) { return true; }
	else { return false; }
}


$(document).ready(function(){
	$(".noclick").click(function(){
		alert("Tymczasowo niedostępne.");
		return false;
	});
	
	$('#slider').nivoSlider({
		effect: 'sliceDown', //Specify sets like: 'fold,fade,sliceDown'
		slices:9,
		animSpeed:500, //Slide transition speed
		pauseTime:3000,
		startSlide:0, //Set starting Slide (0 index)
		directionNav:true, //Next & Prev
		directionNavHide:true, //Only show on hover
		controlNav:true, //1,2,3...
		controlNavThumbs:false, //Use thumbnails for Control Nav
		controlNavThumbsFromRel:false, //Use image rel for thumbs
		controlNavThumbsSearch: '.jpg', //Replace this with...
		controlNavThumbsReplace: '_thumb.jpg', //...this in thumb Image src
		keyboardNav:true, //Use left & right arrows
		pauseOnHover:true, //Stop animation while hovering
		manualAdvance:false, //Force manual transitions
		captionOpacity:0.8, //Universal caption opacity
		beforeChange: function(){},
		afterChange: function(){},
		slideshowEnd: function(){} //Triggers after all slides have been shown
	});
	
	var g=0;
	$(".projekt").each(function(){
		g++;
		$(this).find('a.LB').attr('rel','prettyPhoto[gal'+g+']');
	});
	$("a.LB").prettyPhoto({theme:'dark_rounded'});
	
	
	//$("a[rel^='prettyPhoto']").prettyPhoto({theme:'dark_rounded', hideflash:true});
});





function getURLParam(strParamName){
	  var strReturn = "";
	  var strHref = window.location.href;
	  if ( strHref.indexOf("?") > -1 ){
	    var strQueryString = strHref.substr(strHref.indexOf("?")).toLowerCase();
	    var aQueryString = strQueryString.split("&");
	    for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
	      if ( aQueryString[iParam].indexOf(strParamName + "=") > -1 ){
	        var aParam = aQueryString[iParam].split("=");
	        strReturn = aParam[1];
	        break;
	      }
	    }
	  }
	  return decodeURIComponent(strReturn);
}


function wyslij_wiad(id) {
	if (validacja_formy(id)) {
		var imie = $('#'+id+" *[name='imie']").val();
		var mail = $('#'+id+" *[name='mail']").val();
		var temat = $('#'+id+" *[name='temat']").val();
		var tresc = $('#'+id+" *[name='tresc']").val();
		
		$('#forma').hide(500);
		$('#loader').show(500);
		
		$.ajax({
			type: "GET",
			url: "/ajax.php?mail="+mail+"&temat="+temat+"&imie="+imie+"&tresc="+tresc,
			cache: true, // to prevent doubles ;)
			success: function(info) {
				if (info) {
					$('#loader').hide(500);
					if (info=="OK") {
						$('#status').html("Wiadomość została wysłana");
						$('#status').show(500);
					}
					else {
						alert("Nieznany błąd. Spróbuj ponownie. Jeżeli błąd będzie się powtarzał - proszę skorzystaj z innej formy kontaktu.");
						$('#forma').show(500);
					}
				}
				else {
					alert("Żadanie przekroczyło dozwolony czas oczekiwania. Sprawdź połączenie z internetem, odśwież stronę i spróbuj ponownie.");
					$('#forma').show(500);
				}
	         } // success
		});// ajax
	}
}


function validacja_formy(id, or_ok) {
	var blad='';
	$('#'+id+' .req_text').each (function () {
		var def = $(this)[0].defaultValue;
		var cur = $(this).val();
		if (cur=='' || cur==def) {
			blad += "- " + $(this).attr('title') + ".\n";
		}
	});
	$('#'+id+' .req_mail').each (function () {
		if (!isEmail($(this).attr('value'))) {
			blad += "- " + $(this).attr('title') + "\n";
		}
	});
	$('#'+id+' .type_mail').each (function () {
		if (!isEmail($(this).attr('value')) && ($(this).attr('value')!='')) {
			blad += "- Niepoprawny " + $(this).attr('title') + "\n";
		}
	});
	$('#'+id+' .req_checkbox').each (function () {
		if (!$(this).attr('checked')) {
			blad += "- " + $(this).attr('title') + "\n";
		}
	});	

	if (blad != '') {
		alert(blad);
		return false;
	}
	else {
		return true;
	}
}


function isEmail(email) {
	email = email.replace(/[ ]/g, '');
	var regEmail = /^([a-zA-Z0-9._-]{1,})@([a-zA-Z0-9._-]{1,})\.([a-zA-Z]{2,4})$/;
	if (!regEmail.test(email))
		return false;
	else
		return email;
}
