
$(document).ready(function(){
		
	$('#controller').jFlow({
		slides: '#maincontent',
		controller: '.jFlowControl',
		width: '100%',
		height: '388px',
		easing: 'easeOutBack',
		duration: 400,
		next: '.jFlowNext',	
		interval: 9999999999 /*so it does not automatically scroll. Gets a little cranky when you add too many 9s though.*/
				
	});		
	
	$('#controller2').jFlow({
		slides: '#top',
		controller: '.jFlowControl2',
		width: '100%',
		height: '320px',
		easing: 'swing',
		duration: 800,
		interval: 9000,
		next: '.jFlowNext2',
		prev: '.jFlowPrev2'
	});	
			  
	/*
	$('#news').cycle({ 
		fx:     'fade', 
		timeout: 6000, 
		delay:  -2000 
	});
	*/
	
	$('#hpportfolio').cycle({ 
		fx:     'scrollDown', 
		timeout: 6000, 
		delay:  -2000,
		easing: 'easeOutBack',
		pause:   1
	});
	
	$('a.nudge').hover(function() { //mouse in
	$(this).animate({ paddingTop: 0 }, 400, 'easeOutBounce');
	}, function() { //mouse out
	$(this).animate({ paddingTop: 20 }, 400, 'easeOutBounce');
	});
	
	$('a.rnudge').hover(function() { //mouse in
	$(this).animate({ paddingRight: '20px' }, 400, 'easeOutBounce');
	}, function() { //mouse out
	$(this).animate({ paddingRight: 0 }, 400, 'easeOutBounce');
	});
	
	$('.scroll-pane').jScrollPane({
		scrollbarWidth: 12,
		wheelSpeed: 100            
	});		         
	
	
	/*
	
	$("#tag").click(function(){
	$("#tag").animate({ right: '900px', opacity: 'hide'}, 'slow', 'easeOutBack');
	
	});
	
	*/
	
	$.uGallery(); 
	
	$("div.gal-thumbs").prepend($('<h2>Port<span class="rest">folio</span><span class="desc">Wybrane realizacje</span></h2><br />'));
	
	$("#contact-form").validate({
	rules: {
			name: {
				required: true
				},
			email: {
				required: true,
				email: true
				},
			messagebox: {
				required: true
				}
		},
		messages: {
			name: "Proszę wpisać imię i nazwisko.",
			email: "Proszę wpisać prawidłowy adres e-mail.",
			messagebox: "Proszę wpisać treść wiadomości."
		}
	});


	$("#contact-form :submit").removeAttr("disabled");	
	$("#contact-form").ajaxForm({
		dataType:  'json', 
		success:	function(_data) {
				if(_data.error == 2){
					$("#contact-form").html('<p><strong>Przepraszamy. Wystąpił błąd. Skontaktuj się z nami wysyłając wiadomość na adres <a href="mailto:kontakt@w3media.pl">kontakt@w3media.pl</a></strong></p>');
				}
				else if(_data.error) { 
					$("#contact-form").html('<p><strong>Przepraszamy. Wystąpił błąd. Spróbuj ponownie później.</strong></p>');
				}
				else {
					$("#contact-form").html('<p><strong>Dziękujemy. Twoja wiadomość została wysłana. Postaramy się odpowiedzieć najszybciej jak to jest możliwe.</strong></p>');
				}
				$("#contact-form :submit").removeAttr("disabled");
			},
		
		beforeSubmit: function(_formData, _jqForm, _options) {
				$("#contact-form :submit").attr("disabled","disabled");
			}
	});	


	$("#login-form").validate({
	rules: {
			login: {
				required: true
				},
			password: {
				required: true
				}
		},
		messages: {
			login: "Pole wymagane.",
			password: "Pole wymagane."
		}
	});


	$("#login-form :submit").removeAttr("disabled");	
	$("#login-form").ajaxForm({
		dataType:  'json', 
		success:	function(_data) {
				if(_data.error) { 
					$("#login-form").append('<p id="login-error"><strong style="color:red">Login lub hasło nieprawidłowe.</strong></p>');
				}
				else {
					document.location = '/client-zone/'
				}
				$("#login-form :submit").removeAttr("disabled");
			},
		
		beforeSubmit: function(_formData, _jqForm, _options) {
				$("#login-form :submit").attr("disabled","disabled");
				$("#login-error").remove();
			}
	});	

});     
				