
$(document).ready(function(){

  if($(".discounts .post-4-box").length<=4){
        $(".discounts .lnk-more").css("display","none");
  }

  /*inizializzazione*/
  oldOb=$(".post-4-box").eq(0);
  father='';
  x=0;


  $(".bot-part").css("display","none");
  $(".containerP").height($(".slideP").height());
  $(".active-promotions .lnk-prev").css("display","none");
  $(".paging .prev").css("display","none");

  $(".bot-part").eq(0).css("display","block");
  $(".top-part").eq(0).css("display","none");
  $(".post-4-box").addClass("open");
  /*tasti*/
  $(".lnk-details").hover(function(){
        $(this).css("color","#FF3399");
        },function(){
        $(this).css("color","#CCCCCC");
        });
  
  /*Slider promozioni hp città*/
  $(".discounts .lnk-more").click(function(){
        
  });

 /*slider promo sotto fascia*/

    sliderPLend=$(".slidePL").length-1;

    if($(".post-4-box").length<=9){
        $("#next-promo-inloc").css("display","none");
            }

   $(".active-promotions .lnk-next").click(function(){
            if (x == -sliderPLend) { $(".sliderPL").animate({left:0});
                             x=0;
                             $(".lnk-prev").css("display","none");}
            else {
            $(".lnk-prev").css("display","block");
            x--;
            $(".sliderPL").animate({left:425*x}, "fast");

            }
  });

  $(".active-promotions .lnk-prev").click(function(){
            if (x == -1) {
                          $(".sliderPL").animate({left:0}, "fast");
                          $(".lnk-prev").css("display","none");
                          x=0;   }
            else {
            x++;
            $(".sliderPL").animate({left:425*x}, "fast");}
  });

  /*Box*/
  $('.post-4-box').hover(function(){
                      $(this).addClass('hover');
                    }, function() {
                      $(this).removeClass('hover');
                    });
  
  $(".post-4-box").click(function(){
                      father=$(this); 
                      if ($(oldOb).hasClass('open')) {
                        $(".bot-part",oldOb).css("display","none");
                        $(".post-4-box",oldOb).css("display","block");
                        $(".top-part",oldOb).css("display","block");
                        $(oldOb).removeClass('open');
                      
                        $(".bot-part",father).css("display","block");
                        $(".post-4-box",father).css("display","none");
                        $(".top-part",father).css("display","none");
                        $(father).addClass('open');
                        oldOb=$(father);}
                        else {  
                        $(".bot-part",father).css("display","block");
                        $(".post-4-box",father).css("display","none");
                        $(".top-part",father).css("display","none");
                        $(father).addClass('open');
                        oldOb=$(this);}
                        $(".containerP").height($(this).parent().parent().height());                       
                    });

/*Gratis E promo section*/
/*
$(".paging .next a").click(function(){
    if (x == -sliderPLend) { $(".sliderPL").animate({left:0});
                             x=0;
                             $(".paging .prev").css("display","none");}
            else {
            $(".paging .prev").css("display","block");
            x--;
            $(".sliderPL").animate({left:425*x}, "fast");

            }
});*/
$(".paging .prev a").click(function(){
            if (x == -1) {
                          $(".sliderPL").animate({left:0}, "fast");
                          $(".paging .prev").css("display","none");
                          x=0;   }
            else {
            x++;
            $(".sliderPL").animate({left:425*x}, "fast");}
  });

});