$(document).ready(function (){
	
	$('.contentImg').jScrollPane({scrollbarWidth: 25, showArrows:true, arrowSize: 11});
	$(".jScrollPaneDrag").css("height","31px");
	$("a").not("input").focus( function(){ $(this).blur() } );
	if(document.forms[0]){
	document.forms[0].reset();
	}

$.preloadCssImages();

initFileUploads();
$('.contentImg a').lightBox({fixedNavigation:true});
//$('').lightBox({fixedNavigation:true});
//$('.singleFoto a, .singleFotoSecond a').lightBox({fixedNavigation:true});
$('.checkbox_input').checkBox();

});


var W3CDOM = (document.createElement && document.getElementsByTagName);

function initFileUploads() {
	if (!W3CDOM) return;
	var fakeFileUpload = document.createElement('div');
	fakeFileUpload.className = 'fakefile';
	fakeFileUpload.appendChild(document.createElement('input'));
	var image = document.createElement('img');
	image.src='design_el/search.png';
	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].className = 'file hidden';
		var clone = fakeFileUpload.cloneNode(true);
		x[i].parentNode.appendChild(clone);
		x[i].relatedElement = clone.getElementsByTagName('input')[0];
		x[i].onchange = x[i].onmouseout = function () {
			this.relatedElement.value = this.value;
		}
	}
}

//obsługa formularza
function submitForm(){
//	alert("got ya!");
	var error=0,
	nickName = $("#nickname").val(),
	name = $("#name").val(),
	email = $("#email").val(),
	description1 = $("#description1").val(),
	foto1 = $("#foto1").val(),
	description2 = $("#description2").val(),
	foto2 = $("#foto2").val(),
	description3 = $("description3").val(),
	foto3 = $("#foto3").val(),
	adress = $("#adress").val(),
	phone = $("#phone").val(),
	rulesDisclaimer = $("#rulesDisclaimer"),
	privacyPolicy = $("#privacyPolicy");
	//document.forms[0].submit();
	function testMail(src) {
		var emailReg = "^[\\w-_\.+]*[\\w-_\.]\@([\\w]+\\.)+[\\w]+[\\w]$";
		var regex = new RegExp(emailReg);
		return regex.test(src);
	}


	if(!nickName){
		$("#nickname").css({border:"1px #f00 solid", height:14, width: 205});
		error=1;
	}else{
		if(error!=1){
			error=0;
		}
		$("#nickname").css({border:"none", height:16, width: 207});
	}
	if(!name){
		$("#name").css({border:"1px #f00 solid", height:14, width: 205});
		error=1;
	}else{
		if(error!=1){
			error=0;
		}
		$("#name").css({border:"none", height:16, width: 207});
	}
	if(!email || testMail(email)== false){
		$("#email").css({border:"1px #f00 solid", height:14, width: 205});
		error=1;
	}else{
		if(error!=1){
			error=0;
		}
		$("#email").css({border:"none", height:16, width: 207});
	}
	
	if(!description1=='' || !description2=='' || !description3==''){
		if(error!=1){
			error=0;
		}
		$("#description1").css({border:"none", height:16, width: 207});
	}else{
		error=1;
		$("#description1").css({border:"1px #f00 solid", height:14, width: 205});
	}

	if( !foto1=='' || !foto2=='' || !foto3==''){
		if(error!=1){
			error=0;
		}
		$(".fakefile:eq(0) input").css({border:"none", height:16, width: 121});
	}else{
		$(".fakefile:eq(0) input").css({border:"1px #f00 solid", height:14, width: 119});
		error=1;
	}
	
	if(!adress){
		$("#adress").css({border:"1px #f00 solid", height:14, width: 205});
		error=1;
	}else{
		if(error!=1){
			error=0;
		}
		$("#adress").css({border:"none", height:16, width: 207});
	}
	if(!phone){
		$("#phone").css({border:"1px #f00 solid", height:14, width: 205});
		error=1;
	}else{
		if(error!=1){
			error=0;
		}
		$("#phone").css({border:"none", height:16, width: 207});
	}
	if(!$("#rulesDisclaimer").is(":checked")){
		$(".ui-checkbox:eq(0)").css({border:"1px #f00 solid", height:14, width: 14});
		error=1;
	}
	else{
		$(".ui-checkbox:eq(0)").css({border:"none", height:16, width: 16});
		if(error!=1){
			error=0;
		}
	}
	if(!$("#privacyPolicy").is(":checked")){
		$(".ui-checkbox:eq(1)").css({border:"1px #f00 solid", height:14, width: 14});
		error=1;
	}
	else{
		if(error!=1){
			error=0;
		}
		$(".ui-checkbox:eq(1)").css({border:"none", height:16, width: 16});
	}
	if(error==1){
		$('body').append('<div id="jquery-overlay2"></div><div id="jquery-lightbox2"><div id="lightbox-container-image-box2"><img src="design_el/errorform.png" alt="" /></div></div></div>');
		$('#jquery-overlay2').css({
			backgroundColor:	'#2e5f99',
			opacity:			0.6,
			width:				"100%",
			height:				"100%"
		}).fadeIn();
		$('#jquery-overlay2, #jquery-lightbox2, #lightbox-container-image-box2').click(function() { // close btn karim
			$('#jquery-overlay2, #jquery-lightbox2').remove();							
		});
		//alert("Proszę wypełnij pola, które są zaznaczone czerwoną obwódką.");
		return false;		
	}
	else{
		document.forms[0].submit();
	}
}