// studiofabryka.pl
// mc, kaczmarek, 17 aug 2011

$(document).ready(function(){


// Tables even row

	if($('table').length > 0) {
		$('table tr:even').addClass('even');
	}

	$('.keywords').animate({top:0}, 800);
	
	

// family

		$('.family').hide().fadeIn(800);
	


// blank

	if($('.blank').length > 0) {
		$('.blank').click( function() {
			window.open(this.href);
			return false;
		});
	}


// Gallery

	if ($('.gallery').length > 0) {
		$.getScript('js/jquery.prettyPhoto.js', function(){
			$(".gallery a").not('.gi a').prettyPhoto({
				theme: 'light_square',
				opacity: 0.40
			});
		});
	}


// links containing images

	$('a').hover(function(){
		$(this).find('img').animate({opacity: .8}, 200);
	}, function(){
		$(this).find('img').animate({opacity: 1}, 200);
	});



// Form validate

	if($('#contact-form').length > 0) {
		$('#contact-form').bind('submit', function(){
			var valid = true;
			$('.required').click(function(){
				$(this).removeClass('error-input');
			});
			$('.required').not('#subject').each(function(){
				if(($(this).val()=='') || ($('#subject').val()!='') || ($(this).val() == 'imię i nazwisko/nazwa firmy') || ($(this).val() == 'adres e-mail') || ($(this).val() == 'wiadomość')){
					$(this).addClass('error-input');
					 valid = false;
				}else{
					$(this).removeClass('error-input');
				}
			});
			if(!valid){
				$('#error').fadeIn();
				return false;
			}
		});
	}

	// ajax form

		if($('#contact-form').length > 0) {
			$.getScript('js/jquery.form.js', function(){
				$('#contact-form').ajaxForm(function(){
					if($('#error').is(':visible') == true) {
						$('#error').fadeOut(300);
						$('#ok').delay(300).fadeIn(300);
					} else {
						$('#ok').fadeIn(300);
					}

					$('#contact-form input, #contact-form textarea').attr('disabled', 'disabled');
				});
			});
		}


//button hovers

	if($('button').length > 0) {
		$('button').hover(function(){
			$(this).css({
				cursor: 'pointer',
				opacity:.8
			});
		}, function(){
			$(this).css({
				cursor: 'pointer',
				opacity:1
			});
		});
	}



// left menu hover

	$('.lvl1 > li > a').hover(function(){
		$(this).find('img').stop(true, false).animate({marginLeft: 0}, 200);
	},  function(){
		$(this).find('img').stop(true, false).animate({marginLeft: 5}, 200);
	});


// li.hit jest zawsze rozwinięte, reszta ukryta
	$('.lvl2').not('.hit .lvl2').hide();

	$('.lvl2 li').click(function(){
		$(this).parent().addClass('hit');
	});

	//rozwijanie odpowiedniego poziomu i zwijanie pozostałych
	$('.lvl1 li').click(function(){
		$('.lvl2').not('.hit').slideUp();
		$(this).find('.lvl2').slideDown();
	});


// kategorie główne

	$('.kategorie a').hover(
		function(){
			$(this).find('em').slideDown();
		}, function(){
			$(this).find('em').slideUp();
	});


// instalacje

	if($('.realizacje').length > 0) {
		$.getScript('js/jquery.cycle.all.min.js', function(){
			$('.slides').cycle({
				sync:1,
				fx: 'scrollHorz',
				timeout:3000,
				speed:800,
				pause: true
			});
		});
	}


}); // ready end
