var addthis_config = {
	ui_language: "de"
}

var gmapLoading = false;

//jQuery closure
(function($) {
	//document ready
	$(document).ready(function() {
		$('#nav-top').show();
		
		$('#nav-top a').click(function(event) {
			var duration = 700;
			var targetContainer = $('#' + $(this).attr('targetid'));
			var fullHeight = targetContainer.find('aside').outerHeight(true);
			//open
			if (targetContainer.innerHeight() < fullHeight) {
				//load gmap
				if ($(this).attr('targetid') == 'top-content-map' && !gmapLoading) {
					$('#gmap').gMap({
						markers: [{address: "Neutorgasse 48, Graz, Austria", html: "<strong>Gösser Bräu Graz</strong><br />Neutorgasse 48<br />8010 Graz"}],
						address: "Neutorgasse 48, Graz, Austria",
						zoom: 16,
						controls: ["GScaleControl","GLargeMapControl3D"]
					});
					gmapLoading = true;
				}
				targetContainer
				.animate({height: fullHeight}, duration);
			}
			//close
			else {
				targetContainer
				.animate({height: 0}, duration);
			}
			event.preventDefault();
		});
		
		$('#gmap-content').gMap({
			markers: [{address: "Neutorgasse 48, Graz, Austria", html: "<strong>Gösser Bräu Graz</strong><br />Neutorgasse 48<br />8010 Graz"}],
			address: "Neutorgasse 48, Graz, Austria",
			zoom: 16,
			controls: ["GScaleControl","GLargeMapControl3D"]
		});
		
		$('#rundgang-starten, .rundgang-starten').click(function(e) {
			$('#rundgang').lightbox_me({
				
			});
			e.preventDefault();
		});
		
		$('.lightbox .close').click(function() {
			$('#rundgang').trigger('close');
		});
		
		if ($.fn.rssfeed) $('#sidebar-fb-feed').rssfeed(posGbFbPageId, {
			limit: 2,
			pageUrl: posGbFbPageUrl,
			pageName: 'Gösser Bräu Graz'
		});
		
		$('.teamliste a.expand').click(function(e) {
			$('.teamliste article').animate({width: 112, height: 158}); //close all
			var article = $(this).closest('article'); //get clicked article
			var newWidth = 112;
			if (article.width() < 425) newWidth = 425;
			article.animate({width: newWidth});
			//var newHeight = article.find('p').height() / 2;
			var newHeight = article.find('p').height() / 2;
			if (newHeight < 158) newHeight = 158; 
			//if (newWidth == 425) article.animate({height: newHeight});
			article.animate({height: newHeight});
			e.preventDefault();
		});
		
		$(window).load(function() {
			$('#slider').nivoSlider({
				effect:'fade',
				controlNav: true,
				directionNav: false,
				directionNavHide: false,
				prevText: '',
				nextText: '',
				captionOpacity: 1,
				pauseTime: 4000
			});
		});
		
		//feedback smileys
		$('.contact-form .freundlichkeit, .contact-form .wohlgefuehl, .contact-form .speiseangebot').each(function(){
			var wrapper = this;
			var select = $(wrapper).find('select');
			var hidden = $('<input type="hidden" name="' + $(select).attr('name') + '" value="" />').appendTo(wrapper);
			$(this).find('option').each(function() {
				var optionValue = $(this).val();
				if ($(this).val() != '---') {
					$('<p class="smiley smiley-' + $(this).val().replace(' ','-') + '" title="' + $(this).val() + '"><span></span></p>')
					.click(function(){
						$(hidden).val(optionValue);
						$(this).addClass('selected');
						$(this).siblings().removeClass('selected');
					})
					.appendTo(wrapper);
				}
			});
			$(select).remove();
		});
	});
})(jQuery);
