var current = 1;
var stop = false;

function slideBoxes()
{
	if(stop) return;
	
	setTimeout(function()
	{	   		
		changeBoxes();
   		slideBoxes();
	}, 15000);
}

function changeBoxes()
{

	$("#banner"+current++).fadeOut(function()
	{
		if(current>6)
			current=1;
		$("#banner"+current).fadeIn();
	}
	);
}

function showBanner(number)
{
	if(current == number ) return;
	
	stop = true;
	oldcurrent = current;
	current = number;
	
	
	
	$("#banner"+oldcurrent).fadeOut(function()
	{
		
		
	}
	);
	$("#banner"+current).fadeIn();
}

$().ready(function(){
	
	$("#searchInput").click(function(){
		if($("#searchInput").val() == "wpisz frazę")
		{
			$("#searchInput").val("");
		}
		
	});
	
	
	$("#searchInput").blur(function(){
		
		if($("#searchInput").val() == "")
		{
			$("#searchInput").val("wpisz frazę");
		}
		
	});
	
	
	$("#contactForm").validate({
		
		showErrors: function(errorMap, errorList) {

			if(errorList.length>0)
			{
				alert("Wypełnij wszystkie wymagane pola!");
			}
	       
	    },
	   
	    focusInvalid: false,
	    onfocusout: false,
	    onkeyup: false,
	    
		messages: 
		{
			subject: "     pole  wymagane ",
			
			email: { required: "    pole  wymagane",
        	email: "zły format"
 },
 tresc_wiadomosci: "  &nbsp;   pole  wymagane "
		}
	});
	
	
	$("#newsletterForm").validate({
			
		showErrors: function(errorMap, errorList) {

			if(errorList.length>0)
			{
				alert("Podaj poprawny adres email!");
			}
	       
	    },
	   
	    focusInvalid: false,
	    onfocusout: false,
	    onkeyup: false,
			
		    
			messages: 
			{
				email: { required: "pole  wymagane",
	        	email: "zły format"
	 }
			}
			});
	
	
	



	
	
		
	$("#wyszukaj").click(function() {
		
		$("#szukaj").toggle();			
	})	
	
$("#szukaj").mouseleave(function() {
	
	$(this).hide();
	
});
	$("#sub-1").mouseover(
			function () {
				
				showBanner(1);
				$(".tip-kable").show();	
			}	
		);
		
		$(".tip-kable").mouseover(
		
			function () {
			
			$(".tip-kable").show();	
			}	
		);
		
		
		$("#sub-1").mouseleave(
			function () {
				stop = false;
			$(".tip-kable").hide();	
			}
			
			
		);
			
		
		$(".tip-kable").mouseleave(
			function () {
			
			$(".tip-kable").hide();	
			}
		);
		
	$("#sub-2").mouseover(
			function () {
			showBanner(2);	
			$(".tip-oswietlenie").show();	
			}	
		);
		
		$(".tip-oswietlenie").mouseover(
		
			function () {
		
			$(".tip-oswietlenie").show();	
			}	
		);
		
		
		$("#sub-2").mouseleave(
			function () {
				stop = false;
			$(".tip-oswietlenie").hide();	
			}
			
			
		);
			
		
		$(".tip-oswietlenie").mouseleave(
			function () {
			$(".tip-oswietlenie").hide();	
			}
		);
		
		$("#sub-3").mouseover(
				function () {
				showBanner(3);
				$(".tip-aparatura").show();	
				}	
			);
			
			$(".tip-aparatura").mouseover(
			
				function () {
				$(".tip-aparatura").show();	
				}	
			);
			
			
			$("#sub-3").mouseleave(
				function () {
					stop = false;
				$(".tip-aparatura").hide();	
				}
				
				
			);
				
			
			$(".tip-aparatura").mouseleave(
				function () {
				$(".tip-aparatura").hide();	
				}
			);
			
			$("#sub-4").mouseover(
					function () {
					showBanner(4);
					$(".tip-trasy-kablowe").show();	
					}	
				);
				
				$(".tip-trasy-kablowe").mouseover(
				
					function () {
					$(".tip-trasy-kablowe").show();	
					}	
				);
				
				
				$("#sub-4").mouseleave(
					function () {
						stop = false;
					$(".tip-trasy-kablowe").hide();	
					}
					
					
				);
					
				
				$(".tip-trasy-kablowe").mouseleave(
					function () {
					$(".tip-trasy-kablowe").hide();	
					}
				);
				
				$("#sub-5").mouseover(
						function () {
						showBanner(5);
						$(".tip-osprzet-bialy").show();	
						}	
					);
					
					$(".tip-osprzet-bialy").mouseover(
					
						function () {
						$(".tip-osprzet-bialy").show();	
						}	
					);
					
					
					$("#sub-5").mouseleave(
						function () {
							stop = false;
						$(".tip-osprzet-bialy").hide();	
						}
						
						
					);
						
					
					$(".tip-osprzet-bialy").mouseleave(
						function () {
						$(".tip-osprzet-bialy").hide();	
						}
					);
					
					
					$("#sub-6").mouseover(
							function () {
							showBanner(6);
							$(".tip-sieci-energetyczne").show();	
							}	
						);
						
						$(".tip-sieci-energetyczne").mouseover(
						
							function () {
							$(".tip-sieci-energetyczne").show();	
							}	
						);
						
						
						$("#sub-6").mouseleave(
							function () {
								stop = false;
							$(".tip-sieci-energetyczne").hide();	
							}
							
							
						);
							
						
						$(".tip-sieci-energetyczne").mouseleave(
							function () {
							$(".tip-sieci-energetyczne").hide();	
							}
						);
		
		
		
		
	});
