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

$(document).ready(function(){


// Tables even row

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

	if($('#news').length > 0) {
		$('#news .row:first').addClass('first');
	}


//poziome rozwijane menu

$('aside .lvl2').not('.hit > ul').hide();
$('aside .lvl3').not('.hit > ul').hide();
$('aside .lvl4').not('.hit > ul').hide();

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

	$(this)
		.parent()
		.find('> li ul:visible')
		.slideToggle(300);
	$(this)
		.find('ul:first')
		.stop(true, true)
		.slideToggle(300);
});



// search value

	$('#search input').click(function(){$(this).val('')});

	$('#search input').blur(function(){
		if($('#search input').val() == '') {
			$(this).val('search...')
		}
	});




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


// slideshows

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

	if($('.ba').length > 0) {
		$.getScript('js/jquery.qbeforeafter.js', function(){
			$('.ba').qbeforeafter({
				defaultgap:200,
				leftgap:10,
				rightgap:10,
				caption: true
			});
		});
	}







$('ul li:even').addClass('even');

$('.seealso a').not('.seealso li:last-child a').after(", ");




}); // ready end

var pat; var pathlast;

pat = document.getElementById('path').getElementsByTagName('li');
pathlast = pat[pat.length-1];

if(pathlast.innerHTML.length > 55) {
	var plt = pathlast.innerHTML.substring(0, 55);
	pathlast.innerHTML=plt+"...";
}















	
