function initialScroll() {
	$('#content .intro').jScrollPane({scrollbarWidth:9});
}

$(document).ready(function() {

	// get all animations
	$(".showElement embed").each(function() {
		$(this).parent().data("flash", $(this).parent().html());
		$(this).remove();
	});

	// show element
	$(".showButton span").toggle(
		function () {
			var pos = $(this).position();
			var caption = $(this).text();
			// put flash element
			$(this).parent().next().html($(this).parent().next().data("flash"));

			$(this).text(caption.replace(/Pokaż/, "Ukryj"))
				.parent().css("background-position","0 -18px")
				.next().slideToggle(500)
				.parent().animate({ top:-pos.top+'px' }, 500);
			setTimeout("initialScroll()",501);
		},
		function () {
			var caption = $(this).text();
			$(this).text(caption.replace(/Ukryj/, "Pokaż"))
				.parent().css("background-position","0 0")
				.next().slideToggle(500, function() {
					$(this).find("embed").remove();
			});
			setTimeout("initialScroll()",501);
		}
	);

	// scroll
	if ( $('#content .steps .image img').length != 0  ) {
// 		alert('0');
		if( $('#content .steps .image img').height() > 260 ) {
// 			alert('h1');
			$('#content .intro').jScrollPane({scrollbarWidth:9, maintainPosition:false});
		} else {
// 			alert('h0');
			$('#content .steps .image img').load(function(){
// 				alert('L');
				$('#content .intro').jScrollPane({scrollbarWidth:9, maintainPosition:false});
			})
		}
	} else {
		$('#content .intro').jScrollPane({scrollbarWidth:9, maintainPosition:false});
	}

	showFullImage($("#productDetails .image img"));
	showFullImage($(".showElement img"));

	// change image in productDetails
	function changeImg(img) {
		$('#productDetails .image .img:eq('+ img +')').fadeIn().siblings().hide();
		$('#productDetails .navi .link:eq('+ img +')').addClass('active').siblings().removeClass('active');
	}
	$("#productDetails .navi .link").click(function(){
		changeImg( ($(this).text()-1) );
	});
	$("#productDetails .navi .prev").click(function(){
		var img = $('#productDetails .navi .active').text()-2;
		changeImg( (img<0?0:img) );
	});
	$("#productDetails .navi .next").click(function(){
		var imgs = $('#productDetails .navi .link').length;
		var img = $('#productDetails .navi .active').text();
		changeImg( (img>=imgs?imgs-1:img) );
	});
	if( $('#productDetails').length !=0 ) changeImg(0);

});

