$('#shoptooltip').mouseenter(function(){
	tooltipOver = true;
});
$('#shoptooltip').mouseleave(function(){
	tooltipOver = false;
});

function initShop() {
	$('#shopcontent a,#shopBacklink a').click(function(){
		$('#shopWrapper').fadeTo('fast', .1);
		var url = $(this).attr('href')
		$.ajax({
			type: "POST",
			url: url,
			data: "ajax=1",
			success: function(html) {
				$('#shopWrapper').html(html);
				$('#shopWrapper').fadeTo('fast', 1);
				buildGallery();
				replaceSelect("sizeSelect", "siSe");
				initShop();
				return false;
			},
			error: function(e) {
				alert(e);
				window.location = url;
			}
		});
		return false;
	})
}
function buildGallery() {
	$('#shopGalLeft,#shopGalRight').click(function() {
		var w1 = $('#shopGalHolder').width();
		var w2 = $('#shopGalWrapper').width();
		var step = w1 / $('#shopGalHolder img').length;
		var iml = parseInt($('#shopGalHolder img').css('margin-left').replace(/px/g, ""));
		var imr = parseInt($('#shopGalHolder img').css('margin-right').replace(/px/g, ""));

		var margin = $('#shopGalHolder').css("margin-left");
		if (typeof(margin) == "undefined") {
			margin = 0;
		}
		else if (margin == "auto") {
			margin = 0;
		}
		else {
			margin = parseInt(margin.replace(/px/g, ""));
		}

		if ($(this).attr('id') == 'shopGalLeft') {
			margin += step;
		}
		else {
			margin -= step;
		}

		if (margin > 0) {
			margin = 0;
		}
		if (margin < w2 - w1 + iml + imr) {
			margin = w2 - w1 + iml + imr;
		}

		if ($.support.boxModel) {
			$('#shopGalHolder').animate({
				marginLeft: margin + "px"
			}, 300);
		}

		$('#shopGalHolder').css("margin-left", margin + "px");
	});
}

function moveOut(el, direction, newhtml, direction2) {
	var h = $(el).height();
	var w = $(el).width();
	$(el).prepend("<div id='moveOutWrapper'></div>");
	$(el).wrap( $('#moveOutWrapper') );
	$('#moveOutWrapper').css('height', h + 'px');
	$('#moveOutWrapper').css('width', w + 'px');
	$('#moveOutWrapper').css('overflow', 'hidden');

	switch (direction) {
		case "top":
			var mt = h * -1;
			mt = mt + "px";
			$(el).animate({
				marginTop: mt
			}, 'slow', function(){
				$(el).html(newhtml);
				$(el).css('margin-top', '0px');
				switch (direction2) {
					case "top":
						$(el).css('marginTop', "-" + h + "px");
						$(el).animate({
							marginTop: "0px"
						}, 'slow', function() {
							var html = $('#moveOutWrapper').html();
							$('#moveOutWrapper').html('').after(html).remove();
						});
					break;
					case "left":
						$(el).css('marginLeft', "-" + w + "px");
						$(el).animate({
							marginLeft: "0px"
						}, 'slow', function() {
							var html = $('#moveOutWrapper').html();
							$('#moveOutWrapper').html('').after(html).remove();
						});
					break;
					case "right":
						$(el).css('marginLeft', w + "px");
						$(el).animate({
							marginLeft: "0px"
						}, 'slow', function() {
							var html = $('#moveOutWrapper').html();
							$('#moveOutWrapper').html('').after(html).remove();
						});
					break;
					default:
					case "bottom":
						$(el).css('marginTop', h + "px");
						$(el).animate({
							marginTop: "0px"
						}, 'slow', function() {
							var html = $('#moveOutWrapper').html();
							$('#moveOutWrapper').html('').after(html).remove();
						});
					break;
				}
			});
		break;
		case "left":
			var ml = w * -1;
			ml = ml + "px";
			$(el).animate({
				marginLeft: ml
			}, 'slow', function(){
				$(el).html('');
				$(el).css('margin-left', '0px');
				switch (direction2) {
					case "top":
						$(el).css('marginTop', "-" + h + "px");
						$(el).animate({
							marginTop: "0px"
						}, 'slow', function() {
							var html = $('#moveOutWrapper').html();
							$('#moveOutWrapper').html('').after(html).remove();
						});
					break;
					case "left":
						$(el).css('marginLeft', "-" + w + "px");
						$(el).animate({
							marginLeft: "0px"
						}, 'slow', function() {
							var html = $('#moveOutWrapper').html();
							$('#moveOutWrapper').html('').after(html).remove();
						});
					break;
					case "right":
						$(el).css('marginLeft', w + "px");
						$(el).animate({
							marginLeft: "0px"
						}, 'slow', function() {
							var html = $('#moveOutWrapper').html();
							$('#moveOutWrapper').html('').after(html).remove();
						});
					break;
					default:
					case "bottom":
						$(el).css('marginTop', h + "px");
						$(el).animate({
							marginTop: "0px"
						}, 'slow', function() {
							var html = $('#moveOutWrapper').html();
							$('#moveOutWrapper').html('').after(html).remove();
						});
					break;
				}
			});
		break;
		case "right":
			var ml = w + "px";
			$(el).animate({
				marginLeft: ml
			}, 'slow', function(){
				$(el).html('');
				$(el).css('margin-left', '0px');
				switch (direction2) {
					case "top":
						$(el).css('marginTop', "-" + h + "px");
						$(el).animate({
							marginTop: "0px"
						}, 'slow', function() {
							var html = $('#moveOutWrapper').html();
							$('#moveOutWrapper').html('').after(html).remove();
						});
					break;
					case "left":
						$(el).css('marginLeft', "-" + w + "px");
						$(el).animate({
							marginLeft: "0px"
						}, 'slow', function() {
							var html = $('#moveOutWrapper').html();
							$('#moveOutWrapper').html('').after(html).remove();
						});
					break;
					case "right":
						$(el).css('marginLeft', w + "px");
						$(el).animate({
							marginLeft: "0px"
						}, 'slow', function() {
							var html = $('#moveOutWrapper').html();
							$('#moveOutWrapper').html('').after(html).remove();
						});
					break;
					default:
					case "bottom":
						$(el).css('marginTop', h + "px");
						$(el).animate({
							marginTop: "0px"
						}, 'slow', function() {
							var html = $('#moveOutWrapper').html();
							$('#moveOutWrapper').html('').after(html).remove();
						});
					break;
				}
			});
		break;
		case "bottom":
		default:
			var mt = h + "px";
			$(el).animate({
				marginTop: mt
			}, 1500, function(){
				$(el).html('');
				$(el).css('margin-top', '0px');
				switch (direction2) {
					case "top":
						$(el).css('marginTop', "-" + h + "px");
						$(el).animate({
							marginTop: "0px"
						}, 'slow', function() {
							var html = $('#moveOutWrapper').html();
							$('#moveOutWrapper').html('').after(html).remove();
						});
					break;
					case "left":
						$(el).css('marginLeft', "-" + w + "px");
						$(el).animate({
							marginLeft: "0px"
						}, 'slow', function() {
							var html = $('#moveOutWrapper').html();
							$('#moveOutWrapper').html('').after(html).remove();
						});
					break;
					case "right":
						$(el).css('marginLeft', w + "px");
						$(el).animate({
							marginLeft: "0px"
						}, 'slow', function() {
							var html = $('#moveOutWrapper').html();
							$('#moveOutWrapper').html('').after(html).remove();
						});
					break;
					default:
					case "bottom":
						$(el).css('marginTop', h + "px");
						$(el).animate({
							marginTop: "0px"
						}, 'slow', function() {
							var html = $('#moveOutWrapper').html();
							$('#moveOutWrapper').html('').after(html).remove();
						});
					break;
				}
			});
		break;
	}
}

function showZoom() {
	if ($('#detailImgLink img').length != 1) {
		return;
	}
	var zoom = "http://www.shusta.de/img/shop/zoom.gif";
	var img = $('#detailImgLink img').attr('src');
	if (img != zoom) {
		$('#detailImgLink img').attr('src', zoom);
		$('#detailImgLink').css("background-image", "url(" + img + ")");
	}
}

showZoom();

//initShop();
