// for testing: color switcher
/*
jQuery(function($) {
	$('body').prepend('<div id="bgswitch" title="Entwicklung: Klicken zum Farbe wechseln" '
			+ ' style="position:absolute; z-index:200; top: 5px; right: 5px; width: 20px; height: 10px; background:#accc00;'
			+ 'background-image: -moz-linear-gradient(left, #fff 0, #fff 50%, #000 50%, #000 100%);'
			+ 'background-image: -webkit-linear-gradient(left, #fff 0, #fff 50%, #000 50%, #000 100%);'
			+ '"></div>');
	
	$('#bgswitch').click(function() {
		if ($('body').toggleClass('black'));
	});
});
*/

// additional info elements / teaserbox opener

jQuery(function($) {
	$('.additional').hide();
	$('.toggle_additional').show();
	$('.toggle_additional').addClass('show');
	
	$('.toggle_additional').click(function() {
		var additional = $(this).nextElementInDom('.additional');
		var but = $(this);
		if (additional.is(":visible")) {
			but.addClass('show');
		} else {
			but.removeClass('show');
		}
		additional.toggle('normal', function() {
			/*
			if (additional.is(":visible")) {
				but.removeClass('show');
			} else {
				but.addClass('show');
			}
			*/
		});
	});

	$('.click_additional').click(function() {
		var click_additional = $(this).nextElementInDom('.toggle_additional');
		if (click_additional) {
			click_additional.click();
		}
	});
	
	// close Partnerbox
	$('#detailsbox').mouseleave(function() {
		// $(this).fadeOut();
	});

	$('#detailsbox .close').click(function() {
		$('#detailsbox').fadeOut();
	});
});

// detailsbox with data element

(function($){
	$('*[data-showbox]').each(function() {
		// Pointer Mauszeiger
		$(this).addClass('link');
		// wenn unsichtbar erstmal einblenden (z.B. more-hinweis)
		if (! $(this).is(":visible")) { 
			$(this).show();
		}
	});
	
	$('*[data-showbox]').click(function() {
		// alert($(this).data('showbox'));
		
		// Inhalt austauschen
		jQuery('#detailsbox .details').html(jQuery('#' + $(this).data('showbox')).html());

		if (!jQuery('#detailsbox').is(":visible")) { 
			jQuery('#detailsbox').fadeIn();
		}
		
		// Höhe des Maincontents so anpassen, dass die Partnerbox nicht ausläuft
		jQuery('#maincontent').css('min-height', jQuery('#detailsbox .details').offset().top - jQuery('#maincontent').offset().top + jQuery('#detailsbox .details').outerHeight() + 80);
		// IE6 fix
		if (typeof document.body.style.maxHeight === "undefined") {
			// jQuery('#maincontent').css('height', 'auto');
			if (parseInt(jQuery('#maincontent').css('height')) < jQuery('#detailsbox .details').offset().top - jQuery('#maincontent').offset().top + parseInt(jQuery('#detailsbox .details').outerHeight()) + 80) {
				jQuery('#maincontent').css('height', jQuery('#detailsbox .details').offset().top - jQuery('#maincontent').offset().top + parseInt(jQuery('#detailsbox .details').outerHeight()) + 80);
			}
		}
		
		// hinscrollen
		jQuery.scrollTo('#detailsbox', 300, {offset: {top:-40}});
	});
})(jQuery);

// extend jQuery for nextElementDom method. used in teaserbox opener (above)

(function($){
	$.fn.nextElementInDom = function(selector, options) {
	var defaults = { stopAt : 'body' };
		options = $.extend(defaults, options);
		
		var parent = $(this).parent();
		var found = parent.find(selector);

		switch (true){
			case (found.length > 0):
				return found;
			case (parent.length === 0 || parent.is(options.stopAt)):
				return $([]);
			default:
				return parent.nextElementInDom(selector);
		}
	};
})(jQuery);


// soft scrolling to #

(function($) {
	$.localScroll.hash({
		//target: '#content', // Could be a selector or a jQuery object too.
		queue: true,
		duration: 1400
	});
	$.localScroll({
		//target: '#content', // could be a selector or a jQuery object too.
		queue: true,
		duration: 1100,
		hash: true,
		onBefore: function( e, anchor, $target ){
			// The 'this' is the settings object, can be modified
		},
		onAfter: function( anchor, settings ){
			// The 'this' contains the scrolled element (#content)
		}
	});
})(jQuery);

