$(document).ready(function() {
	
	gemius_hit(".FDqwXh2m5yZAUmC2kEbKLSmLd8Ke8MCKW91Hm4oGaD.R7");

	
	// pokazywanie boksow ind i korpo + karuzela
	
	$('.see-ind-customers').click(function(e){
		e.preventDefault();
		carouselInd();
		runCarouselInd = true;
		$('.buttons').fadeOut("fast", function(){
			$('.ind-customers').fadeIn();
			$('.site-wrapper .body .prizes-info .common-ranking-list').fadeOut(function(){
				
				$('.carousel-ind').fadeIn();
				$("#carousel-controler-ind").fadeIn();
				$('.home-text').hide();
				$('.ind-text').fadeIn();
				$('.back-button').fadeIn();
			});
		});
		gemius_hit("olTgGz8Iv8yePMKnF1Jnq5Srj8M6bBseH5wIEGjc.mH.C7");
	});
	
	$('.see-corpo-customers').click(function(e){
		e.preventDefault();
		carouselCorpo();
		runCarouselCorpo = true;
		$('.buttons').fadeOut("fast", function(){
			$('.corpo-customers').fadeIn();
			$('.site-wrapper .body .prizes-info .common-ranking-list').fadeOut(function(){
				
				$('.carousel-corpo').fadeIn();
				$("#carousel-controler-corpo").fadeIn();
				$('.home-text').hide();
				$('.corpo-text').fadeIn();
				$('.back-button').fadeIn();
			});
		});
		gemius_hit(".FDqH3h2m_WTSkli8SWTELSm78wKe9tOiQiSFj6dBu3.e7");
	});
	
	// przelaczanie sie pomiedzy boksami
	
	$('.site-wrapper .body .ind-customers .prizes .see-more, .site-wrapper .body .ind-customers .see-offer-2').click(function(e){
		e.preventDefault();
		carouselCorpo();
		runCarouselCorpo = true;
		$('.ind-customers').fadeOut("fast", function(){
			$('.corpo-customers').fadeIn();
			$('.carousel-ind').hide();
			$("#carousel-controler-ind").hide();
			
			$('.carousel-corpo').fadeIn();
			$("#carousel-controler-corpo").fadeIn();
			$('.ind-text').hide();
			$('.corpo-text').fadeIn();
		});
		
		gemius_hit(".FDqH3h2m_WTSkli8SWTELSm78wKe9tOiQiSFj6dBu3.e7");
		
	});
	
	$('.site-wrapper .body .corpo-customers .prizes .see-more').click(function(e){
		e.preventDefault();
		carouselInd();
		runCarouselInd = true;
		$('.corpo-customers').fadeOut("fast", function(){
			$('.ind-customers').fadeIn();
			$('.carousel-corpo').hide();
			$("#carousel-controler-corpo").hide();
		
			$('.carousel-ind').fadeIn();
			$("#carousel-controler-ind").fadeIn();
			$('.corpo-text').hide();
			$('.ind-text').fadeIn();
		});
		gemius_hit("olTgGz8Iv8yePMKnF1Jnq5Srj8M6bBseH5wIEGjc.mH.C7");
	});
	
	// powrót do głownej
	
	$('.logo,.back-button').click(function(e){
		e.preventDefault();
		$('.ind-customers').fadeOut("fast", function(){
			$('.buttons').fadeIn();
			$('.carousel-controler').fadeOut();
			$('.carousel').fadeOut(function(){
					$('.site-wrapper .body .prizes-info .common-ranking-list').fadeIn();
			});
			$('.ind-text').hide();
			$('.home-text').fadeIn();
			$('.back-button').fadeOut();
		});
		
		$('.corpo-customers').fadeOut("fast", function(){
			$('.buttons').fadeIn();
			$('.carousel-controler').fadeOut();
			$('.carousel').fadeOut(function(){
					$('.site-wrapper .body .prizes-info .common-ranking-list').fadeIn();
			});
			$('.corpo-text').hide();
			$('.home-text').fadeIn();
			$('.back-button').fadeOut();
		});
	});
	
	// rozwijanie i zwijanie contentu
	
	$('.site-wrapper .body .content .wrapper dl dd .see-more').click(function(e){
		e.preventDefault();
		$(this).hide('fast');
		$(this).parent().find('.see-less').show();
		$(this).parent().find('p').css("height","auto");
	});
	
	$('.site-wrapper .body .content .wrapper dl dd .see-less').click(function(e){
		e.preventDefault();
		$(this).hide('fast');
		$(this).parent().find('.see-more').show();
		$(this).parent().find('p').css("height","16px");
	});
	
	// layer
	
	
	function layerShow(){
			$('.layer-background').show();
			$('.layer-content').show();
			$('.layer-background').css('height', $(document).height()+'px');
			$('html').animate({scrollTop: 0});
	}
	
	$('.layer-content .close-button').click(function(){
			$('.layer-content').hide();
			$('.layer-content .wrapper').hide();
			$('.layer-background').hide();
			$('html').animate({scrollTop: $(document).height()});
		
	});

	$('.common-ranking-list li a').bind("click", function(e){
		e.preventDefault();
		layerShow();
		if($(this).parent().hasClass("ranking-1")){
			$('.layer-content .ranking-1').show();
			$('.layer-content').css('margin-top', -$('.layer-content .ranking-1').outerHeight()/2+'px');
		}
		if($(this).parent().hasClass("ranking-2")){
			$('.layer-content .ranking-2').show();
			$('.layer-content').css('margin-top', -$('.layer-content .ranking-2').outerHeight()/2+'px');
		}
		if($(this).parent().hasClass("ranking-3")){
			$('.layer-content .ranking-3').show();
			$('.layer-content').css('margin-top', -$('.layer-content .ranking-3').outerHeight()/2+'px');
		}
		if($(this).parent().hasClass("ranking-4")){
			$('.layer-content .ranking-4').show();
			$('.layer-content').css('margin-top', -$('.layer-content .ranking-4').outerHeight()/2+'px');
		}
		if($(this).parent().hasClass("ranking-5")){
			$('.layer-content .ranking-5').show();
			$('.layer-content').css('margin-top', -$('.layer-content .ranking-5').outerHeight()/2+'px');
		}
		if($(this).parent().hasClass("ranking-6")){
			$('.layer-content .ranking-6').show();
			$('.layer-content').css('margin-top', -$('.layer-content .ranking-6').outerHeight()/2+'px');
		}
	});
	
	// inicjalizacja i ustawienia karuzeli
	function carouselInd(){
		if(!runCarouselInd){
			$(".carousel-ind-wrapper").show();
			$(".carousel-ind").easySlider({ 
				numeric: true,
				auto: true,
				continuous: true,
				numericId: 'carousel-controler-ind',
				pause: 5000,
				speed: 200
			});
			$(".carousel-ind").hide();
			$("#carousel-controler-ind").hide();
		}
	}
	
	function carouselCorpo(){
		if(!runCarouselCorpo){
			$(".carousel-corpo-wrapper").show();
			$(".carousel-corpo").easySlider({ 
				numeric: true,
				auto: true,
				continuous: true,
				numericId: 'carousel-controler-corpo',
				pause: 5000,
				speed: 200
			});
			$(".carousel-corpo").hide();
			$("#carousel-controler-corpo").hide();
		}
	}
	
	var runCarouselInd, runCarouselCorpo = false;
	
	
	
});