$('#header-menu-outer').remove();
var thumb = new Array();
function next(uid) {
	if (typeof(thumb[uid]) == "undefined") {
		thumb[uid] = 0;
	}
	var step = 180;
	var width  = parseInt($('#gallerySlider' + uid).width());
	var margin = parseInt($('#gallerySlider' + uid).css('margin-left').replace(/px/, ''));
	var position = thumb[uid];
	var thumbs = width / step - 1;
	if (thumbs == 0) {
		return;
	}
	if (position == 0 || position == thumbs - 1) {
		$('#thumb' + uid + "_" + position).removeClass('galleryThumbActive');
		position++;
		$('#thumb' + uid + "_" + position).addClass('galleryThumbActive');
	}
	else if (position == thumbs) {
		return;
	}
	else {
		$('#thumb' + uid + "_" + position).removeClass('galleryThumbActive');
		position++;
		$('#thumb' + uid + "_" + position).addClass('galleryThumbActive');
		margin -= step;
		$('#gallerySlider' + uid).animate({
			marginLeft: margin + "px"
		}, 500);
	}
	position = position > thumbs ? thumbs : position;
	position = position < 0 ? 0 : position;
	
	thumb[uid] = position;


	
	var currentHeight = $('#detailImgWrapper' + uid).height();
	$('#detailImgWrapper' + uid).css("height", currentHeight + "px");
	$('#detailImgWrapper' + uid).css("overflow", "hidden");
	var src = $('#thumbnail' + uid + "_" + position).attr('src');
		src = src.replace(/t_/, 'l_');
		$('#detailImg' + uid).attr('src', src);
 		document.getElementById('galleryDetail' + uid).scrollIntoView(true);
}
function prv(uid) {
	if (typeof(thumb[uid]) == "undefined") {
		thumb[uid] = 0;
	}
	var step = 180;
	var width  = parseInt($('#gallerySlider' + uid).width());
	var margin = parseInt($('#gallerySlider' + uid).css('margin-left').replace(/px/, ''));
	var position = thumb[uid];
	var thumbs = width / step - 1;
	if (thumbs == 0) {
		return;
	}
	if (position == 1 || position == thumbs) {
		$('#thumb' + uid + "_" + position).removeClass('galleryThumbActive');
		position--;
		$('#thumb' + uid + "_" + position).addClass('galleryThumbActive');
	}
	else if (position == 0) {
		return;
	}
	else {
		$('#thumb' + uid + "_" + position).removeClass('galleryThumbActive');
		position--;
		$('#thumb' + uid + "_" + position).addClass('galleryThumbActive');
		margin += step;
		$('#gallerySlider' + uid).animate({
			marginLeft: margin + "px"
		}, 500);
	}
	position = position > thumbs ? thumbs : position;
	position = position < 0 ? 0 : position;
	
	thumb[uid] = position;
	
	var currentHeight = $('#detailImgWrapper' + uid).height();
	$('#detailImgWrapper' + uid).css("height", currentHeight + "px");
	$('#detailImgWrapper' + uid).css("overflow", "hidden");
	var src = $('#thumbnail' + uid + "_" + position).attr('src');
		src = src.replace(/t_/, 'l_');
		$('#detailImg' + uid).attr('src', src);
		document.getElementById('galleryDetail' + uid).scrollIntoView(true);
}
function show(i, uid) {
	if (typeof(thumb[uid]) == "undefined") {
		thumb[uid] = 0;
	}
	var step = 180;
	var width  = parseInt($('#gallerySlider' + uid).width());
	var margin = parseInt($('#gallerySlider' + uid).css('margin-left').replace(/px/, ''));
	var position = thumb[uid];
	var thumbs = width / step - 1;
	
	if (i == position) {
		return;
	}
	else if (i == position - 1) {
		prv(uid);
	}
	else if (i == position - 2) {
		prv(uid);
		prv(uid);
	}
	else if (i == position + 1) {
		next(uid);
	}
	else if (i == position + 2) {
		next(uid);
		next(uid);
	}
}

function showBig(uid) {
	var url = $('#detailImg' + uid).attr('src').replace(/l_/, "z_");
	var description = "";
	var options = "";
	jQuery.slimbox(url, description, options);
	if($.inArray(uid, checkGalleryHeightUids) == -1) {
		checkGalleryHeightUids[checkGalleryHeightUids.length] = uid;
	}
}


var checkGalleryHeightInterval = 1000;
var checkGalleryHeightUids = new Array();
function checkGalleryHeight() {
	for (i = 0; i < checkGalleryHeightUids.length; i++) {
		var wrapperHeight = $('#detailImgWrapper' + checkGalleryHeightUids[i]).height();
		var imgHeight = $('#detailImgContainer' + checkGalleryHeightUids[i]).height();
		if (imgHeight != wrapperHeight) {
			$('#detailImgWrapper' + checkGalleryHeightUids[i]).animate({
				height: imgHeight + "px"
			}, 300);
		}
	}
	window.setTimeout(checkGalleryHeight, checkGalleryHeightInterval);
}
checkGalleryHeight();