﻿$(document).ready(function () {
	//create gallery
	createGallery('#PageBottomGallery', '#PageBottomGalleryCanvas', 'li', 180);

	//watermark the search box
	function check() {
		var value = $(this).val();
		if (value == 'Suche') {
			$(this).val('');
		} else if (value == '') {
			$(this).val('Suche');
		}

	};

	$('#ctl00_tbSuche')
		.focus(check)
		.blur(check);

});

function Blind(expandElementId, minValue, maxValue, flowVertical, shrinkElementId) {
	var targetValue;

	if (typeof (flowVertical) == 'undefined')
		flowVertical = true;

	var expandElement = document.getElementById(expandElementId);

	if (flowVertical) {
		if (expandElement.offsetHeight < maxValue)
			targetValue = maxValue;
		else
			targetValue = minValue;
	}
	else {
		if (expandElement.offsetWidth < maxValue)
			targetValue = maxValue;
		else
			targetValue = minValue;
	}

	AdjustSize(expandElementId, targetValue, flowVertical, shrinkElementId)
}

function AdjustSize(expandElementId, targetValue, flowVertical, shrinkElementId) {
	if (typeof (flowVertical) == undefined)
		flowVertical = true;

	var expandElement = document.getElementById(expandElementId);
	var shrinkElement;
	if (typeof (shrinkElementId) != undefined)
		shrinkElement = document.getElementById(shrinkElementId);

	var doExpand = false;
	if (flowVertical)
		doExpand = expandElement.offsetHeight < targetValue;
	else
		doExpand = expandElement.offsetWidth < targetValue;

	var step = -2;
	if (doExpand)
		step = 2;

	if (flowVertical) {
		expandElement.style.height = (expandElement.offsetHeight + step) + 'px';
		expandElement.style.display = '';

		if (shrinkElement) {
			shrinkElement.style.height = (shrinkElement.offsetHeight + (step * -1)) + 'px';
			if (shrinkElement.style.height == '0px')
				shrinkElement.style.display = 'none';
		}

		if ((doExpand && expandElement.offsetHeight < targetValue) || (!doExpand && expandElement.offsetHeight > targetValue))
			window.setTimeout("AdjustSize('" + expandElementId + "', " + targetValue + ", " + flowVertical + ", '" + shrinkElementId + "')", 1);
	}
	else {
		expandElement.style.width = (expandElement.offsetWidth + step) + 'px';
		expandElement.style.display = '';

		if (shrinkElement) {
			shrinkElement.style.width = (shrinkElement.offsetWidth + (step * -1)) + 'px';
			if (shrinkElement.style.width == '0px')
				shrinkElement.style.display = 'none';
		}

		if ((doExpand && expandElement.offsetHeight < targetValue) || (!doExpand && expandElement.offsetHeight > targetValue))
			window.setTimeout("AdjustSize('" + expandElementId + "', " + targetValue + ", " + flowVertical + ", '" + shrinkElementId + "')", 1);
	}
}

//round Border
function createRoundBorder(p, i, s) {
	var parent = $(p);
	var items = $(p).find(i);
	if (parent && items && items.length > 0) {
		if ($.browser.msie) {
			/*for (var i = items.length; i > 0; i--) {
			items[i].parent().html('<div class="roundBorderLeft"><div><div><div>' + items[i].parent().html() + '</div></div></div></div>');
			}*/
			items.each(function (key, value) {
				$(value).html('<div class="roundBorderLeft"><div><div><div>' + $(value).html() + '</div></div></div></div>');
			});
		} else {
			if (s == 'small') {
				items.children('a').addClass('roundSmallBorderCss');
			} else {
				items.addClass('roundBorderCss');
			}
		}
	}
}
//gallery
function createGallery(p, c, i, w) {
	var parent = $(p);
	var items = $(p).find(i);
	if (parent && items && items.length > 0 && w > 0) {
		galleryItemWidth = w;
		var count = (items.length - 4);

		// set hover handler for images
		items.hover(overItem, outItem);

		if (count <= 0) {
			galleryMaxOffset = 0;
		} else {
			galleryMaxOffset = ((galleryItemWidth * (count))) * (-1);
		}
		parent.css({
			'overflow': 'visible',
			'width': galleryItemWidth * 4
		});
		$(c).css({
			'width': galleryItemWidth * 4,
			'overflow': 'hidden',
			'position': 'relative'
		});
		galleryItem = parent.find('ul');
		galleryItem.css({
			'position': 'relative',
			'left': '0'
		});
		if (count != 0) {
			parent.append('<a id="' + parent.attr('id') + 'Next" class="ButtonNext">&nbsp;</a><a id="' + parent.attr('id') + 'Prev" class="ButtonPrevious">&nbsp;</a>');

			$(p + 'Next').click(function () { goToGallery(galleryItemWidth * (-1) * 4, p); });
			$(p + 'Prev').click(function () { goToGallery(galleryItemWidth * 4, p); });

			$(p + 'Prev').css('opacity', 0.3);
		}
	}
}
var galleryItem = null;
var galleryMaxOffset = 0;
var galleryItemWidth = 0;
function goToGallery(i, p) {
	var offsetInt = parseInt(galleryItem.css('left'));
	offsetInt = offsetInt + i;

	$(p + 'Next').css('opacity', 1);
	$(p + 'Prev').css('opacity', 1);

	if (offsetInt <= galleryMaxOffset) {
		offsetInt = galleryMaxOffset;
		$(p + 'Next').css('opacity', 0.2);
	}
	if (offsetInt >= 0) {
		offsetInt = 0;
		$(p + 'Prev').css('opacity', 0.2);
	}
	$(galleryItem).animate({
		left: offsetInt
	}, 500, function () {
		//console.log(parseInt(galleryItem.css('left')));
	});
}

function overItem() {
	// get the spn with the description
	var text = $(this).find('span:first');

	// only show the element when it is not active
	if (!$(this).find('a:first').hasClass('active')) {
		// check if there is an element available
		if (text) {
			// check if the element is visible
			if (text.css('display') === 'none') {
				// set the element as visible, but set the opacity to 0, to start the aniamtion correct
				text.css({
					display: 'block',
					opacity: 0
				});
			}

			// show the element, soft and smooth
			text.stop().animate({
				opacity: 1
			}, 500);

		}
	}
}

function outItem() {
	// get the spn with the description
	var text = $(this).find('span:first');

	// check if there is an element available
	
		if (text) {
			// hide the element, soft and smooth
			text.stop().animate({
				opacity: 0
			}, 500);
		}
	
}

