$(document).ready(function(){
var _opacity = 0
$('.produktTresc').stop().animate({opacity: _opacity}, 0);


	$(".produktTrescBelka").click(function() {
		//$('.produktTresc').toggle();
		if(_opacity == 0){
			_opacity = 1
			$('.produktTresc').show().stop().animate({opacity: 1}, 200);

		} else {
			$('.produktTresc').stop().animate({opacity: 0}, 200).hide();
			_opacity = 0
		}

	})
	var dir = "";
	var counts = 0
	$("#arrUp").click(function(){
		//counts = $(".produktMiniLeft").length

		if(counts>0){
			counts--
			$(".pionMove").animate({top: -counts*96}, 200);
			//$(".pionMove").animate({ width: "10px", top:100, opacity:.0}, 1000)
		}
//alert("X");
		//dir="up";
		//movePionMove()
		//t = setTimeout(movePionMove(),100);
		//t=self.setInterval(movePionMove(),300);
		//$(this).everyTime(500, 'controlled', movePionMove());
	})

	$("#arrDown").click(function(){

		//dir="down";

		if(counts<$(".produktMiniLeft").length-3){
			counts++
			$(".pionMove").animate({top: -counts*96}, 200);
			//$(".pionMove").animate({opacity: 0}, 200);
			//alert(counts+" "+$(".produktMiniLeft").length)
		}
		//movePionMove()
		//$(this).everyTime(500, 'controlled', movePionMove());
		//if($(".pionMove").height()>$(".prodMiniMaska").height()){
		//	var r = $(".pionMove").height()-$(".prodMiniMaska").height()
			//alert(r)
		//}
	})

	function movePionMove(){
	alert($(".produktMiniLeft").length)
		var offsetPion = $(".pionMove").offset();
		var offsetMaska = $(".prodMiniMaska").offset();
		//alert(offsetPion.top+" "+offsetMaska.top)

		if(dir == "up" && offsetPion.top<offsetMaska.top){
			$(".pionMove").offset({ top: offsetPion.top+4});
		} else if(dir == "down"){
			$(".pionMove").offset({ top: offsetPion.top-4});
		}
	}

});


function swapImage(ktory, destImage){
	//
	document.getElementById(ktory).style.visibility = "hidden";

	imageObj = new Image();

	imageObj.onload = function() {
		document.getElementById(ktory).src=destImage
		document.getElementById(ktory).style.visibility = "visible";
	}
	imageObj.src = destImage

}
