
$(document).ready(function() {
	var C = {
		overlayOpacity : 0.9,
		overlayColor   : '#191b1a',
		titlePosition  : 'over'
	};
	$('a[target="_fancybox"],a[rel="group"]').fancybox(C);
    $('.slider').cycle({
		  fx: 'fade'
		 });
	$('a.media').media();
	
	
	if($('.Ierror')[0]) {
		$('html, body').animate({scrollTop:$('.Ierror:eq(0)').offset().top}, 'fast',
			function() {
					$.fancybox(
					'<h2>'+$('h1').text()+'</h2><p style="color:red">'+$('legend').text()+'</p>',
					{
			        		'autoDimensions'	: false,
						'width'         		: 350,
						'height'        		: 'auto',
						'transitionIn'		: 'none',
						'transitionOut'		: 'none'
					}
					);	
			}
		
		);
			
	}
	
	var FancyAutoPlayInt = false;
	$('a[rel="group-play"]').fancybox({
  			'overlayOpacity'		: 0.8,
  			'titlePosition'		: 'inside',
  			onClosed : function() {
            window.clearTimeout(FancyAutoPlayInt);
            FancyAutoPlayInt = false;
        },
  			onComplete : function() {
  			  var SecTimeOut = 4;
  			  var box = $('.dshow');
          box.find('.stop').click(function() {
            box.find('.stop').hide();
            box.find('.play').fadeIn();
            window.clearTimeout(FancyAutoPlayInt);
            FancyAutoPlayInt = false;
            return false;
          });
          box.find('.play').click(function() {
            box.find('.play').hide();
            box.find('.stop').fadeIn();
            $('#fancybox-right').trigger('click');
            FancyAutoPlayInt = true;
            return false;
          });
          // if last entry
          if(!$('#fancybox-right:visible').attr('id')) {
              box.find('.stop').trigger('click');
              box.hide();
              return false;
          }
          if(FancyAutoPlayInt) {
            box.find('.stop').fadeIn();
             var time = SecTimeOut;
             box.find('.sec').html(time);
             var CountTime = function() {
               time--;
               if(time>0) {
                  box.find('.sec').html(time);
                  FancyAutoPlayInt = window.setTimeout(CountTime,1000);
               } else {
                  $('#fancybox-right').trigger('click');
               }
             };
             FancyAutoPlayInt = window.setTimeout(CountTime,1000);
          } else {
            box.find('.play').fadeIn();
          }
          return false;
        },
  			'titleFormat'    : function(title, currentArray, currentIndex, currentOpts) {
            var cnt ='<div class="dshow" style="float:right;">';
                cnt+='<a href="javascript:void(0)" class="play" style="display:none">Diashow starten ></a>';
                cnt+='<a href="javascript:void(0)" class="stop" style="display:none"><span class="sec"></span> Diashow stoppen</a>';
                cnt+='</div>';
            cnt+=title;
            return cnt;
        }
		});
});
