//Efetky
$(document).ready(function() {
	LoadEfekts();
	LoadSlider();
});



function LoadEfekts() {
	  
	//1 
	$(".ItemInfo").hover(function() {
		$(this).css("background-position", "0% 100%");		
		$(this).parent(".ItemGroupContainer").animate( {marginTop: 13}, {queue: true, duration: 400} );
	},function(){
  	$(this).css("background-position", "0% 0%");  	
    $(this).parent(".ItemGroupContainer").animate( {marginTop: 0}, {queue: true, duration: 400} );
	});  


	//2			
	BoxPopup = '<div class="PopupKontener">';
		BoxPopup += '<div class="PopupZamknij"><span class="PopupClose">zamknij</span></div>';
		BoxPopup += '<div id="PopupContent"></div>';
	BoxPopup += '</div">';	

	PageId = $(".btn_polec_strone").attr("id");
	BoxIframe = '<iframe scrolling="no" width="100%" height="235" frameborder="0" marginheight="0" marginwidth="0" id="PopupIframe" allowtransparency="true" src="framework/other/polec_strone.php?pid='+PageId+'">';
	
	if ( $(".BottomBtnContainer").length == 1 ) {
		$(".MiddleContainer").append(BoxPopup);
	}
	
	$(".PopupClose").click(function() {
		$("#PopupContent").html("");
		$(".btn_polec_strone").css("background-position", "0% 0%");
	  $(".PopupKontener").animate( {opacity: "hide" }, {queue: true, duration: 200} );
	});	
	
	$(".btn_polec_strone").click(function() {
		if ($(".PopupKontener").is(":hidden")) {
			$("#PopupContent").append(BoxIframe);
	  	$(".PopupKontener").animate( {opacity: "show" }, {queue: true, duration: 300} );
	  	$(this).css("background-position", "0% 100%");
		}			
	});	

}


function LoadSlider() {
  var currentPosition = 0;
  var slidesOfPage = 4;
  var slideWidth = 238;
  var slides = $(".ItemGroupContainer");
  var numberOfSlides = slides.length;
	
	//if ( numberOfSlides > slidesOfPage ) { }
	$(".CarouselSlider").width( numberOfSlides * slideWidth );
	$(".CarouselNavContainer").show();
  
	manageControls(currentPosition);

  $(".NavBack, .NavNext").bind("click", function() {
		currentPosition = ($(this).attr("class") == "NavNext") ? currentPosition+1 : currentPosition-1;    
    manageControls(currentPosition);
    $(".CarouselSlider").animate( {"marginLeft": slideWidth*(-currentPosition)}, {queue: true, duration: 400} );
  });

  function manageControls(position) {
		if(position == 0) { $(".NavBack").hide(); } else { $(".NavBack").show(); }
    if(position == numberOfSlides-slidesOfPage) { $(".NavNext").hide(); } else { $(".NavNext").show(); }
  }
}

