var numberImg = 0;

function enlargeImage(imageUrl) {
	var image = document.getElementById("sharedGalleryImage");
	var loadingLabel = document.getElementById("sharedGalleryImageLoadingLabel");

	image.src = imageUrl;
	image.style.visibility = "hidden";
	loadingLabel.style.visibility = "visible";
}

function moveImage(strona){
      var image = document.getElementById("sharedGalleryImage");
      var loadingLabel = document.getElementById("sharedGalleryImageLoadingLabel");
      var currentImg = document.getElementById(0);

        if (strona == "lewo") {
            numberImg--;

            if (numberImg <= 0) {
                numberImg = 0;
            }
        }
        else if (strona == "prawo") {
            numberImg++;
        }

        currentImg = document.getElementById(numberImg);

        //alert(currentImg.alt);

        image.src = currentImg.alt;
	image.style.visibility = "hidden";
	loadingLabel.style.visibility = "visible";

        return numberImg;
}



function onSharedGalleryImageLoad(img) {
	var panel = document.getElementById("sharedGalleryImagePanel");
	var loadingLabel = document.getElementById("sharedGalleryImageLoadingLabel");
	var top = document.getElementById("top");
	var content = document.getElementById("content");
        var galleryLeft = document.getElementById("galleryArrowLeft");
        var galleryRight = document.getElementById("galleryArrowRight");

	if (img.width < img.height) {
		panel.style.backgroundImage = "url(img/shared_gallery_image_bg2.png)";
		panel.style.width = "443px";
		panel.style.position = 'relative';
		top.style.background = "transparent url(img/shared_gallery_image_top2.png) 100% 0 no-repeat";
		content.style.background = "url(img/shared_gallery_thumbs_bot2.gif) 100% 0 no-repeat";
                galleryLeft.style.position = 'absolute';
                galleryLeft.style.top = '270px';
                galleryLeft.style.left = '5px';
                galleryLeft.style.cursor = "pointer";

                galleryRight.style.position = 'absolute';
                galleryRight.style.top = '270px';
                galleryRight.style.right = '5px';
                galleryRight.style.cursor = "pointer";

	} else {
		panel.style.backgroundImage = "url(img/shared_gallery_image_bg.png)";
		panel.style.width = "857px";
		panel.style.position = 'relative';
		top.style.background = "transparent url(img/shared_gallery_image_top.png) 100% 0 no-repeat";
		content.style.background = "url(img/shared_gallery_thumbs_bot.gif) 100% 0 no-repeat";
                galleryLeft.style.position = 'absolute';
                galleryLeft.style.top = '270px';
                galleryLeft.style.left = '5px';
                galleryLeft.style.cursor = "pointer";

                galleryRight.style.position = 'absolute';
                galleryRight.style.top = '270px';
                galleryRight.style.right = '5px';
                galleryRight.style.cursor = "pointer";
	}
	loadingLabel.style.visibility = "hidden";
	img.style.visibility = "visible";
}

function fadeInImage(img) {
	setOpacity(img, 45);
}

function fadeOutImage(img) {
	setOpacity(img, 100);
}

function setOpacity(obj, opacity) {
	if (opacity >= 100) {
		opacity = 99.999;
	}
	obj.style.filter = "alpha(opacity:"+ opacity +")";
	obj.style.KHTMLOpacity = opacity/100;
	obj.style.MozOpacity = opacity/100;
	obj.style.opacity = opacity/100;
}

var timeoutId = null;

function stopThumbnailsMoving() {
//	if (timeoutId != null) {
//		clearTimeout(timeoutId);
//		timeoutId = null;
//
//	}
}

//function moveThumbnailsLeft(continued) {
//	if (continued == null) {
//		continued = false;
//	}
//	if (!continued) {
//		if (timeoutId != null) {
//			clearTimeout(timeoutId);
//			timeoutId = null;
//		}
//	} else {
//		clearTimeout(timeoutId);
//		timeoutId = null;
//	}
//	var panel = document.getElementById("thumbnailsPanel");
//	offsetLeft(panel);
//	if (timeoutId == null) {
//		timeoutId = setTimeout(moveThumbnailsLeft, 200, true);
//	}
//}

//function moveThumbnailsRight(continued) {
//	if (continued == null) {
//		continued = false;
//	}
//	if (!continued) {
//		if (timeoutId != null) {
//			clearTimeout(timeoutId);
//			timeoutId = null;
//		}
//	} else {
//		clearTimeout(timeoutId);
//		timeoutId = null;
//	}
//	var panel = document.getElementById("thumbnailsPanel");
//	offsetRight(panel);
//	if (timeoutId == null) {
//		timeoutId = setTimeout(moveThumbnailsRight, 200, true);
//	}
//}

var thumbnailsPanelMoving = false;

function offsetLeft(panel, targetValue) {
	var v = parseInt(panel.style.marginLeft.substring(0, panel.style.marginLeft.length - 2));

	v += 10;
	if (v > targetValue) {
		v = parseInt(panel.style.marginLeft.substring(0, panel.style.marginLeft.length - 2));
		panel.style.marginLeft = v + "px";
		thumbnailsPanelMoving = false;
	} else {
		panel.style.marginLeft = v + "px";
		setTimeout(function() {offsetLeft(panel, targetValue);}, 10);
	}

}

function offsetRight(panel, targetValue) {
	var v = parseInt(panel.style.marginLeft.substring(0, panel.style.marginLeft.length - 2));

	v -= 10;
	if (v < targetValue) {
		v = parseInt(panel.style.marginLeft.substring(0, panel.style.marginLeft.length - 2));
		panel.style.marginLeft = v + "px";
		thumbnailsPanelMoving = false;
	} else {
		panel.style.marginLeft = v + "px";
		setTimeout(function() {offsetRight(panel, targetValue);}, 10);
	}
	
}

function moveThumbnailsLeft() {
	if (!thumbnailsPanelMoving) {
		thumbnailsPanelMoving = true;
		var panel = document.getElementById("thumbnailsPanel");
		var targetValue = parseInt(panel.style.marginLeft.substring(0, panel.style.marginLeft.length - 2)) + 750;
		if (targetValue <= 0) {
			offsetLeft(panel, targetValue);
		} else {
			thumbnailsPanelMoving = false;
		}
	}
}

function moveThumbnailsRight() {
	if (!thumbnailsPanelMoving) {
		thumbnailsPanelMoving = true;
		var panel = document.getElementById("thumbnailsPanel");
		var targetValue = parseInt(panel.style.marginLeft.substring(0, panel.style.marginLeft.length - 2)) - 750;
		var width = parseInt(panel.style.width.substring(0, panel.style.width.length - 2));
		//if (targetValue > width) {
			offsetRight(panel, targetValue);
		//} else {
		//	thumbnailsPanelMoving = false;
		//}
	}
}
