$(document).ready(function(){
  
  $("#mycarousel").jcarousel({
        scroll: 2,
        auto: 3,
        wrap: 'last',
        initCallback: mycarousel_initCallback
    });

    $('#mycarouselbanner li').remove();    
    $('#mycarouselbanner').jcarousel({
        scroll: 1,
        auto: 5,
        wrap: 'circular',
        itemVisibleInCallback: {onBeforeAnimation: mycarousel_itemVisibleInCallback},
        itemVisibleOutCallback: {onAfterAnimation: mycarousel_itemVisibleOutCallback},
        initCallback: mycarousel_initCallback
    });
  
  $(".jqzoom").jqueryzoom({
    xzoom: 300,
    yzoom: 300,
    position: "right",        
    offset:23
  });
  
  $(".productmoreimages img").mouseover(function() {
    var zoom  = 'images/product_images/popup_images/';
    var image = 'images/product_images/info_images/';    
    var img = $(this).attr("name");
    $("#prodimg").attr({src: image+img, jqimg: zoom+img});
  });  
  
  $(".productmoreimages img.sdwoutfit").mouseover(function() {
    var zoom  = 'images/outfits/popup_images/';
    var image = 'images/outfits/info_images/';    
    var img = $(this).attr("name");
    $("#prodimg").attr({src: image+img, jqimg: zoom+img});
  }); 
  
  
  $(".sdwoutfitlink").mouseover(function() {
      var zoom  = 'images/product_images/popup_images/';
      var image = 'images/product_images/info_images/';          
      var img = $(this).attr("name");
      $("#prodimg").attr({src: image+img, jqimg: zoom+img});    
  });  
  
  
  $(".relatedproducts a").hover(    
    function() {
      var img = $(this).find("img").attr("src");
      var alt = $(this).find("img").attr("alt");            
      $(this).after('<div class="hooverimg"><img src="'+img+'" width="100" height="100" alt="'+alt+'" /></div>');
    }, 
    function() { $(".hooverimg").remove(); }
    );
    
    
  $(".product_listing a").hover(    
    function() {
      var img = $(this).attr("name");
      var alt = $(this).find("img").attr("alt");            
      $(this).after('<div class="hooverinfoimg"><img src="'+img+'" width="250" height="250" alt="'+alt+'" /></div>');
    }, 
    function() { $(".hooverinfoimg").remove(); }
    );    
    
         
    
  $(".msg_succ")
    .animate({opacity: 1.0}, 6000)
    .fadeOut('slow', function() { $(this).remove(); });
  $(".msg_info")
    .animate({opacity: 1.0}, 6000)
    .fadeOut('slow', function() { $(this).remove(); });
  $(".msg_err")
    .animate({opacity: 1.0}, 6000)
    .fadeOut('slow', function() { $(this).remove(); });    


  $("#gift_cart_toggle").click(function () {
      $(".gift_cart").toggle("slow");
    });
    
    
  $(".review").click(function () {
      var src = $(this).attr("href");            
//      $("#get_cheaper").load(src).removeClass('no-show').show('1000');

     $("#reviewform").load(src).show('1000');                  
      return false;      
    });
       
  
//   $('.product_info_links a').click(function() {
//       alert('test');
// //       $('.product_links a').removeClass('active');
// //       $(this).addClass('active');
//   });
        
    $("#html_link").click(function () {
      $("#html_fields").show();
      $("#bb_fields").hide();    
      $("#html_link").addClass("active");
      $("#bb_link").removeClass("active");                
    });
    
    $("#bb_link").click(function () {
      $("#html_fields").hide();
      $("#bb_fields").show();    
      $("#html_link").removeClass("active");
      $("#bb_link").addClass("active");                
    });
  
  $(".product_links_content input").click(function () {
    $(this).select();
  });    
    
  $(".generator_table textarea").click(function () {
    $(this).select();
  });
  
//   $(".wishlist-txt .wishlist-no-access").click(function () {
//     alert("Um die Merkzettelfunktion nutzen zu koennen, musst Du angemeldet sein!");
//   });
  


  $(".edit").editable('wishlist_write_comment.php?do=post', {
      indicator : '<img src="http://www.harlem-stores.de/shop/templates/harlem_v3/img/indicator.gif" /><br />Wird gespeichert...',
      tooltip   : 'Hier klicken zum Bearbeiten..',
      submit    : 'speichern'
  });
  


  $(".change_custom_name").editable('wishlist_new_url.php?do=newUrl', {
      indicator : '<img src="http://www.harlem-stores.de/shop/templates/harlem_v3/img/indicator.gif" />',
      tooltip   : 'Hier klicken zum Bearbeiten..',
      style     : 'inherit'
  });
  


  $('input#setpublic:checkbox').click(function() {
      var customer_id = $('input#customer_id').val();
      
      if ($('#setpublic:checked').val() && $('#setpublic').val() == 'notpublic') {
            $('#custom_name').removeClass('no-show');
            $('#submit_form').removeClass('no-show');
            $('#new_url_link').removeClass('no-show');
            $('#new_url_link_hint').removeClass('no-show');
      } else {
            $('#custom_name').addClass('no-show');
            $('#submit_form').addClass('no-show');
            $('#new_url_link').addClass('no-show');
            $('#new_url_link_hint').addClass('no-show');
      }
      
      if ($('#setpublic:checked').val() && $('#setpublic').val() == 'public') {
            $('#submit_form').addClass('no-show');
      } else {
            $('#submit_form').removeClass('no-show');
      }
      
      
//       $('input#submit:checked').removeClass('no-show');
//       if  ($('#setpublic').val() == 'notpublic') {
//       if  ($('#setpublic:checked').val()) {
//             $('#setPublicForm').hide();
//             $('#setPublicDiv').show().html('<img src="http://www.harlem-stores.de/shop/templates/harlem_v3/img/indicator.gif" /><br />Wird gespeichert...');
//             
//             $.post('wishlist_set_public.php?do=public', {customer_id: customer_id, setPublic: 1}, 
//             function(data){
//                   $('#paginationPublic').load('wishlist_set_public.php');
//             });
      
//       } else if  ($('#setpublic').val() == 'public') {
//       } else {
//             $('#setPublicForm').hide();
//             $('#setPublicDiv').show().html('<img src="http://www.harlem-stores.de/shop/templates/harlem_v3/img/indicator.gif" /><br />Wird gespeichert...');
//             
//             $.post('wishlist_set_public.php?do=public', {customer_id: customer_id, setPublic: 0},
//             function(data){
//                   $('#paginationPublic').load('wishlist_set_public.php');
//             });
//       }
  });
  
  $(".wishlist-pub-desc table input").click(function () {
    $(this).select();
  });



  $('.banner_links input').click(function() {
      var varColourC = $('.colour:checked').val();
      var varSizeC = $('.size:checked').val();
      var varCodeC = $('.code:checked').val();
      
      // Text 'Vorschau' einblenden wenn Farbe und Größe gesetzt      
      if (varSizeC && varColourC) {
        $('.vorschau').removeClass('no-show');
      }
      
      // Banner Anzeige
      $('.banner_links img').addClass('no-show');
      $('#banner_'+varColourC+'_'+varSizeC).removeClass('no-show');
      
      // Code Anzeige
      $('textarea').addClass('no-show');
      if (varCodeC == 'bbcode') {
        $('#bb_'+varColourC+'_'+varSizeC).removeClass('no-show');
      } else if (varCodeC == 'html') {
        $('#html_'+varColourC+'_'+varSizeC).removeClass('no-show');
      }
  });
  
  
  $('.generate_code').click(function() {
      $('.generator_table').toggle();
  });

  
//   $('.change_custom_name').click(function() {
//       $('.hint').removeClass('no-show');
//   }

  $('.banner_page a').click(function() {
      var a_name = $(this).attr('id');

      $('.banner_page a').removeClass('active');
      $(this).addClass('active');
      
      $('.banner_links_content div').addClass('no-show');
      $('.banner_links_content #'+a_name+'_fields').removeClass('no-show');
  });
  
});

function mycarousel_itemVisibleInCallback(carousel, item, i, state, evt)
{
    // The index() method calculates the index from a given index who is out of the actual item range.
    //if(mycarousel_itemList!='undefine'){
      var idx = carousel.index(i, mycarousel_itemList.length);
      carousel.add(i, mycarousel_getItemHTML(mycarousel_itemList[idx - 1]));
    //}
}

function mycarousel_itemVisibleOutCallback(carousel, item, i, state, evt)
{
    carousel.remove(i);
}

/**
 * Item html creation helper.
 */
function mycarousel_getItemHTML(item)
{
    return '<a href="' + item.url + '"><img src="' + item.src + '" width="222" height="222" alt="' + item.alt + '" /></a>';
}

function mycarousel_initCallback(carousel)
{
    // Disable autoscrolling if the user clicks the prev or next button.
    carousel.buttonNext.bind('click', function() {
        carousel.startAuto(0);
    });

    carousel.buttonPrev.bind('click', function() {
        carousel.startAuto(0);
    });

    // Pause autoscrolling if the user moves with the cursor over the clip.
    carousel.clip.hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });
};