﻿$(document).ready(function() {


	jQuery.fn.exists = function() { return jQuery(this).length>0; }



	// Focus border remove

			$("a").focus(function() {
				$(this).blur();
			});
		

	
	
	// Fancybox

			$(".fancy").fancybox({
				'titlePosition'	:	'over',
				'padding'			: 0,
				'transitionIn'		: 'none',
				'transitionOut'		: 'none',
				'type'              : 'image',
				'changeFade'        : 0,
				'onComplete'	:	function() {
					$("#fancybox-wrap").hover(function() {
						$("#fancybox-title").show();
					}, function() {
						$("#fancybox-title").hide();
					});
				}
			});


	
	// Opacity

			$.fn.opacity = function() {
				$(this).hover(
				  function () {
					$(this).css({ opacity: ".9" });
				  }, 
				  function () {
					$(this).css({ opacity: "1" });
				  }
				);
			}
		
			if ($("#gallery").exists())	{ $("#gallery a").opacity(); }
			if ($("#gallery-index").exists())	{ $("#gallery-index a img").opacity(); }
			if ($("#nasze").exists())	{ $("#nasze a").opacity(); }



	
	// Menu Drop-Down:
	
			$(".menu_head").click(function() {
				$(".menu_body").slideUp (300);
				$(this).next(".menu_body").slideToggle(300);
				return false;
			});
			
			$(".hit").next(".menu_body").slideToggle(300).siblings(".menu_body").slideUp("fast");
	
			/* Three Levels
			
			$(".menu_head").click(function() {
				$(this).next(".menu_body").slideToggle(300).siblings(".menu_body").slideUp("fast");	
			});
		
		
			$(".hit").next(".menu_body").slideToggle(300).siblings(".menu_body").slideUp("fast");
			*/





	// _blank
	
			$(function() {
				$('a[href^=http]').click( function() {
					window.open(this.href);
					return false;
				});
			});



	// Form validate
		
			$('#error').hide();
			$('form').bind('submit', function(){
				var valid = true;
				$('.required').click(function(){
					$(this).removeClass('error-input');
				});
				$('.required').each(function(){
					if($(this).val()==''){
						$(this).addClass('error-input');
						 valid = false;
					}else{
						$(this).removeClass('error-input');
					}
				});
				if(!valid){
					$('#error').fadeIn();
					return false;
				}
			});




	
	
	// Do something in (n) element
/*
			var i = 0;
		    $('.test div').each(function() {
				var item = $('div:eq('+i+')');
    				i=i+2;
			    	item.css({ backgroundColor: 'yellow' });
		    });
		    


		    
		   $.fn.loo = function(value) {
				var i = 0;
				var o = $(this);
				
				$(o).each (function() {
					if (i > 0 && (i % value) == 0) {
			        	$(this).css({
							background: 'red'
						});
					}
					i++;
				});
			}
			$(".gallery .box").loo(3);
			
			
*/




});



