// Easing equation, borrowed from jQuery easing plugin
// http://gsgd.co.uk/sandbox/jquery/easing/
jQuery.easing.easeOutQuart = function (x, t, b, c, d) {
	return -c * ((t=t/d-1)*t*t*t - 1) + b;
};

var a1_krok2 = '<input type="radio" name="akcja2" value="1" id="akcja_2_1" checked onclick="reportNieMamStrony()" /> <label class="check" for="akcja_2_1" id="label_2_1" onclick="reportNieMamStrony();onclick(\'label_2_1\')" onmouseover="onmouseover2(\'label_2_1\');" onmouseout="onmouseout2(\'label_2_1\')">Nie mam jeszcze strony www</label><br/> <input type="radio" name="akcja2" value="2" id="akcja_2_2" onclick="reportMamStrone()" /> <label for="akcja_2_2" id="label_2_2" onclick="reportMamStrone();onclick(\'label_2_1\')" onmouseover="onmouseover2(\'label_2_2\');" onmouseout="onmouseout2(\'label_2_2\')">Mam już stronę - chcę ją odnowić</label><br/>adres strony:<br/><input type="text" name="url_2_2" id="url_2_2" /><br/>';

var a2_krok2 = '<input type="radio" name="akcja2_a" value="3" id="akcja_2_3" checked /> <label class="check" for="akcja_2_3" id="label_2_3" onclick="reportNieMamSklepu();onclick(\'label_2_3\')" onmouseover="onmouseover2(\'label_2_3\');" onmouseout="onmouseout2(\'label_2_3\')">Nie mam jeszcze sklepu</label><br/><input type="radio" name="akcja2_a" value="4" id="akcja_2_4" /> <label for="akcja_2_4" id="label_2_4" onclick="reportMamSklep();onclick(\'label_2_4\')" onmouseover="onmouseover2(\'label_2_4\');" onmouseout="onmouseout2(\'label_2_4\')">Mam już sklep - chcę go odnowić</label><br/>adres sklepu:<br/><input type="text" name="url_2_4" id="url_2_4" /><br/>';

var a3_krok2 = 'adres strony:<br/><input type="text" name="url_2_5" id="url_2_5" /><br/>frazy:<br/><textarea name="frazy_2_5" id="frazy_2_5" rows="3" cols="10"></textarea><br/>';

var a4_krok2 = 'chcę abyście wykonali:<br/><textarea name="cont_2_6" id="cont_2_6" rows="5" cols="10"></textarea><br/>';

var a5_krok2 = 'adresy moich stron:<br/><textarea name="url_2_7" id="url_2_7" rows="5" cols="10"></textarea><br/>';
var a6_krok2 = '';

var a1_krok3 = 'podoba mi się strona (strony):<br/><textarea name="url_3_1" id="url_3_1" rows="3" cols="10"></textarea><br/>strona będzie o:<br/><input type="text" name="tematyka_3_2" id="tematyka_3_2" /><br/>strona bedzie aktualizowana:<br/><select name="freq_3_3" id="freq_3_3"><option value="1">raz na rok</option><option value="2">raz na 6 miesięcy</option><option value="3">raz na 3 miesiące</option><option value="4">raz na miesiąc</option><option value="5">raz na 2 tyg</option><option value="6">raz na tydzień</option><option value="7">codziennie</option></select><br/>strona ma zawierać:<br/><textarea name="cont_3_4" id="cont_3_4" rows="3" cols="10"></textarea><br/>';

var a2_krok3 = 'podoba mi się strona (strony):<br/><textarea name="url_3_5" id="url_3_5" rows="3" cols="10"></textarea><br/>strona bedzie aktualizowana:<br/><select name="freq_3_6" id="freq_3_6"><option value="1">raz na rok</option><option value="2">raz na 6 miesięcy</option><option value="3">raz na 3 miesiące</option><option value="4">raz na miesiąc</option><option value="5">raz na 2 tyg</option><option value="6">raz na tydzień</option><option value="7">codziennie</option></select><br/>strona ma być rozbudowana o:<br/><textarea name="cont_3_7" id="cont_3_7" rows="3" cols="10"></textarea><br/>';

var a3_krok3 = 'podoba mi się sklep (sklepy):<br/><textarea name="url_3_8" id="url_3_8" rows="3" cols="10"></textarea><br/>będzie to sklep z:<br/><input type="text" name="tematyka_3_9" id="tematyka_3_9" /><br/>sklep będzie zawierał:<br/><select name="ilosc_3_10" id="ilosc_3_10"><option value="1">do 50 produktów</option><option value="2">do 150 produktów</option><option value="3">do 500 produktów</option><option value="4">do 1500 produktów</option><option value="5">do 5000 produktów</option><option value="6">powyżej 5000 produktów</option></select><br/>sklep ma zawierać funkcje:<br/><textarea name="cont_3_11" id="cont_3_11" rows="3" cols="10"></textarea><br/>';

var a4_krok3 = 'podoba mi się sklep (sklepy):<br/><textarea name="url_3_12" id="url_3_12" rows="3" cols="10"></textarea><br/>sklep będzie zawierał:<br/><select name="ilosc_3_13" id="ilosc_3_13"><option value="1">do 50 produktów</option><option value="2">do 150 produktów</option><option value="3">do 500 produktów</option><option value="4">do 1500 produktów</option><option value="5">do 5000 produktów</option><option value="6">powyżej 5000 produktów</option></select><br/>sklep ma być rozbudowany o:<br/><textarea name="cont_3_14" id="cont_3_14" rows="3" cols="10"></textarea><br/>';

var a4_krok3 = 'czy strona była juz pozycjonowana:<br/><input type="radio" name="akcja3" value="tak" id="akcja_3_15" checked /> <label for="akcja_3_15">tak</label>&nbsp;&nbsp;<input type="radio" name="akcja3" value="nie" id="akcja_3_16" /> <label for="akcja_3_16">nie</label><br/>interesują mnie pozycje:<br/><input type="text" name="tematyka_3_17" id="tematyka_3_17" />';

function reportMamStrone(){
	$('#krok3').html(a2_krok3);	
}
function reportNieMamStrony(){
	$('#krok3').html(a1_krok3);	
}

function reportMamSklep(){
	$('#krok3').html(a3_krok3);	
}
function reportNieMamSklepu(){
	$('#krok3').html(a4_krok3);	
}

function onmouseover(id){
	$(id).addClass('check');
}
function onmouseout(id){
	$(id).removeClass('check');
}

function onmouseover2(id){
	$('#'+id).addClass('check');
}
function onmouseout2(id){
	
	var elem = $('#'+id).attr('for');

		if($('#'+elem+':checked').length > 0){
			return;
		}
	$('#'+id).removeClass('check');
}

function onclick(id){
	$('#label_2_1').removeClass('check');
	$('#label_2_2').removeClass('check');
	$('#label_2_3').removeClass('check');
	$('#label_2_4').removeClass('check');
	$('#'+id).addClass('check');
}

function hideactions(){
	for(var i = 1; i<=6; i++){
		$("#a"+i).hide(0);
	}
}
function hideactions2(){
	for(var i = 1; i<=7; i++){
		$("#a1"+i).hide(0);
	}
}

function validateEmail(id){
	var msg = '';
	if($('#'+id).val().indexOf('@')==-1 || $('#'+id).val().indexOf('.')==-1)
	{
		msg = 'błędny adres email';
		return msg;
		
	}
	return true;
}
function validateWWW(id){
	var msg = '';
	if(($('#'+id).val().indexOf('http')==-1 && $('#'+id).val().indexOf('www')==-1) || $('#'+id).val().indexOf('.')==-1)
	{
		msg = 'błędny adres strony';
		return msg;
		
	}
	return true;
}
function validateEmpty(id, name){
	var msg = '';
	if($('#'+id).val()=='')
	{
		msg = 'uzupełnij '+name;
		return msg;
		
	}
	return true;
}

$(document).ready(function(){
	$("input:radio").css({'position':'absolute','left':'-999px'});
	
	$("input:text").css({'border':'1px solid #2fa0f0','color':'#2fa0f0','font-size':'11px','width':'320px'});
	$("textarea").css({'border':'1px solid #2fa0f0','color':'#2fa0f0','font-size':'11px','width':'320px'});
	$("select").css({'border':'1px solid #2fa0f0','color':'#2fa0f0','font-size':'11px','width':'320px'});
	
	
	$('label').mouseover(function(){
		onmouseover(this);
	});
	$('label').mouseout(function(){
		
		
		var elem = $(this).attr('for');
		if($('#'+elem+':checked').length > 0){
			return;
		}
		
		onmouseout(this);
		
	});
	
	$('.step1').click(function(){
		$('.step1').each(function(i){
			$(this).removeClass('check');
		});
		
		$(this).addClass('check');
	});
	$('.step2').click(function(){
		$('.step2').each(function(i){
			$(this).removeClass('check');
		});
		
		$(this).addClass('check');
	});
	
	$('.step2_a').click(function(){
		$('.step2_a').each(function(i){
			$(this).removeClass('check');
		});
		
		$(this).addClass('check');
	});
	
	$('.step3').click(function(){
		$('.step3').each(function(i){
			$(this).removeClass('check');
		});
		
		$(this).addClass('check');
	});
	
	$('#akcja_1').click(function(){
		hideactions();
		if($('#akcja_1:checked').length > 0){
			//$('#krok2').html(a1_krok2);
			$("#a1").show(0);
		}
	});
	
	$('#akcja_2').click(function(){
		hideactions();
		if($('#akcja_2:checked').length > 0){
			$("#a2").show(0);
		}
	});
	$('#akcja_2_1').click(function(){
		hideactions2();
		if($('#akcja_2_1:checked').length > 0){
			$("#a11").show(0);
		}
	});
	
	$('#akcja_2_2').click(function(){
		hideactions2();
		if($('#akcja_2_2:checked').length > 0){
			$("#a12").show(0);
		}
	});
	$('#akcja_2_3').click(function(){
		hideactions2();
		if($('#akcja_2_3:checked').length > 0){
			$("#a13").show(0);
		}
	});
	$('#akcja_2_4').click(function(){
		hideactions2();
		if($('#akcja_2_4:checked').length > 0){
			$("#a14").show(0);
		}
	});
	
	$('#akcja_3').click(function(){
		hideactions();
		hideactions2();
		if($('#akcja_3:checked').length > 0){
			$("#a3").show(0);
			$("#a15").show(0);
		}
	});
	
	
	$('#akcja_4').click(function(){
		hideactions();
		hideactions2();
		if($('#akcja_4:checked').length > 0){
			$("#a4").show(0);
			$("#a16").show(0);
			}
	});
	$('#akcja_5').click(function(){
		hideactions();
		hideactions2();
		if($('#akcja_5:checked').length > 0){
			$("#a5").show(0);
			$("#a17").show(0);
			}
	});
	$('#akcja_6').click(function(){
		hideactions();
		if($('#akcja_6:checked').length > 0){
			$('#dalej').trigger( 'goto', [ 3 ] );
			
			}
	});
	
	$('#wroc').click(function(){
		if($('#akcja_6:checked').length > 0){
			$('#wroc').trigger( 'goto', [ 0 ] );
		}
	});
	
	$('#submit').click(function(){
		if(validateEmpty('imie_naziwsko', 'imię i nazwisko')!==true){
			alert(validateEmpty('imie_naziwsko', 'imię i nazwisko'));
			return false;
		}
		if(validateEmail('email')!==true){
			alert(validateEmail('email'));
			return false;
		}
		if( confirm('na pewno ?') ){
		$('#ff').ajaxSubmit( {
				success: function() { 
					
					$.get("message.php", function(data){
						$('#screen').slideUp();
						$('#message').html(data);
						$('#message').fadeIn();
					});
					
				}
            }); 
		return false;
		}
	});
	
});

jQuery(function( $ ){
	var current = 1;
	
	$('#screen').serialScroll({
		target:'#sections',
		items:'li', // Selector to the items ( relative to the matched elements, '#sections' in this case )
		prev:'span.prev',// Selector to the 'prev' button (absolute!, meaning it's relative to the document)
		next:'span.next',// Selector to the 'next' button (absolute too)
		axis:'x',// The default is 'y' scroll on both ways
		navigation:'#navigation div',
		duration:700,// Length of the animation (if you scroll 2 axes and use queue, then each axis take half this time)
		force:true, // Force a scroll to the element specified by 'start' (some browsers don't reset on refreshes)
		
		//queue:false,// We scroll on both axes, scroll both at the same time.
		//event:'click',// On which event to react (click is the default, you probably won't need to specify it)
		//stop:false,// Each click will stop any previous animations of the target. (false by default)
		//lock:true, // Ignore events if already animating (true by default)		
		//start: 0, // On which element (index) to begin ( 0 is the default, redundant in this case )		
		//cycle:true,// Cycle endlessly ( constant velocity, true is the default )
		//step:_step, // How many items to scroll each time ( 1 is the default, no need to specify )
		//jump:false, // If true, items become clickable (or w/e 'event' is, and when activated, the pane scrolls to them)
		//lazy:false,// (default) if true, the plugin looks for the items on each event(allows AJAX or JS content, or reordering)
		//interval:1000, // It's the number of milliseconds to automatically go to the next
		//constant:true, // constant speed
		
		onBefore:function( e, elem, $pane, $items, pos ){
			/**
			 * 'this' is the triggered element 
			 * e is the event object
			 * elem is the element we'll be scrolling to
			 * $pane is the element being scrolled
			 * $items is the items collection at this moment
			 * pos is the position of elem in the collection
			 * if it returns false, the event will be ignored
			 */
			 //those arguments with a $ are jqueryfied, elem isn't.
			current = pos+1;
			
			if(pos == 2){
				if($('#akcja_2_2:checked').length > 0){
					if(validateEmpty('url_2_2', 'adres strony')!==true){
						alert(validateEmpty('url_2_2', 'adres strony'));
						return false;
					}
					if(validateWWW('url_2_2')!==true){
						alert(validateWWW('url_2_2'));
						return false;
					}
				}
				if($('#akcja_2_4:checked').length > 0){
					if(validateEmpty('url_2_4', 'adres strony')!==true){
						alert(validateEmpty('url_2_4', 'adres strony'));
						return false;
					}
					if(validateWWW('url_2_4')!==true){
						alert(validateWWW('url_2_4'));
						return false;
					}
				}
				if($('#akcja_3:checked').length > 0){
					if(validateEmpty('url_2_5', 'adres strony')!==true){
						alert(validateEmpty('url_2_5', 'adres strony'));
						return false;
					}
					if(validateWWW('url_2_5')!==true){
						alert(validateWWW('url_2_5'));
						return false;
					}
					if(validateEmpty('frazy_2_5', 'słowa kluczowe')!==true){
						alert(validateEmpty('frazy_2_5', 'słowa kluczowe'));
						return false;
					}
				}
				if(pos == 4){
					
					if(validateEmpty('imie_naziwsko', 'imię i nazwisko')!==true){
						alert(validateEmpty('imie_naziwsko', 'imię i nazwisko'));
						return false;
					}
					if(validateEmail('email')!==true){
						alert(validateEmail('email'));
						return false;
					}
				
				}
				
					
					
				
				
			}
			
			
			e.preventDefault();
			if( this.blur )
				this.blur();
		},
		onAfter:function( elem ){
			
			
			//'this' is the element being scrolled ($pane) not jqueryfied
			$('#navigation div').removeClass('filled');
			$('#navigation div').removeClass('current');
			$('#navigation div').removeClass('common');
			for(var i = 1 ; i< current; i++){
				$('#nav'+i).addClass('filled')
			}
			$('#nav'+current).addClass('current');
			for(var i = current+1 ; i< 5; i++){
				$('#nav'+i).addClass('common');
			}
		}
	});
});
