//funkcje i parametry dla scrolla w menu
	ktore=0;
	scrolltime=30;
	scrollskok=3;
	function stopscroll() {
		if (window.scrollint) clearInterval(scrollint);
	}
	function scrollit(direction,idek)
	{
		aktywne=$("#"+idek);
		aktywne.scrollTop(aktywne.scrollTop()+direction*scrollskok);
//		if (aktywne.scrollTop()==0)
//			aktywne.children('.scrollup:visible').hide();
//		else
		aktywne.children('.scrollup:hidden').show();
//		if (aktywne.scrollTop()>=aktywne.attr('scrollHeight')-aktywne.height())
//			aktywne.children('.scrolldown:visible').hide();
//		else
		aktywne.children('.scrolldown:hidden').show();
		return false;
	}
	function pokazSkrol(ktoremenu)
	{
		if (ktoremenu.attr('scrollHeight')>ktoremenu.height()) {
			ktoremenu.children('.scrolldown').css('left',ktoremenu.offset().left+ktoremenu.width()+4).css('top',ktoremenu.offset().top+231);
			ktoremenu.children('.scrollup').css('left',ktoremenu.offset().left+ktoremenu.width()+4).css('top',ktoremenu.offset().top);
			ktoremenu.children('.scrolldown').show();
//			if (ktoremenu.scrollTop()==0)
//				ktoremenu.children('.scrollup:visible').hide();
//			else
				ktoremenu.children('.scrollup:hidden').show();
//			if (ktoremenu.scrollTop()>=ktoremenu.attr('scrollHeight')-ktoremenu.height())
//				ktoremenu.children('.scrolldown:visible').hide();
//			else
				ktoremenu.children('.scrolldown:hidden').show();
		}
	}
	
	function przeliczMenusy()
	{
		$('.menu-poz3:visible, .menu-poz2:visible').each(function() {
			if ($(this).attr('scrollHeight')>$(this).height()) {
				$(this).children('.scrolldown').css('left',$(this).offset().left+$(this).width()+4).css('top',$(this).offset().top+231);
				$(this).children('.scrollup').css('left',$(this).offset().left+$(this).width()+4).css('top',$(this).offset().top);
				$(this).children('.scrollup').show();
				$(this).children('.scrolldown').show();
				tmp=$(this).children('.selected').offset();
				tmp2=$(this).offset();
				if((tmp.top-tmp2.top)>=$(this).height()) {
					$(this).scrollTop(tmp.top-tmp2.top-$(this).height()+20);					
//				if ($(this).scrollTop()==0)
//					$(this).children('.scrollup:visible').hide();
//				else
					$(this).children('.scrollup:hidden').show();
//				if ($(this).scrollTop()>=$(this).attr('scrollHeight')-$(this).height())
//					$(this).children('.scrolldown:visible').hide();
//				else
					$(this).children('.scrolldown:hidden').show();
				}
				document.cookie = "scrollpoz="+($(this).scrollTop())+"; path=/";			
			}
		});
	}
	
	$(document).ready(function(){

	//pokazywanie poziomow menu
		
		$('.menu-poz a').click(function() {
		//$('.menu-poz a, .menu-poz2 a').click(function() {
			ktore=$(this).attr('id');
			if (!ktore) return true;
			if ($(this).parent().attr('class')=='menu-poz') {
				schowaj='.menu-poz3:visible, .menu-poz2:visible';
				$('.menu-poz3:visible img,.menu-poz3:visible img').hide();
				$('.menu-poz3 a, .menu-poz2 a, .menu-poz a').removeClass('selected');
			}
			else {
				schowaj='.menu-poz3:visible';
				$('.menu-poz3:visible img').hide();
				$('.menu-poz3 a, .menu-poz2 a').removeClass('selected');
			}
			if ($(schowaj).length) {
				$(schowaj).fadeOut('fast',function(){
					$('#'+ktore+'-sub').fadeIn('fast',function(){pokazSkrol($('#'+ktore+'-sub'))});
				}) 
			}
			else {
				$('#'+ktore+'-sub').fadeIn('fast',function(){pokazSkrol($('#'+ktore+'-sub'))});			
			}
//			$('.menu-poz3:visible, .menu-poz2:visible').each(function(){
//				if ($(this).attr('scrollHeight')>$(this).height()) {
//					$(this).children('.scrolldown').css('left',$(this).offset().left+2).css('top',$(this).offset().top+225);
//					$(this).children('.scrollup').css('left',$(this).offset().left+2).css('top',$(this).offset().top);
//					//$(this).children('.scrolldown').show();
//					if ($(this).scrollTop()==0)
//						$(this).children('.scrollup:visible').hide();
//					else
//						$(this).children('.scrollup:hidden').show();
//					if ($(this).scrollTop()>=$(this).attr('scrollHeight')-$(this).height())
//						$(this).children('.scrolldown:visible').hide();
//					else
//						$(this).children('.scrolldown:hidden').show();
//				}
//			});
			$(this).attr('class','selected');
			return false;
		})
		
	//podmiana fotki
		newfotosrc='';
		bigfotosrc='';
		$('.prod_fotki a').click(function() {
			$('.prod_fotki .prod_imgbox_sel').addClass('prod_imgbox').removeClass('prod_imgbox_sel');
			$(this).addClass('prod_imgbox_sel').removeClass('prod_imgbox');
			newfotosrc=eval($(this).attr('id')+'_img.src');
			bigfotosrc=eval($(this).attr('id')+'_img_big.src');
			$('#imgprod').fadeOut('slow',function(){$('#imgprod').attr('src',newfotosrc).fadeIn('slow',function() {przeliczMenusy()});})			
			$('.prod-desc').html(eval($(this).attr('id')+'_desc'));
			if(($('#fotozoom').hasClass('fotozoom'))) {
				$('#fotozoomimg').fadeOut('slow',function(){$('#fotozoom').removeClass('fotozoom').addClass('fotozoom2').html('')});			
			}
			return false;
		});
		
	//podmiana listy fotek i pokazanej fotki po wybraniu pokrycia
		$('#prod_finishes a').click(function() {
			$('#prod_finishes a').removeClass('selected2');
			$(this).addClass('selected2');
			$('.prod_fotki').hide();
			$("#fotki-"+($(this).attr('id'))).show();
			nowafotka=$(("#fotki-"+($(this).attr('id'))+' a:last-child'));
			if (nowafotka) {
				$('.prod_fotki .prod_imgbox_sel').addClass('prod_imgbox').removeClass('prod_imgbox_sel');
				nowafotka.addClass('prod_imgbox_sel').removeClass('prod_imgbox');
				$('#imgprod').attr('src',eval(nowafotka.attr('id')+'_img.src'));
			}
			return false;
		});
		
	//pokazanie wyboru available finishes
		myoffset=$('#prod_name').offset();
		if (myoffset)
			$('#prod_finishes').css('position','absolute').css('left',myoffset.left-150).css('top',myoffset.top+270);
			
	//link dane techniczne
		$('#danetech').click(function(){
			$('.prod_fotki .prod_imgbox_sel').addClass('prod_imgbox').removeClass('prod_imgbox_sel');
			$('#imgprod').attr('src',eval($(this).attr('id')+'_img.src')).fadeIn('slow');
			return false;
		})
		
	//duzy obrazek 
		$('#imgprod').click(function(event){
			event.stopPropagation();
			$('#fotozoom').html("<img src='' id='fotozoomimg' /><br/><div>click on image to close window</div>");
			$('#fotozoomimg').attr('src',bigfotosrc);
			//$('#fotozoom').width($('#fotozoomimg').width());
			$('#fotozoom').removeClass('fotozoom2').addClass('fotozoom');
			//mleft=($(window).width()-$('#fotozoom').width())/2;
			
			//mleft=($(window).width()-950)/2+950-$('#fotozoomimg').width();
			//alert($('#fotozoomimg').width()+' '+mleft);
			//$('#fotozoom').width($('#fotozoomimg').width()+8);
			mleft=($(window).width()-950)/2+$('.menu-poz').width()+10;
			$('#fotozoom').width($('#fotozoomimg').width()+8);
			if (mleft>0)
				$('#fotozoom').css('left',mleft+'px');
			$('#fotozoomimg').fadeIn('slow',function() {przeliczMenusy()});
			return false;			
		});
		$('#fotozoom').click(function(event){
			event.stopPropagation();
			$('#fotozoomimg').attr('src',bigfotosrc).fadeOut('slow',function(){$('#fotozoom').removeClass('fotozoom').addClass('fotozoom2').html('')});			
		});
		$('#linkdownload').click(function(){
			re=/\d{1,}$/;
			$(this).attr('href','index.php?pg=download'+'&foto='+$('.prod_imgbox_sel').attr('id').match(re));
		});
		
	//scroll w menu
		przeliczMenusy();
	
		$('.scrolldown').mouseover(function(){
			if (window.scrollint) clearInterval(scrollint);
			scrollit(1,$(this).parent().eq(0).attr('id'));
			scrollint=setInterval("scrollit(1,'"+$(this).parent().eq(0).attr('id')+"')",scrolltime);
		})
		
		$('.scrolldown').mouseout(function(){
			stopscroll();
			document.cookie = "scrollpoz="+($(this).parent().eq(0).scrollTop())+"; path=/";			
		})
		
		$('.scrollup').mouseover(function(){
			if (window.scrollint) clearInterval(scrollint);
			scrollit(-1,$(this).parent().eq(0).attr('id'));
			scrollint=setInterval("scrollit(-1,'"+$(this).parent().eq(0).attr('id')+"')",scrolltime);
		})
		
		$('.scrollup').mouseout(function(){
			stopscroll();
			document.cookie = "scrollpoz="+($(this).parent().eq(0).scrollTop())+"; path=/";			
		})
		
		finishzoomed='';
	//powiekszenia wykonczen
		$('.tech_fin img').mouseover(function(event) {
			$(this).unbind('mouseout');
			event.stopPropagation();
			if (finishzoomed==$(this).attr('id')) {
				return;
			}
			
			if (finishzoomed && finishzoomed!=$(this).attr('id'))
				hidefinish();
			offsecik=$(this).offset();
			$(this).css('position','absolute');
			$(this).css('z-index','100');
			$(this).css('left',(offsecik.left-$('#technicalinfo').offset().left-120)+'px');
			$(this).css('top',(offsecik.top-$('#technicalinfo').offset().top-120)+'px');
			$(this).attr('src',eval('b_'+$(this).attr('id')+'.src'));
			$(this).mouseout(function(event) {
				event.stopPropagation();
				$(this).css('position','relative');
				$(this).css('left',0);
				$(this).css('top',0);
				$(this).css('z-index','99');
				$(this).attr('src',eval('s_'+$(this).attr('id')+'.src'));			
				finishzoomed='';
				$(this).unbind('mouseout');
			})
			finishzoomed=$(this).attr('id');
		});
		$('#tech_close').click(function(){
			$('#technicalinfo:visible').fadeOut('fast');
		});
		$('#techdata').click(function(){
			
			$(this).css('z-index','98');
			$('#technicalinfo').css('left',($(window).width()-650)/2+'px');
			$('#technicalinfo').css('top','50px');
			$('#technicalinfo').fadeIn('fast');
			
			return false;
		});
		
	});
		function hidefinish()
		{
			$('#'+finishzoomed).css('position','relative');
			$('#'+finishzoomed).attr('src',eval('s_'+finishzoomed+'.src'));
			$('#'+finishzoomed).css('z-index','1');
			$('#'+finishzoomed).css('left',0);
			$('#'+finishzoomed).css('top',0);
			$('#'+finishzoomed).unbind('mouseout');
		}

