/*
  
  Website: Eurener Hof
  BOB Design http://www.bob-design.de/
  Imagion AG http://www.imagion.de/
  Javascript Datei
  19.08.2011 Daan Meskers
  $last_change: 19.08.2011 Daan Meskers
*/

var prevMenuItem, MSIE

// init
$(document).ready( function() {

  if ( $("div#ImagesMain img").size() > 1 )
    setInterval( "slideSwitch()", 6500 );
  
  // Menu
  //prevMenuItem = $("ul#Menu li.on")
  $("ul#Menu li").each( function() {
    if( $(this).find("ul") ) {
      $(this).css( "width", $(this).width() +"px")
      var $mymenu = $(this).find("ul")
      if ( $mymenu.height()  ) 
        $mymenu.data( "fullheight", $mymenu.height() )
      if ( !$mymenu.parent().hasClass("active")  && !MSIE ) 
        $mymenu.css({height:0, opacity:0})
    }
  }).delay(500);
  $("ul#Menu li").hover(
     function () { 
      var $opener =  $(this).find("ul")
      $opener.parent().addClass('on')
      var newHeight = $opener.data( "fullheight" )+"px"
      $(this).css( "overflow", "visible" )
      if ( !MSIE ) {
         $opener.animate({opacity: 1, height: newHeight}, 500, function() 
         {
            if (prevMenuItem) prevMenuItem.removeClass('on');
            prevMenuItem = $opener.parent()    
         })
       } else {
          $opener.animate({height: newHeight, paddingTop: 8}, 500, function() 
          {
             if (prevMenuItem) prevMenuItem.removeClass('on');
             prevMenuItem = $opener.parent()    
          })
       }
     }, 
     function () {
      $(this).css( "overflow", "hidden" ).delay(500)
      var $closer =  $(this).find("ul")
      //if ( !$(this).hasClass("active")  ) 
      if ( !MSIE ) 
      {
         $closer.animate({opacity: 0, height: 0}, 750).delay(300)
      } else 
      {
         $closer.animate({height: 0, paddingTop: 0, paddingBottom: 0}, 750).delay(300)
      }
     }
  );
  $("ul#Menu li ul li").unbind('mouseenter');
  //prevMenuItem = $("ul#Menu li.on")
});


// slideshow
function slideSwitch() {
    //alert( "slideSwitch" )
    var $active = $('div#ImagesMain img.active');
    if ( $active.length == 0 ) $active = $('div#ImagesMain img.first');
    var $next =  $active.next().length ? $active.next() : $('div#ImagesMain img.first');
    $active.addClass('last-active');
    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 800, function() {
            $active.removeClass('active last-active');
        });
    $active.animate({opacity: 1}, 250, function() {
            $active.animate({opacity: 0}, 1000);
        });
    //$('div#ImagesMain').animate({height: $next.height()}, 750);
  
}
