// jcarousel functions
function mycarousel_itemLoadCallback(carousel, state)
{
    // Check if the requested items already exist
    if (carousel.has(carousel.first, carousel.last)) {
        return;
    }

    jQuery.get(
        'jcarousel-ajax.php',
        {
            first: carousel.first,
            last: carousel.last
        },
        function(xml) {
            mycarousel_itemAddCallback(carousel, carousel.first, carousel.last, xml);
        },
        'xml'
    );
};
function mycarousel_itemAddCallback(carousel, first, last, xml)
{
    // Set the size of the carousel
    carousel.size(parseInt(jQuery('total', xml).text()));

    jQuery('image', xml).each(function(i) {
        carousel.add(first + i, mycarousel_getItemHTML(jQuery(this).text()));
    });
};
/**
 * Item html creation helper.
 */
function mycarousel_getItemHTML(url)
{
    return '<img src="' + url + '" width="80" height="80" alt="" />';
};


$(document).ready( function(){

  // rotating fading bbc logos
  $('#logofade').show();
  $('#logofade').innerfade({ speed: 'slow', timeout: 4000, type: 'sequence', containerheight: '70px' });
  
  // pnav menu
  $('ul.pnav').jdMenu();

  // home-spotlightbox
  $("li.snav-auktionen a img").attr({src: "/images/home-box2-a_on.png"});
  $("div.box-auktionen").show();
  $("div.box-shop").hide();
  
  $("li.snav-auktionen a").click(function(){
    $("li.snav-auktionen a img").attr({src: "/images/home-box2-a_on.png"});
    $("li.snav-shop a img").attr({src: "/images/home-box2-s.png"});
    $("div.box-auktionen").show();
    $("div.box-shop").hide();
    return false;
  });
  $("li.snav-shop a").click(function(){
    $("li.snav-auktionen a img").attr({src: "/images/home-box2-a.png"});
    $("li.snav-shop a img").attr({src: "/images/home-box2-s_on.png"});
    $("div.box-auktionen").hide();
    $("div.box-shop").show();
    return false;
  });
  
  // termine toggle
  
  $("ol.termine-more").hide();
  $("div.home-box1 div.last a.more").click(function(){
    if ($(this).text()=="Weniger einblenden"){
      $(this).text("Weitere einblenden");
      var togglestatus = 0;
    } else {
      $(this).text("Weniger einblenden");
      var togglestatus = 1;
    }
    
    
    var moreheight = $("ol.termine-more").height() +10;
    
    $("ol.termine-more").slideToggle("slow");
    
    if (togglestatus == 0){
      var open_height = $("div.home-box1 div.first").height() - moreheight;
    } else {
      var open_height = $("div.home-box1 div.first").height() + moreheight;
    }
    
    $("div.home-box1 div.first").animate({"height": open_height + "px"}, {duration: "slow" });
    
    
    return false;
  });
  
  // features toggle
   $("div.text div.featurestoggle").hide();
   $("div.rc").find("div.text a.more").click(function(){
     if ($(this).text()=="weniger"){
       $(this).text("mehr");
     } else {
       $(this).text("weniger");
     }

     $(this).parent(3).find("div.featurestoggle").slideToggle("slow");
     return false;
   });
  
  // news toggle
  $("div.text div.newstoggle").hide();
  $("div.article").find("div.text a.more").click(function(){
    if ($(this).text()=="weniger"){
      $(this).text("mehr");
    } else {
      $(this).text("weniger");
    }
    
    $(this).parent(3).find("div.newstoggle").slideToggle("slow");
    return false;
  });
  
  $("div.allnews").hide();
  $("a.allnews").click(function(){
    if ($(this).text()=="weniger News anzeigen"){
      $(this).text("alle News anzeigen");
    } else {
      $(this).text("weniger News anzeigen");
    }
    
    $(this).parent().find("div.allnews").slideToggle("slow");
    return false;
  });
  
  // jcarousel
  if ( $('#imgcarousel').length > 0 ) {
     $('#imgcarousel').jcarousel({scroll: 4});
     $("#imgcarousel li a").click(function(){
       var imgsrc = $(this).attr('href');
       $("#gallerybig img").attr({ 
         src: imgsrc
       });
       return false;
     });
  };
  
  // php-ajax-carousel
  //jQuery('#imgcarousel').jcarousel({
  //  itemLoadCallback: mycarousel_itemLoadCallback
  //});
  
  // accordion
  if ( $('.accordion').length > 0 ) {
    $('.accordion').accordion({
      autoHeight: false,
      active: '.selected'
    });
  };
  if($.browser.msie && $.browser.version=="6.0") {
    $('div.friends h3').addClass("png ui-state-active");
  }
  else {
    if ( $('div.friends').length > 0 ) {
      $('.friends').accordion({
        autoHeight: false,
        active: false
      });
    };
  }
  
  
});