/**
 * Optiker Hoefer JS Copyright 2011 Optiker Hoefer GmbH
 * http://www.optiker-hoefer.at
 */
function setupPopup(themePath) {
	$('#headerStoresImage').CreateBubblePopup( {
		themePath : themePath,
		themeName : 'azure',
		position : 'bottom',
		align : 'right',
		tail : {
			align : 'center',
			hidden : false
		},
		selectable : true,
		closingDelay : 200,
		innerHtml : $('#storesTooltip').html()
	});
}

function setupContactOverlay() {
	$('a[rel="#contactOverlay"]').overlay( {
		mask : {
			color : '#fafafa'
		},
		effect : 'apple',
		onBeforeLoad : function() {
			var wrapper = this.getOverlay().find("div.contentWrap");
			if (wrapper.is(":empty")) {
				wrapper.load(this.getTrigger().attr("href"));
			}
		}
	});
}

function newsEntriesReadMore() {
	$('div.newsEntryReadMore').css('display', 'block');
	$('div.newsEntryTextAdditional').hide();
	$('div.newsEntryReadMore').click(
			function(event) {
				$(event.target).parents('div.newsEntryText').next(
						'div.newsEntryTextAdditional').toggle('blind', 800,
						function() {
							if ($(this).is(':visible')) {
								$(event.target).text('Zuklappen');
							} else {
								$(event.target).text('Mehr lesen');
							}
						});
			});
}

function carousel() {
	$("#carousel").featureCarousel( {
		largeFeatureWidth: 450,
		largeFeatureHeight: 230,
		smallFeatureWidth: 225,
		smallFeatureHeight: 115,
		counterBlipText : '',
		leavingCenter : function($feature) {
			$("#showcaseTextTitle").fadeTo("fast", 0);
			$("#showcaseTextSubTitle").fadeTo("fast", 0);
		},
		movedToCenter : function(feature) {
			$('div.carousel-feature').css('cursor', 'pointer');
			feature.css('cursor', 'default');
			
			var caption = feature.find(".carousel-caption").text();
			var subCaption = feature.find(".carousel-sub-caption").text();

			$("#showcaseTextTitle").html(caption);
			$("#showcaseTextTitle").fadeTo("slow", 1);
			$("#showcaseTextSubTitle").html(subCaption);
			$("#showcaseTextSubTitle").fadeTo("slow", 1);
		}
	});
}

function subNavHover() {
	$('div.subNavEntry').hover(function() {
		$('div.subNavEntryActive').addClass('subNavEntryWasActive');
		$('div.subNavEntryActive').removeClass('subNavEntryActive');
	}, function() {
		$('div.subNavEntryWasActive').addClass('subNavEntryActive');
		$('div.subNavEntryWasActive').removeClass('subNavEntryWasActive');
	});
}

function ihreBrilleSlideshowChanged(moodular) {
	$('span#ihreBrilleCurrentCaption').html(
			$('span#ihreBrilleCaption_' + moodular.current).html());
	$('span#ihreBrilleCounter').html(
			(moodular.current + 1) + ' / '
					+ $('span[id^="ihreBrilleCaption"]').length);
	$('span#ihreBrilleCurrentCaption').fadeTo('fast', 1);
	$('#ihreBrilleCounterContainer').fadeTo('fast', 1);
}

function ihreBrille() {
	var moodular = $('.ihreBrilleSlideshow ul').moodular( {
		callbacks : [ ihreBrilleSlideshowChanged ],
		controls : 'stopOver',
		speed : 1500,
		api : true,
		// the auto parameter does not work correctly,
		// so we set the delay to a very large number
		auto : true,
		dispTimeout : 900719925474099
	});

	$('#nextLink').click(function() {
		$('#ihreBrilleCounterContainer').fadeTo('fast', 0);
		$('span#ihreBrilleCurrentCaption').fadeTo('fast', 0);

		moodular.next();
		return false;
	});

	$('#previousLink').click(function() {
		// jumping from first to last picture with prev() results
		// in incorrect moodular.current
		if (moodular.current > 0) {
			$('#ihreBrilleCounterContainer').fadeTo('fast', 0);
			$('span#ihreBrilleCurrentCaption').fadeTo('fast', 0);

			moodular.prev();
		}
		return false;
	});

	$('span#ihreBrilleCounter').html(
			'1 / ' + $('span[id^="ihreBrilleCaption"]').length);
}

function disableAjaxCaching() {
	$.ajaxSetup( {
		cache : false
	});
}
