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

Cufon.replace('.lvl1 > li > a', {hover:true})('#vert a')('.gal-products strong')('h1')('h2')('h3')('h4')('h5');

$(document).ready(function(){

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

// nawigation

	$('#horz .lvl2').slideUp();
	$('#horz ul li').mouseover(function(){
		if($('.lvl2').is(':hidden')){$(this).find('.lvl2').stop(true, true).fadeIn(300);}
	});
	$('#horz ul li').mouseleave(function(){
		if($('#horz .lvl2').is(':visible')){$(this).dequeue().find('.lvl2').stop(true, true).fadeOut(300);}
	});

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

	$('aside li').click(function(){
		$('aside li .lvl2').not(this).slideUp();
		$(this).find('.lvl2').slideToggle();
	});

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



// more colors & photos

	$('.moreColors').click(function(){
		$(this).parent().find('.colors').slideToggle(300);
	});

	$('.morePhotos').click(function(){
		$(this).parent().find('.gallery').slideToggle(300);
	});



// Vert nav [home]

	//animacja boksów na startowej

		$('#vert li, .home #fbk').hide();
		$('#vert li').each(function(index){
			var $li = $(this);
			delay = 100;

			setTimeout(function(){
				$li.fadeIn(500);
			}, index * delay);
		});

		$('.home #fbk').delay(800).fadeIn(500);

	// hover

	$('.home #vert a').prepend('<span />');
	$('.home #vert a').hover(function(){
		$(this).find('span').stop(true, false).animate({marginLeft: 0}, 300);
	}, function(){
		$(this).find('span').animate({marginLeft: -15}, 300);
	});

// blank

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



// search input val

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

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

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



// Gallery

	if ($('.gallery, .productPhotos, .g, #categories').length > 0) {
		$.getScript('js/jquery.prettyPhoto.js', function(){
			$(".gallery a, .productPhotos a, .g a, #categories a").not('#pages a, .katalog a, p a').prettyPhoto({
				theme: 'light_square',
				overlay_gallery: false
			});
		});
	}

// Form validate

		if($('form').length > 0) {
			$('form').not('#search').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, button').fadeOut(300);
						$('#ok').delay(300).fadeIn(300);
					} else {
						$('#ok').fadeIn(300);
					}

					$('input, textarea').attr('disabled', 'disabled');
				});
			});
		}



// slideshow

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

// sub slideshow

	if($('#subslides').length > 0) {
		$.getScript('js/jquery.cycle.all.min.js', function(){
			$('#subslides').cycle({
				timeout:	3000,
				speed:		2000,
				sync:		1
			});
		});
	}


// slideshow - ost. realizacje

	if($('#realizacje').length > 0) {
		$.getScript('js/jquery.cycle.all.min.js', function(){
			$('#realizacje .slides').cycle({
				fx:			'scrollHorz',
				timeout:	3000,
				speed:		1000,
				sync:		1
			});
		});

		$('#realizacje').hover(function(){
			$('#realizacje .slides').cycle('pause');
		}, function(){
			$('#realizacje .slides').cycle('resume', true);
		});
	}


// polecane

	if($('#polecaneSlides').length > 0) {
		$.getScript('js/jquery.cycle.all.min.js', function(){
			$('#polecaneSlides').cycle({
				fx:			'scrollHorz',
				timeout:	5000,
				speed:		2500,
				sync:		1,
				next:		'#polecane .next',
				prev:		'#polecane .prev',
				pause: true
			});
		});
	}

// adv

	if($('#adv li').length > 8) {
		$.getScript('js/jquery.cycle.all.min.js', function(){
			$('#adv').cycle({
				fx:			'scrollHorz',
				continuous: 1,
				easing: 'linear',
				speed:		9500,
				sync:		1,
				pause: true
			});
		});
	}


// hovers

	$('p a').hover(
		function(){
			$(this).animate({opacity: .8}, 200);
		},
		function(){
			$(this).animate({opacity: 1}, 200);
		}
	);

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




}); // ready end
