// studiofabryka.pl
// mc, 16 june 2011

$(document).ready(function(){

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





// Form validate

		if($('form').length > 0) {
			$('form').not('#search, #newsletter, #login').bind('submit', function(){
				var valid = true;
				$('.required').click(function(){
					$(this).removeClass('error-input');
				});
				$('.required').not('#subject').each(function(){
					if(($(this).val()=='') || ($(this).val()=='dd') || ($(this).val()=='mm') || ($(this).val()=='rrrr')){
						$(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, #newsletter, #login').ajaxForm(function(){
					if($('#error').is(':visible') == true) {
						$('#error').fadeOut(300);
						$('#ok').delay(300).fadeIn(300);
					} else {
						$('#ok').fadeIn(300);
					}
					$('input, textarea').not('#search input, #newsletter input').attr('disabled', 'disabled');
					$('button, input[type="submit"]').not('#search button, #newsletter button, #search input[type="submit"], #newsletter input[type="submit"], #search input[type="submit"]').hide();
				});
			});
		}






//menu animation

	//hover 4#blue nav
	$('#blue a').hover(function(){
		$(this).stop(true, false).animate({
			opacity:.8,
			textIndent: 10
		}, 300);
	}, function(){
		$(this).animate({
			opacity:1,
			textIndent:0
		}, 300);
	});

	//hover 4#strefy nav
	$('#strefy a').hover(function(){
		$(this).stop('true, false').animate({opacity:.9}, 200);
		$(this).find('span').stop('true, false').animate({paddingBottom:10}, 200);
	}, function(){
		$(this).animate({opacity:1}, 200);
		$(this).find('span').animate({paddingBottom:2}, 200);
	});


// sub aside nav

	$('.sub aside nav .lvl2 a').prepend('- ');

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

	$('.lvl2').parent().css('cursor', 'pointer');


// blank

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

// search & newsletter input val

	searchVal = $('#search input').val();
	letterVal = $('#newsletter input').val();

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

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

// Gallery

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





// slideshow

	if($('#slideshow').length > 0) {
		$.getScript('js/jquery.cycle.all.min.js', function(){
			$('#slides').cycle({
				fx:			'scrollHorz',
				timeout:	4000,
				speed:		500,
				sync:		1,
				pager:		'#slidenav',
				pause: true,
				cleartypeNoBg: true
			});
		});
	}

// img hovers

	$('a').find('img').not('#slides img, #logo img').hover(
		function(){
			$(this).animate({opacity: .7}, 300);
		},
		function(){
			$(this).animate({opacity: 1}, 300);
		}
	);

//button hovers

	$('button').hover(function(){
		$(this).css({
			cursor: 'pointer',
			opacity:.8
		});
	}, function(){
		$(this).css({
			cursor: 'pointer',
			opacity:1
		});
	});



// sklepy - gdzie kupić

	$('.sklepy').hide();

	$('#polska li').click(function(){
		var maplink = $(this).find('a').attr('href').substring(2);

		$('#map-pl, .mapinfo').slideUp(300);
		$('.sklepy').filter(':visible').slideUp(300);
		$('.sklepy').load('/templates/inc_sklep.php?id='+ maplink).delay(300);
		$('.sklepy').fadeIn(300);
	});

	$('.togglemap').live('click', function(){
		$('#map-pl, .mapinfo').slideDown(300);
		$('.sklepy').filter(':visible').slideUp(300);
	});



// rejestracja

	if($('.rejestracja-link').length > 0) {
		$('.rejestracja-link').click(function(){
			$('.rejestracja').slideDown();
		});
	}


//$('aside nav .lvl1 > li:last-child').before('<li><a href="/dystrybutorzy.html">Dystrybutorzy</a></li>');

}); // ready end
