// studiofabryka.pl
// mc, pneumatech, 11 aug 2011

$(document).ready(function(){

	if($('table').length > 0) {
		$('table tr:even').addClass('even');
	}
	$('ul li:last-child').addClass('last');


// slideshow > main

	if($('.sub #slideouter').length > 0) {
		$('#main').addClass('narrow');
	}




//poziome rozwijane menu

$('nav ul li').mouseover(function(){
	if($('.lvl2').is(':hidden')){$(this).find('.lvl2').stop(true, true).slideDown(200);}
});
$('nav ul li').mouseleave(function(){
	if($('.lvl2').is(':visible')){$(this).dequeue().find('.lvl2').stop(true, true).slideUp(100);}
});

$('.lvl2').hover(function(){
	$(this).parent().find('a:first').addClass('subopen');
	}, function(){
	$(this).parent().find('a:first').removeClass('subopen');
});

$('.lvl2').prev('a').hover(function(){
	$(this).addClass('subopen');
	}, function(){
	$(this).removeClass('subopen');
});



// inputs value

$('input').click(function(){

	if($(this).val() != ""){
		$(this).val("");
	}
});



// 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
			});
		});
	}



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



// Form validate

		if($('form').length > 0) {
			$('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($('form').length > 0) {
			$.getScript('js/jquery.form.js', function(){
				$('form').not('#search').ajaxForm(function(){
					if($('#error').is(':visible') == true) {
						$('#error').fadeOut(300);
						$('#ok').delay(300).fadeIn(300);
					} else {
						$('#ok').fadeIn(300);
					}

					$('input, 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
			});
		});
	}



// slideshows

	if($('#slideshow').length > 0) {
	$('#slideshow img').load(function() {

		$.getScript('js/jquery.cycle.all.min.js', function(){
			$('#slideshow').cycle({
				pause: true,
				timeout: 4000,
				speed: 1200,
				sync:1

			});
		});
	});
	}





$.fn.vAlign = function() {
	return this.each(function(i){
	var ah = $(this).height();
	var ph = $(this).parent().height();
	var mh = Math.ceil((ph-ah) / 2);
	$(this).css('margin-top', mh);
	});
};

$('.slides a').vAlign();




}); // ready end
