$(document).ready(function() {

	$('#survey').hover(function(){
		$(this).animate({left: '0'})
		$('#fb').hide();
	},function(){
		$(this).animate({left: '-197px'});
		$('#fb').show();
	});

	$('#fb').hover(function(){
		$(this).animate({left: '0'});
	},function(){
		$(this).animate({left: '-197px'});
	});

	$('.public-house-panel .single').hover(function(){
		$('.public-house-panel div').removeClass('select');
		$(this).addClass('select');
	});
	$('#project-nav li').hover(function(){
		$('#project-nav li').removeClass('select');
		$(this).addClass('select');
	});
	$('#marquee div').marquee('marquee-content', 50);

	$('.project-form .info .buton').toggle(function(){
		$(this).next('.desc').slideDown();
		changeText($(this), new Array('rozwiń opis', 'zwiń opis'))
	},function(){
		$(this).next('.desc').slideUp();
		changeText($(this), new Array('rozwiń opis', 'zwiń opis'))
	});
	$('.slide-down, .slide-up').toggle(function(){
		$($(this).attr('rel')).slideDown();
		changeText($(this), new Array('rozwiń cały tekst', 'zwiń cały tekst'))
	},function(){
		$($(this).attr('rel')).slideUp();
		changeText($(this), new Array('rozwiń cały tekst', 'zwiń cały tekst'))
	});

	var all_slides = 0;
	$('.promotions #slides div').each(function(){
		all_slides += 1;
	})
	var active_slide = 0;
	var intervalID = setTimeout(function(){
		changeSlide('next')
	}, 6000)
	$('.promotions .next').click(function(){
		changeSlide('next', 'none')
	})

	$('.promotions .prev').click(function(){
		changeSlide('prev', 'none')
	})


	function changeSlide(action, $break){
		$('.promotions #slides div:eq('+active_slide+')').hide();
		if(action=='prev'){
			active_slide -= 1;
			if(active_slide<0) active_slide = (all_slides-1);
		}else{
			active_slide += 1;
			if(active_slide>(all_slides-1)) active_slide = 0;
		}
		$('.promotions #slides div:eq('+active_slide+')').fadeIn();
		if($break==undefined){
			intervalID = setTimeout(function(){changeSlide('next')}, 6000);
		}else{
			clearTimeout(intervalID);
		}
	}

	function changeText(a, text){
		if(a.text()==text[0])
			a.text(text[1])
		else{
			a.text(text[0])
		}
	}

	$('.team .all li a').hover(function(){
		$(this).parent('li').siblings('li').removeClass('select');
		$(this).parent('li').addClass('select');
		$($(this).attr('rel')).siblings('.people').hide();
		$($(this).attr('rel')).show();
	})


	$('.project-list .single img').mouseover(function(){
		var $this = $(this).attr('src');
		$(this).attr('src', $(this).parent('a').attr('rel'));
		$(this).parent('a').attr('rel', $this)
	})
	$('.project-list .single img').mouseout(function(){
		var $this = $(this).attr('src');
		$(this).attr('src', $(this).parent('a').attr('rel'));
		$(this).parent('a').attr('rel', $this)
	})

	$('#form li.category select option').click(function(){
		$rel = $(this).attr('rel');
		if($rel==1){
			$('#form li.roof, #form li.typ').hide();
			$('#form li.floors').show();
		}else{
			$('#form li.roof, #form li.typ').show();
			$('#form li.floors').hide();
		}
		//alert($(this).attr('rel'));
	});

	var options = {
	    title: false,
	    zoomWidth: 380,
	    zoomHeight: 300,
	    preloadText: 'Ładowanie...'
	}

	$('.zoom-product-first').jqzoom(options);

	 $(".product-change").each(function(){
		  	$(this).click(
				function(){
					$(".zoomed").css('display', 'none');
					$('.'+$(this).attr('rel')).jqzoom(options).css('display', 'block');
					return false;
				}
			);
		  });

});
