function formatTitle(title, currentArray, currentIndex, currentOpts) {
    return '<div id="tip7-title"><span><a href="javascript:;" onclick="$.fancybox.close();"><img src="/data/closelabel.gif" /></a></span>' + (title && title.length ? '<b>' + title + '</b>' : '' ) + 'Image ' + (currentIndex + 1) + ' of ' + currentArray.length + '</div>';
}

//(function($) {
//
//$.fn.pulse = function( properties, duration, numTimes, interval) {  
//   
//   if (duration === undefined || duration < 0) duration = 500;
//   if (duration < 0) duration = 500;
//
//   if (numTimes === undefined) numTimes = 1;
//   if (numTimes < 0) numTimes = 0;
//
//   if (interval === undefined || interval < 0) interval = 0;
//
//   return this.each(function() {
//      var $this = jQuery(this);
//      var origProperties = {};
//      for (property in properties) {
//         origProperties[property] = $this.css(property);
//      }
//
//      var subsequentTimeout = 0;
//      for (var i = 0; i < numTimes; i++) {
//         window.setTimeout(function() {
//            $this.animate(
//               properties,
//               {
//                  duration:duration / 2,
//                  complete:function(){
//                     $this.animate(origProperties, duration / 2)}
//               }
//            );
//         }, (duration + interval)* i);
//      }
//   });
//  
//};
//})(jQuery);

(function($) {
$.fn.pulse = function( prop, speed, times, easing, callback ) {
    
    if ( isNaN(times) ) {
        callback = easing;
        easing = times;
        times = 1;
    }
    
    var optall = jQuery.speed(speed, easing, callback),
        queue = optall.queue !== false,
        largest = 0;
        
    for (var p in prop) {
        largest = Math.max(prop[p].length, largest);
    }
    
    optall.times = optall.times || times;
    
    return this[queue?'queue':'each'](function(){
        
        var counts = {},
            opt = jQuery.extend({}, optall),
            self = jQuery(this);
            
        pulse();
        
        function pulse() {
            
            var propsSingle = {},
                doAnimate = false;
            
            for (var p in prop) {
                
                // Make sure counter is setup for current prop
                counts[p] = counts[p] || {runs:0,cur:-1};
                
                // Set "cur" to reflect new position in pulse array
                if ( counts[p].cur < prop[p].length - 1 ) {
                    ++counts[p].cur;
                } else {
                    // Reset to beginning of pulse array
                    counts[p].cur = 0;
                    ++counts[p].runs;
                }
                
                if ( prop[p].length === largest ) {
                    doAnimate = opt.times > counts[p].runs;
                }
                
                propsSingle[p] = prop[p][counts[p].cur];
                
            }
            
            opt.complete = pulse;
            opt.queue = false;
            
            if (doAnimate) {
                self.animate(propsSingle, opt);
            } else {
                optall.complete.call(self[0]);
            }
            
        }
            
    });
    
};
})(jQuery);

$(document).ready(function() {

        $('#ct-mood').bind('mouseleave', function() {
//            var properties = {
//                opacity : 0.7
//            }
//            $(this).pulse(properties, 800, 2, 400);

            if($('#slide-btn').attr('id') == "slide-btn" && $('#slide-btn').hasClass('active') === false) {
                $(this).pulse({
                    opacity: [0.75,1] // pulse between 1 and 0
                }, 200, 2, 'linear', function(){
                    $(this).css({
                        opacity : 1
                    });
                });
                
                $('#slide-btn').pulse({
                    opacity: [0.75,1] // pulse between 1 and 0
                }, 200, 1, 'linear', function(){
                    $(this).css({
                        opacity : 1
                    });
                });
            }
        });
        $('#ct-mood .active').bind('mouseenter', function() {        
                $('#slide-btn').pulse({
                    opacity: [0.75,1] // pulse between 1 and 0
                }, 200, 1, 'linear', function(){
                    $(this).css({
                        opacity : 1
                    });
                });
        });


        if($("#slide-bt") != null) 
	$('#slide-btn').click(function() {
		$('#slide-max').slideToggle("slow");
		$('#navslidemax').slideToggle("slow");
		$('#slide-btn').toggleClass("active");
                $('#ct-mood').pulse().end();
	});
        
        if($("a.group") != null && (typeof $("a.group").fancybox) != "undefined") 
	$("a.group").fancybox({
		'transitionIn'		: 'elastic',
		'transitionOut'		: 'elastic',
		'speedIn'			: 600,
		'speedOut'			: 200,
		'hideOnContentClick': true
	});
        
        if($("a.tour") != null && (typeof $("a.tour").fancybox) != "undefined") 
	$("a.tour").fancybox({
		'speedIn'			: 600,
		'speedOut'			: 200,
		'hideOnContentClick': true
	});
        
      
        if($("a.dPdfBook") != null && (typeof $("a.dPdfBook").fancybox) != "undefined") {
            //$("a.dPdfBook[href*=datenblaetter]").attr('rel','gallery');
            
            var fbdPdfBook = $("a.dPdfBook").fancybox({
                'width'            : '95%',
                'height'            : '80%',
                'hideOnContentClick'    : true,
                'overlayShow'           : true,
                'overlayOpacity'        : 0.6,
                //'titleFormat'		: formatTitle,
                'href' : $(this).attr('href')+'?show=book',
                'type' : 'iframe',
                'onComplete'	:	function(el) {
                    if($("#fancybox-wrap").height() < 720) {
                        $("#fancybox-content").css({'height':'720px'})
                        $.fancybox.resize();
                    }
                }
                ,'onStart' : function(itemArray, selectedIndex, selectedOpts){
                    newWidth = '95%';
                    if(screen.width < $(document).width()) {
                        newWidth = Math.ceil((screen.width/100)*95)
                    }
                    else if($("#ct-content").width() > $(window).width()) {
                        newWidth = $("#ct-content").width();
                    }
                    return {
                        width : newWidth,
                        href : itemArray[selectedIndex].href+'?show=book'
                    };
                }
            });

            $(window).resize(function(){
                $.fancybox.resize();
            });    
        }

});



function callFancy(my_href) {

//	var newlink = document.getElementById("hidden");
//
//	newlink.href = my_href;
	$('[href='+my_href+']').trigger('click');

}

