// studiofabryka.pl
// mc, elgato, 3 aug 2011

Cufon.replace('nav a, .sub aside .lvl1 > li > a', {hover:true, fontFamily: 'mpb'})('h1', {fontFamily: 'mpc'})('h2', {fontFamily: 'mpb'})('aside h2', {fontFamily: 'mpc'})('h3', {fontFamily: 'mpb'})('h4')('h5')('th');

$(document).ready(function(){



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

	$('section h2:first').addClass('firstH2');


// 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
	$('.sub aside .lvl1 li').click(function(){
		$('.lvl2').not('.hit').slideUp();
		$(this).find('.lvl2').slideDown();
	});




// animacja w topie

	$('h1').animate({marginRight: 0}, 1200, 'swing');



// blank

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


// Gallery

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

		$('a img').hover(function(){
			$(this).animate({opacity: .8}, 200);
		}, function(){
			$(this).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).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
			});
		});
	}

	$('.zadajpytanie').hide();
	$('.pytanie').hide();

	if($('.bogone').length > 0) {
		$('.zadajpytanie').show();

		$('.zadajpytanie').click(function(){
			$('form').slideToggle();
		});

		$('.zadajpytanie').hover(function(){
			$(this).animate({opacity:0.8});
		}, function(){
			$(this).animate({opacity:1});
		});
	}


}); // ready end
