// studiofabryka.pl

// mc, ziemniak, 30 june 2011



$(document).ready(function(){



$('.lvl2 a').prepend('<strong>- </strong>');



// li.hit jest zawsze rozwinięte, reszta ukryta

	$('.lvl2').not('.hit .lvl2').hide();



	//rozwijanie odpowiedniego poziomu i zwijanie pozostałych

	$('.lvl1 li').click(function(){

		$('li .lvl2').not(this).slideUp();

		$(this).find('.lvl2').slideToggle();

	});



$('ul li:last-child').addClass('last');

$('table tr:even').addClass('even');



// listy

	$('section li').not('.gallery li, .gallery-index li').wrapInner('<span />');



// blank



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

		window.open(this.href);

		return false;

	});



// Gallery



	if ($('.gallery').length > 0) {

		$.getScript('js/jquery.prettyPhoto.js', function(){

			$(".gallery a").not('.back').prettyPhoto({

				theme: 'light_square',

				opacity: 0.50

			});

		});



		$('.gallery a').not('.back').prepend('<div class="gmask"></div>');

	}



	$('.gallery-index a').prepend('<div class="gimask"></div>');



// 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).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').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



	$('button').hover(function(){

		$(this).css({

			cursor: 'pointer',

			opacity:.8

		});

	}, function(){

		$(this).css({

			cursor: 'pointer',

			opacity:1

		});

	});









}); // ready end
