$(function() { 
    $('#quote-slider').cycle({ 
        fx:     'fade', 
        speed:   600, 
        timeout: 60000, 
        pager:  '#quote-nav', 
        before: function() {  
            $('#caption').html(this.alt); 
        } 
    }); 
	 
	   $('#logo-slider').cycle({ 
        fx:     'fade', 
        speed:   600, 
        timeout: 6000,  
        before: function() {  
            $('#caption').html(this.alt); 
        } 
    }); 
		
		$('#blog-slider').cycle({ 
        fx:     'fade', 
        speed:   600, 
        timeout: 6000, 
        pager:  '#blog-nav'
    }); 
	 jQuery.fn.fadeToggle = function(speed, easing, callback) {
   return this.animate({opacity: 'toggle'}, speed, easing, callback);

}; 
	 $('.faq h2').click(function() {
		$(this).next().fadeToggle() 
		return false;
	}).next().hide();
	 
	
	$(".calc2").click(function(){
										$("#wrap").fadeIn('medium');
																				});
	
	$(".calculator").click(function(){
										$("#oblicz-koszt").fadeIn('medium');
																				});
	
	$('#wrap .close').click(function() {
		$('#wrap').fadeOut() 
		return false;
	})
	
	$('#oblicz-koszt .close').click(function() {
		$('#oblicz-koszt').fadeOut() 
		return false;
	})
	
	
	$('#show-more-1 a').click(function() {
												$('.show-more a').removeClass('active');
												$(this).addClass('active');
				$('.wyniki').hide()									
		$('#pierwsze-losowanie').show() 
		
		return false;
	});
	$('#show-more-2 a').click(function() {
													$('.show-more a').removeClass('active');
												$(this).addClass('active');
		$('.wyniki').hide()									
		$('#drugie-losowanie').show()  
		
		return false;
	});
	$('#show-more-3 a').click(function() {
													$('.show-more a').removeClass('active');
												$(this).addClass('active');
		$('.wyniki').hide()									
		$('#trzecie-losowanie').show()  
		return false;
	});
	
	 $(".faq h2").hover(function(){
$(this).addClass("hover");
$(this).fadeTo("slow", 0.5); // This should set the opacity to 100% on hover
},function(){
$(this).fadeTo("slow", 1.0); $(this).removeClass("hover"); // This should set the opacity back to 60% on mouseout
});

	 
	 	  $("#hot-news .close").click(function() { 
        $("#hot-news").fadeOut('slow');
        return false;});
	 
	 	  $("a#play").click(function() { 
        $("#vimeo").fadeIn('slow');
        return false;});
	 
		  $(".popup-answerwrong a.close").click(function() { 
        $(".popup-answerwrong").fadeOut('slow');
        return false;});
		  
		  $("#vimeo a.close").click(function() { 
        $("#vimeo").fadeOut('slow');
        return false;
			}); 
 
 			$("#ad a#play").fancybox({

		      'autoScale'     	: true,
		      'transitionIn'	: 'elastic',
				'transitionOut'	: 'elastic',
			});

 			$("#main-content a.lightbox").fancybox({
		      'autoScale'     	: true,
		      'transitionIn'	: 'elastic',
				'transitionOut'	: 'elastic',
			});
 

 
 
 //$("a[href$='.pdf']").addClass("pdf");
 

$("#sidebar .current_page_item").hover(function() {
	  $(this).animate({"marginLeft": "-40px"}, "medium");
	}, function() {
	  $(this).animate({"marginLeft": "-20px"}, "fast");
	});


	
$("a.popup").hover(function() {
									 						
								
		$(this).after('<span class="popup">' +this.title + '</span>').fadeIn('slow').animate({ top: "0"}, "slow");
		
}, function() {
	
$(this).next("span").fadeOut('medium').animate({ top: "-20"}, "fast").remove();

});

	
	 
$(".rss-popup a").hover(function() {
$(this).next("em").stop(true, true).animate({opacity: "show", top: "-60"}, "slow");
}, function() {
$(this).next("em").animate({opacity: "hide", top: "-70"}, "fast");
});


$("#videotutoriale h3 a").click(function() {
	$.fancybox({
			'padding'		: 0,
			'autoScale'		: false,
			'transitionIn'	: 'none',
			'transitionOut'	: 'none',
			'title'			: this.title,
			'width'		: 680,
			'height'		: 495,
			'href'			: this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
			'type'			: 'swf',
			'swf'			: {
			   	 'wmode'		: 'transparent',
				'allowfullscreen'	: 'true'
			}
		});

	return false;
});

	$(".videobox > h3:nth-child(2n)").addClass("no-margin-r");


$("#number-tooltip").css({opacity:0.8});

	 $("#number-tooltip").hover(
	
  function () { 
    $(this).animate({ top: -398, opacity: 1 }, 160);;
  },
  function () {
     $(this).animate({ top: -396, opacity: 0.8 }, 150);
  }
);
	
	
$("#live-button").hover(function() {
									 						
								
		$("#demo-tooltip").fadeIn('slow').animate({ top: "-64"}, "medium");
		
}, function() {
	
$("#demo-tooltip").fadeOut('medium').animate({ top: "-70"}, "fast");

});

// Kalkulator cenowy

	$(function(){
														  
		 function calculateTotalPrice() {
			 var suma, a, b, cena, wpol, abonament, kosztsystemu, dodatkowe, zysk, cena2, wspol2;
			 a = 0; 
			 b = 0; 
			 abonament = 6;
			 kosztsystemu = 0;
			 dodatkowe = 0;
			 zysk = 0;
			 
			 cena = 100; // parseInt($("#cenna").val());
			 wspol = 15; //parseInt($("#wspol").val());
			 
			 cena2 =  parseInt($("#cenna").val());
			 wspol2 = parseInt($("#wspol").val());
			 
			 a = parseInt($(".pracownicy").val());
			 b = parseInt($(".abonament").val());
			 
			 if(a==1){ abonament=99;} 
			 else if (a==2){ abonament=2*94.05;} 
			 else if (a==3){ abonament=3*94.05;} 
			 else if (a==4){ abonament=4*89.10;} 
			 else if (a==5){ abonament=5*89.10;;} 
			 else if (a==6){ abonament=6*84.15;} 
			 else if (a==7){ abonament=7*84.15;} 
			 else if( a>7 ){abonament=a*79.20;}
			 if(b==6){ kosztsystemu=280/6; } 
			 else if (b==12){ kosztsystemu=499/12;}
			 
			 suma = (parseFloat(abonament.toFixed(2))+parseFloat(kosztsystemu.toFixed(2)));
			 
			 nieodwolane = a*wspol2;
			 strata = a*wspol2*cena2;
			 uratowane = a*wspol2*0.5;
			 zysk = (wspol2*cena2*a)*0.5; 
			 dodatkowe = zysk*12;	
			
			
			
			$(".pracownicy").val(a.toFixed(0));
			$(".abonament").val(b.toFixed(0));
			$("#suma-mies").val(dodatkowe.toFixed(0));
			$("#miesiace").val(b.toFixed(0));
			$("#srednia").val(cena2.toFixed(0));
			$("#strata").val(strata.toFixed(0));
			$(".nieodwolane").val(nieodwolane.toFixed(0));
			$(".uratowane").val(uratowane.toFixed(0));
			$(".koszt").val(suma.toFixed(2));
			$(".zysk").val(zysk.toFixed(0));
			
			$("#story .pracownicy").text(a.toFixed(0));
			$("#story .abonament").text(b.toFixed(0));
			$("#story #suma-mies").text(dodatkowe.toFixed(0));
			$("#story #miesiace").text(b.toFixed(0));
			$("#story #srednia").text(cena2.toFixed(0));
			$("#story #strata").text(strata.toFixed(0));
			$("#story .nieodwolane").text(nieodwolane.toFixed(0));
			$("#story .uratowane").text(uratowane.toFixed(0));
			$("#story .koszt").text(suma.toFixed(2));
			$("#story .zysk").text(zysk.toFixed(0));
			
			// simple
			
    }
				
// People
				$('.people').slider({	
					value:2,
					min: 1,
					max: 20,
					step: 1,
					slide: function(event, ui) {
						$(".pracownicy").val(ui.value); 
						calculateTotalPrice();
				}
				});
				
// Time
				$('.time').slider({
					value:6,
					min: 6,
					max: 12,
					step: 6,
					slide: function(event, ui) {
						$(".abonament").val(ui.value); 
						calculateTotalPrice();
					}
				});

// Wspolczynnik odrzucen na osobe
				$('#wspolczynnik').slider({
					value:8,
					min: 1,
					max: 100,
					step: 1,
					slide: function(event, ui) {
						$("#wspol").val(ui.value); 
						calculateTotalPrice();
					}
				});
				
// Cena za usluge
				$('#cena').slider({
					value:6,
					min: 10,
					max: 3000,
					step: 25,
					slide: function(event, ui) {
						$("#cenna").val(ui.value); 
						calculateTotalPrice();
					}
				});
				
				
				
				 calculateTotalPrice();
});
		
$("#show-results").click( function (){ $("#wynik").fadeIn('medium'); return false; } );

// Newsletter
 
   $("#newsletter-join").delay(1500).fadeIn(900);
	
	//$("#newsletter-form .button").attr('src', ''); 
	
	$("#newsletter-join a.close").click(function() {  $("#newsletter-join").fadeOut('slow'); return false;});
		
	
}); 
