// studiofabryka.pl
// mc, joker, 25 paz 2011

$(document).ready(function(){


// długość aside
	$('aside').css('minHeight', $('.sections').height());

// ostatni news na głównej
	$('#news .news:last').addClass('last');

// path a
	$('.path a').parent().after('<li>&raquo;</li>');


// 3 mecze
	//$('.games .game').eq(1).find('.type').text('Juniorki');
	//$('.games .game').eq(2).find('.type').text('Kadetki');


// wielopoziomowy akordeon

$('aside nav ul.lvl2, aside nav ul.lvl3').not('.current ul:first').hide();

$('.lvl2 .current > .lvl3').show();


$('aside .lvl2 > li > a').prepend('- ');


$('aside nav li').click(function() {
	var selfClick = $(this).find('ul:first').is(':visible');
	if (selfClick) {
		return;
	}
	$(this)
		.parent()
		.find('> li ul:visible')
		.slideToggle();
	$(this)
		.find('ul:first')
		.stop(true, true)
		.slideToggle();
});


// typ pliku wg linku w download

	$('.typPliku').each(function(){
		$(this).text('('+ $(this).parent().attr('href').substring($(this).parent().attr('href').length - 3) +')');
		$(this).addClass($(this).parent().attr('href').substring($(this).parent().attr('href').length - 3));
	});

// last li

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


//tabele

	$('table tr:first-child').addClass('firstrow');
	$('table tr:even').addClass('even');


// blank

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

// Gallery

	if ($('.fancy').length > 0) {
			$(".fancy").fancybox({
				titlePosition: 'over',
				overlayOpacity: 0.8,
				overlayColor: '#000'
			});
	}



// Form validate

	$('#error').hide();


	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 *') || ($(this).val() == 'email *') || ($(this).val() == 'np. 8:00 *') || ($(this).val() == 'np. 16:00 *')){
					$(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, #contact-form select, #contact-form button').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
			});
		});
	}



//slideshow

	if($('.slideshow').length > 0){
		$.getScript('js/jquery.cycle.all.min.js', function(){
			$('.slideshow').cycle({
				sync:1,
				timeout: 4000,
				speed: 800,
				cleartype:  false
			});
		});
	}


// sponsorzy

if($('.sponsors').length > 0) {
	$.getScript('js/jquery.cycle.all.min.js', function(){
		$('.slider').cycle({
			fx: "blindY",
			pause: true,
			speed: 800,
			timeout: 3000,
			sync: 1,
			cleartypeNoBg:true,
			next:   '.sponsors .next',
			prev:   '.sponsors .prev'
		});
	});
}




$('.iframe').fancybox({
	width:550,
	height: 470,
	scrolling: 'no',
	padding:5,
	margin:0
});


}); // ready end
