PEPS = {};

PEPS.rollover = 
{
   init: function()
   {
      this.preload();

      $(".ro").hover(
         function () { $(this).attr( 'src', PEPS.rollover.newimage($(this).attr('src')) ); }, 
         function () { $(this).attr( 'src', PEPS.rollover.oldimage($(this).attr('src')) ); }
      );
   },

   preload: function()
   {
      $(window).bind('load', function() {
         $('.ro').each( function( key, elm ) { $('<img>').attr( 'src', PEPS.rollover.newimage( $(this).attr('src') ) ); });
      });
   },

   newimage: function( src )
   { 
      return src.substring( 0, src.search(/(\.[a-z]+)$/) ) + '_over' + src.match(/(\.[a-z]+)$/)[0]; 
   },

   oldimage: function( src )
   { 
      return src.replace(/_over\./, '.'); 
   }
};
slt = 0;
srn = 1;
mvcr = null;
function slideSwitch() {
    var $active = $('#slideshow IMG.active');
    if ( $active.length == 0 ) $active = $('#slideshow IMG:last');

// This function here needs to be modified to only select the next item that doesn't have the class "manual"!
    var $next =  $active.next().length ? $active.next()
        : $('#slideshow IMG:first');


    $active.addClass('last-active');
	
	if(!$next.length) return;

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 2000, function() {
            $active.removeClass('active last-active');
            if(srn > 0) slt = setTimeout(slideSwitch,4000);
        });
}
function toggleVideo() {
	if(!mvcr) return;
	if(srn > 0) {
		if(slt > 0) clearTimeout(slt);
		slt = 0;
		srn = 0;
		$("#slideshow").css("visibility","hidden");
		$(".videolink").html("Video aus");
		$("#video_holder").css({visibility:"visible"});
		mvcr.showVideo();
	} else {
		$("#video_holder").css({visibility:"hidden"});
		$("#slideshow").css("visibility","visible");
		$(".videolink").html("Video ansehen");
		srn = 1;
		mvcr.hideVideo();
		slideSwitch();
	}
}
function initVideo() {
	var s = $.browser.mozilla ? "vcre" : "vcr";
	var m = document.getElementById(s);
	$("#video_holder").css('visibility','hidden');
	var fn = m.showVideo;
	if(fn) {
		mvcr = m;
		if(document.location.hash=="#v") toggleVideo();
	}
}
function trace(s) {
	if(window.console) console.log(s);
}


