/***************************/
//@Author: Adrian "yEnS" Mato Gondelle & Ivan Guardado Castro;
//@website: www.yensdesign.com;
//@email: yensamg@gmail.com;
//@license: Feel free to use it, but keep this credits please!;				
/***************************/

$(document).ready(function(){
	//global vars;
	var form = $("#formularz_www");
	var name = $("#imie_nazwisko");
	var nameInfo = $("#nameInfo");
	var telefon = $("#telefon");
	var telefonInfo = $("#telefonInfo");
	var email = $("#email");
	var emailInfo = $("#emailInfo");
	var wiadomosc = $("#wiadomosc");
	var wiadomoscInfo = $("#wiadomoscInfo");
	//var pass1 = $("#pass1");
	//var pass1Info = $("#pass1Info");
	//var pass2 = $("#pass2");
	//var pass2Info = $("#pass2Info");
	//var message = $("#message");
	
	//On blur
	name.blur(validateName);
	telefon.blur(validateTelefon);
	email.blur(validateEmail);
//	pass1.blur(validatePass1);
	//pass2.blur(validatePass2);
	//On key press
	name.keyup(validateName);
	wiadomosc.blur(validateWiadomosc);
//	pass1.keyup(validatePass1);
//	pass2.keyup(validatePass2);
//	message.keyup(validateMessage);
	//On Submitting
	form.submit(function(){
	//	if(validateName() & validateTelefon() )

		if(validateName() & validateEmail() & validateTelefon()& validateWiadomosc() )
	//	if(validateName() & validateEmail() & validatePass1() & validatePass2() & validateMessage())

			return true
		else
			return false;
	});
	
	//validation functions
	function validateEmail(){
		//testing regular expression
		var a = $("#email").val();
		var filter = /^[a-zA-Z0-9]+[a-zA-Z0-9_.-]+[a-zA-Z0-9_-]+@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
		//if it's valid email
		if(filter.test(a)){
			email.removeClass("error");
			emailInfo.text("Pole zostało uzupełnione");
			emailInfo.removeClass("error");
			return true;
		}
		//if it's NOT valid
		else{
			email.addClass("error");
			emailInfo.text("To nie jest prawidłowy email");
			emailInfo.addClass("error");
			return false;
		}	
		
	}
	function validateName(){
		//if it's NOT valid
		if(name.val().length < 4){
			name.addClass("error");
			nameInfo.text("Pole powinno zawierać min. 5 znaków.");
			nameInfo.addClass("error");
			return false;
		}
		//if it's valid
		else{
			name.removeClass("error");
			nameInfo.text("Pole uzupełnione");
			nameInfo.removeClass("error");
			return true;
		}
	}
	function validateWiadomosc(){
			//if it's NOT valid
			if(wiadomosc.val().length < 10){
				wiadomosc.addClass("error");
				wiadomoscInfo.text("Pole powinno zawierać min. 5 znaków.");
				wiadomoscInfo.addClass("error");
				return false;
			}
			//if it's valid
			else{
				wiadomosc.removeClass("error");
				wiadomoscInfo.text("Pole uzupełnione");
				wiadomoscInfo.removeClass("error");
				return true;
			}
		}
	function validateTelefon(){
		//if it's NOT valid
		if(telefon.val().length < 4){
			telefon.addClass("error");
			telefonInfo.text("Pole powinno zawierać min. 5 znaków.");
			telefonInfo.addClass("error");
			return false;
		}
		//if it's valid
		else{
			telefon.removeClass("error");
			telefonInfo.text("Pole uzupełnione");
			telefonInfo.removeClass("error");
			return true;
		}
	}
	function validateMessage(){
		//it's NOT valid
		if(message.val().length < 10){
			message.addClass("error");
			return false;
		}
		//it's valid
		else{			
			message.removeClass("error");
			return true;
		}
	}
});

/*** 
    Simple jQuery Slideshow Script
    Released by Jon Raasch (jonraasch.com) under FreeBSD license: free to use or modify, not responsible for anything, etc.  Please link out to me if you like it :)
***/

function slideSwitch() {
    var $active = $('#slideshow img.active');

    if ( $active.length == 0 ) $active = $('#slideshow img:last');

    // use this to pull the images in the order they appear in the markup
    var $next =  $active.next().length ? $active.next()
        : $('#slideshow img:first');

    // uncomment the 3 lines below to pull the images in random order
    
    // var $sibs  = $active.siblings();
    // var rndNum = Math.floor(Math.random() * $sibs.length );
    // var $next  = $( $sibs[ rndNum ] );


    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}

$(function() {
    setInterval( "slideSwitch()", 5000 );
});


$(document).ready(function(){

	$("div[id^=_menu_]").each(function() {
			$(this).click(function(){
				var tpl = $(this).attr('tpl');
				var menuid = $(this).attr('menuid');
				$("div[id=menu_"+menuid+"]").toggle();
				if ((tpl != '') && (tpl != undefined)) location.href=tpl;
			});
		});
	$("div[id^=_menu2_]").each(function() {
			$(this).click(function(){
				var tpl = $(this).attr('tpl');
				var menuid = $(this).attr('menu2id');
				$("div[id=menu2_"+menuid+"]").toggle();
				if ((tpl != '') && (tpl != undefined)) location.href=tpl;
			});
		});
	$("div[id^=menu_]").toggle();
	$("div[id^=menu2_]").toggle();
});

